diff options
author | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2000-09-20 18:00:00 +0200 |
---|---|---|
committer | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2000-09-20 18:00:00 +0200 |
commit | 7e4b4d290570aee1d24241b0e0ac10e7c8148a36 (patch) | |
tree | 699b8f551fb4a2deb3c79030d57a56e5f04fc1a4 /tools.c | |
parent | 76c331181a23f97d5e3f2b55c4741ef4e521242d (diff) | |
download | vdr-patch-lnbsharing-7e4b4d290570aee1d24241b0e0ac10e7c8148a36.tar.gz vdr-patch-lnbsharing-7e4b4d290570aee1d24241b0e0ac10e7c8148a36.tar.bz2 |
Version 0.64vdr-0.64
- NOTE: If you are using DVB driver version 0.7 you need to load the dvb.o
module with option outstream=0, so your insmod statement should read
'insmod dvb.o outstream=0'. This is currently necessary because 'vdr'
still works with AV_PES data.
- Video files now have the 'group read' bit set.
- Fixed handling errors in 'readstring()'.
- Handling SIGPIPE and re-establishing handler after intercepting a signal.
- The configuration files are now by default read from the video directory.
This can be changed by using the new '-c' option. Make sure you copy your
current '*.conf' files to your video directory ('/video' by default), or
use "-c ." to get the old behaviour of loading the configuration files
from the current directory.
- Waiting for input is now handled by a common function, which improves
response time on user actions. As a consequence the EIT data may sometimes
not be displayed, but this will change later when cEIT runs as a separate
thread.
- The new SVDRP command 'HITK' (thanks to Guido Fiala!) can be used to 'hit'
a remote control key. Establish an SVDRP connection and enter HITK without
a parameter for a list of all valid key names.
- The new SVDRP command 'GRAB' (thanks to Guido Fiala!) can be used to grab
the current frame and save it to a file.
- The new SVDRP commands 'OVL*' can be used to control video overlays (thanks
to Guido Fiala!). This is mainly for use in the 'kvdr' tool (see the 'kvdr'
page at http://www.s.netic.de/gfiala).
- If the name of the video directory used with the '-v' option had trailing
slashes, the recording file names have been damaged. Trailing slashes are
now silently removed.
- Fixed a buffer overflow in EIT parsing.
- Added a security warning regarding SVDRP to the INSTALL file.
- Fixed 'confirm' dialog.
- The daemon mode (option '-d') now no longer works with REMOTE=KBD (there
is no stdin in daemon mode, so KBD makes no sense - plus it sometimes
crashed).
Diffstat (limited to 'tools.c')
-rw-r--r-- | tools.c | 157 |
1 files changed, 119 insertions, 38 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.14 2000/09/09 12:53:34 kls Exp $ + * $Id: tools.c 1.19 2000/09/19 17:55:09 kls Exp $ */ #define _GNU_SOURCE @@ -12,31 +12,20 @@ #include <ctype.h> #include <dirent.h> #include <errno.h> +#if defined(DEBUG_OSD) +#include <ncurses.h> +#endif #include <signal.h> #include <stdlib.h> #include <string.h> -#include <sys/stat.h> #include <sys/time.h> +#include <sys/wait.h> #include <unistd.h> #define MaxBuffer 1000 int SysLogLevel = 3; -bool DataAvailable(int filedes, bool wait) -{ - if (filedes >= 0) { - fd_set set; - FD_ZERO(&set); - FD_SET(filedes, &set); - struct timeval timeout; - timeout.tv_sec = wait ? 1 : 0; - timeout.tv_usec = wait ? 0 : 10000; - return select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0 && FD_ISSET(filedes, &set); - } - return false; -} - void writechar(int filedes, char c) { write(filedes, &c, sizeof(c)); @@ -56,32 +45,12 @@ char readchar(int filedes) bool readint(int filedes, int &n) { - return DataAvailable(filedes) && read(filedes, &n, sizeof(n)) == sizeof(n); -} - -int readstring(int filedes, char *buffer, int size, bool wait = false) -{ - int rbytes = 0; - - while (DataAvailable(filedes, wait)) { - int n = read(filedes, buffer + rbytes, size - rbytes); - if (n == 0) - break; // EOF - if (n < 0) { - LOG_ERROR; - break; - } - rbytes += n; - if (rbytes == size) - break; - wait = false; - } - return rbytes; + return cFile::AnyFileReady(filedes, 0) && read(filedes, &n, sizeof(n)) == sizeof(n); } void purge(int filedes) { - while (DataAvailable(filedes)) + while (cFile::AnyFileReady(filedes, 0)) readchar(filedes); } @@ -153,6 +122,14 @@ bool isnumber(const char *s) return true; } +const char *AddDirectory(const char *DirName, const char *FileName) +{ + static char *buf = NULL; + delete buf; + asprintf(&buf, "%s/%s", DirName && *DirName ? DirName : ".", FileName); + return buf; +} + #define DFCMD "df -m %s" uint FreeDiskSpaceMB(const char *Directory) @@ -313,6 +290,110 @@ void KillProcess(pid_t pid, int Timeout) } } +// --- cFile ----------------------------------------------------------------- + +bool cFile::files[FD_SETSIZE] = { false }; +int cFile::maxFiles = 0; + +cFile::cFile(void) +{ + f = -1; +} + +cFile::~cFile() +{ + Close(); +} + +bool cFile::Open(const char *FileName, int Flags, mode_t Mode) +{ + if (!IsOpen()) + return Open(open(FileName, Flags, Mode)); + esyslog(LOG_ERR, "ERROR: attempt to re-open %s", FileName); + return false; +} + +bool cFile::Open(int FileDes) +{ + if (FileDes >= 0) { + if (!IsOpen()) { + f = FileDes; + if (f >= 0) { + if (f < FD_SETSIZE) { + if (f >= maxFiles) + maxFiles = f + 1; + if (!files[f]) + files[f] = true; + else + esyslog(LOG_ERR, "ERROR: file descriptor %d already in files[]", f); + return true; + } + else + esyslog(LOG_ERR, "ERROR: file descriptor %d is larger than FD_SETSIZE (%d)", f, FD_SETSIZE); + } + } + else + esyslog(LOG_ERR, "ERROR: attempt to re-open file descriptor %d", FileDes); + } + return false; +} + +void cFile::Close(void) +{ + if (f >= 0) { + close(f); + files[f] = false; + f = -1; + } +} + +int cFile::ReadString(char *Buffer, int Size) +{ + int rbytes = 0; + bool wait = true; + + while (Ready(wait)) { + int n = read(f, Buffer + rbytes, 1); + if (n == 0) + break; // EOF + if (n < 0) { + LOG_ERROR; + return -1; + } + rbytes += n; + if (rbytes == Size || Buffer[rbytes - 1] == '\n') + break; + wait = false; + } + return rbytes; +} + +bool cFile::Ready(bool Wait) +{ + return f >= 0 && AnyFileReady(f, Wait ? 1000 : 0); +} + +bool cFile::AnyFileReady(int FileDes, int TimeoutMs) +{ +#ifdef DEBUG_OSD + refresh(); +#endif + fd_set set; + FD_ZERO(&set); + for (int i = 0; i < maxFiles; i++) { + if (files[i]) + FD_SET(i, &set); + } + if (0 <= FileDes && FileDes < FD_SETSIZE && !files[FileDes]) + FD_SET(FileDes, &set); // in case we come in with an arbitrary descriptor + if (TimeoutMs == 0) + TimeoutMs = 10; // load gets too heavy with 0 + struct timeval timeout; + timeout.tv_sec = TimeoutMs / 1000; + timeout.tv_usec = (TimeoutMs % 1000) * 1000; + return select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0 && (FileDes < 0 || FD_ISSET(FileDes, &set)); +} + // --- cListObject ----------------------------------------------------------- cListObject::cListObject(void) |