summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <kls (at) cadsoft (dot) de>2000-04-24 18:00:00 +0200
committerKlaus Schmidinger <kls (at) cadsoft (dot) de>2000-04-24 18:00:00 +0200
commit85b8e41e8bb16e4e66561768026456ec5f0ee276 (patch)
treedd52f93f8db69b395ed2170d641a3e9d574ed039 /tools.c
parent37250a0568d5b1d689d5c59f983e9be228ed49c2 (diff)
downloadvdr-patch-lnbsharing-85b8e41e8bb16e4e66561768026456ec5f0ee276.tar.gz
vdr-patch-lnbsharing-85b8e41e8bb16e4e66561768026456ec5f0ee276.tar.bz2
Version 0.04vdr-0.04
- Changed name from 'osm' to 'vdr' to avoid mixups with the 'oms' program that appears to be in use with DVD replay. - Implemented a channel display in the top menu line. - Implemented replay progress display (press "Ok" when replaying to bring it up). - Implemented direct channel selecting by pressing the numeric keys. - Added several 'const' keywords to please stricter compilers. - The repeat function for the remote control no longer adapts dynamically to the timing of the RCU (this sometimes caused the repeat function to kick in too early). - Channel selection is now blocked when recording or replaying. - Improved process handling.
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c60
1 files changed, 56 insertions, 4 deletions
diff --git a/tools.c b/tools.c
index e356e0f..eb0a14a 100644
--- a/tools.c
+++ b/tools.c
@@ -1,16 +1,17 @@
/*
* tools.c: Various tools
*
- * See the main source file 'osm.c' for copyright information and
+ * See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 1.3 2000/04/15 15:10:05 kls Exp $
+ * $Id: tools.c 1.7 2000/04/24 15:01:35 kls Exp $
*/
#define _GNU_SOURCE
#include "tools.h"
#include <dirent.h>
#include <errno.h>
+#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@@ -21,6 +22,17 @@
int SysLogLevel = 3;
+bool DataAvailable(int filedes)
+{
+ fd_set set;
+ FD_ZERO(&set);
+ FD_SET(filedes, &set);
+ struct timeval timeout;
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 10000;
+ return select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0 && FD_ISSET(filedes, &set);
+}
+
void writechar(int filedes, char c)
{
write(filedes, &c, sizeof(c));
@@ -40,8 +52,13 @@ char readchar(int filedes)
bool readint(int filedes, int &n)
{
- //XXX timeout!!
- return read(filedes, &n, sizeof(n));
+ return DataAvailable(filedes) && read(filedes, &n, sizeof(n)) == sizeof(n);
+}
+
+void purge(int filedes)
+{
+ while (DataAvailable(filedes))
+ readchar(filedes);
}
char *readline(FILE *f)
@@ -135,6 +152,41 @@ bool RemoveFileOrDir(const char *FileName)
return false;
}
+bool CheckProcess(pid_t pid)
+{
+ pid_t Pid2Check = pid;
+ int status;
+ pid = waitpid(Pid2Check, &status, WNOHANG);
+ if (pid < 0) {
+ if (errno != ECHILD)
+ LOG_ERROR;
+ return false;
+ }
+ return true;
+}
+
+void KillProcess(pid_t pid, int Timeout)
+{
+ pid_t Pid2Wait4 = pid;
+ for (time_t t0 = time(NULL); time(NULL) - t0 < Timeout; ) {
+ int status;
+ pid_t pid = waitpid(Pid2Wait4, &status, WNOHANG);
+ if (pid < 0) {
+ if (errno != ECHILD)
+ LOG_ERROR;
+ return;
+ }
+ if (pid == Pid2Wait4)
+ return;
+ }
+ esyslog(LOG_ERR, "ERROR: process %d won't end (waited %d seconds) - terminating it...", Pid2Wait4, Timeout);
+ if (kill(Pid2Wait4, SIGTERM) < 0) {
+ esyslog(LOG_ERR, "ERROR: process %d won't terminate (%s) - killing it...", Pid2Wait4, strerror(errno));
+ if (kill(Pid2Wait4, SIGKILL) < 0)
+ esyslog(LOG_ERR, "ERROR: process %d won't die (%s) - giving up", Pid2Wait4, strerror(errno));
+ }
+}
+
// --- cListObject -----------------------------------------------------------
cListObject::cListObject(void)