aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Schwarzott <zzam@gentoo.org>2007-05-30 09:56:54 +0000
committerMatthias Schwarzott <zzam@gentoo.org>2007-05-30 09:56:54 +0000
commit8dcae536930c5823073cc43b9e0287c26caf869f (patch)
tree650b447ab4e74c47d2e3511bde97b826c29daf03
parentFixed last arithmetic expression. (diff)
downloadgentoo-vdr-scripts-8dcae536930c5823073cc43b9e0287c26caf869f.tar.gz
gentoo-vdr-scripts-8dcae536930c5823073cc43b9e0287c26caf869f.tar.bz2
gentoo-vdr-scripts-8dcae536930c5823073cc43b9e0287c26caf869f.zip
Added some small binary to wait for a process to exit.
svn path=/gentoo-vdr-scripts/trunk/; revision=454
-rw-r--r--ChangeLog4
-rw-r--r--Makefile5
-rw-r--r--usr/bin/Makefile8
-rw-r--r--usr/bin/wait_on_pid.c28
-rwxr-xr-xusr/sbin/vdr-watchdogd50
5 files changed, 71 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index d7fc0f7..e6b2706 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,10 @@
# ChangeLog for gentoo-vdr-scripts
# $Id$
+ 30 May 2007; Matthias Schwarzott <zzam@gentoo.org> Makefile,
+ +usr/bin/Makefile, +usr/bin/wait_on_pid.c, usr/sbin/vdr-watchdogd:
+ Added some small binary to wait for a process to exit.
+
12 May 2007; Matthias Schwarzott <zzam@gentoo.org>
usr/share/vdr/bin/vdrshutdown-really.sh:
Fixed last arithmetic expression.
diff --git a/Makefile b/Makefile
index 5b20f43..241d737 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
SHELL=/bin/bash
all:
- @echo nothing to compile
+ make -C usr/bin
VERSION := $(shell grep '^Version' README | awk '{ print $$2 }')
TMPDIR = /tmp
@@ -29,6 +29,9 @@ install:
install -m 0755 -o root -g root -d $(DESTDIR)/usr/sbin
install -m 0755 -o root -g root usr/sbin/vdr-watchdogd $(DESTDIR)/usr/sbin
install -m 0755 -o root -g root usr/sbin/acpi-wakeup.sh $(DESTDIR)/usr/sbin
+
+ install -m 0755 -o root -g root -d $(DESTDIR)/usr/bin
+ install -m 0755 -o root -g root usr/bin/wait_on_pid $(DESTDIR)/usr/bin
#install -m 0755 -o root -g root -d $(DESTDIR)/usr/bin
#install -m 0755 -o root -g root usr/bin/vdr-start $(DESTDIR)/usr/bin
diff --git a/usr/bin/Makefile b/usr/bin/Makefile
new file mode 100644
index 0000000..f9be7db
--- /dev/null
+++ b/usr/bin/Makefile
@@ -0,0 +1,8 @@
+BINS=wait_on_pid
+
+all: $(BINS)
+
+clean:
+ rm $(BINS)
+
+
diff --git a/usr/bin/wait_on_pid.c b/usr/bin/wait_on_pid.c
new file mode 100644
index 0000000..107ea1a
--- /dev/null
+++ b/usr/bin/wait_on_pid.c
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+int proc_exist(int pid)
+{
+ return (kill(pid, 0) == 0);
+}
+
+int main(int argc, char **argv)
+{
+ if (argc < 2) {
+ printf("Usage: wait_on_pid PID\n");
+ return EXIT_FAILURE;
+ }
+ int pid=atoi(argv[1]);
+ if (!proc_exist(pid)) {
+ perror("Cannot wait on process");
+ return 1;
+ }
+
+ while (proc_exist(pid)) {
+ usleep(500*1000);
+ }
+ return EXIT_SUCCESS;
+}
+
diff --git a/usr/sbin/vdr-watchdogd b/usr/sbin/vdr-watchdogd
index 4daff3a..3d18845 100755
--- a/usr/sbin/vdr-watchdogd
+++ b/usr/sbin/vdr-watchdogd
@@ -4,40 +4,44 @@
# Distributed under the GPL
#
# watchdog script to restart vdr after failure
-# to stop watchdog temporarily touch /tmp/nowatchdog
+# to stop watchdog temporarily touch /tmp/vdr-nowatchdog
#
#
#detach from terminal
-LOGFILE=${1:-/dev/null}
exec < /dev/null
-exec >>${LOGFILE} 2>&1
+exec >/dev/null 2>&1
-
-signal_stopped=0
-
-sig_hup()
-{
- periodic_function
+log() {
+ logger -i -t vdrwatchdog -p local0.info "$@"
}
-trap sig_hup HUP
+do_restart() {
+ log "restarting VDR"
+ /etc/init.d/vdr watchdogrestart
+ /usr/bin/svdrpsend.pl mesg "Warning: vdr was restarted by watchdog."
+}
-periodic_function() {
- [ -f /tmp/no-vdr-watchdog ] && return
+is_paused() {
+ [ -f /tmp/vdr-nowatchdog ]
+}
- [ "$signal_stopped" = "1" ] && return
+VDR=/usr/bin/vdr
- if ! pidof /usr/bin/vdr > /dev/null; then
- logger -i -t vdrwatchdog -p local0.info "initializing full VDR restart"
- date
- /etc/init.d/vdr watchdogrestart
- /usr/bin/svdrpsend.pl mesg "Warning: vdr was restarted by watchdog."
+log "Starting vdrwatchdog"
+while true; do
+ pid=$(pidof -s ${VDR})
+ if [ -n "${pid}" ]; then
+ /usr/bin/wait_on_pid "${pid}"
fi
-}
-echo started watchdog
-while sleep 8; do
- periodic_function
+ while is_paused; do
+ sleep 10
+ done
+
+ if ! pidof ${VDR} >/dev/null; then
+ do_restart
+ fi
done
-echo ended watchdog
+log "Exiting vdrwatchdog"
+