Skip to content

Commit

Permalink
Run watchdog every 10s #50
Browse files Browse the repository at this point in the history
If current track has length (unlike internet radios), and play time
has exceeded it, kill its omxplayer.bin via omxwd script.

omxwd kills all omxplayer.bin processes in its own process group,
or just the child of an omxplayer PID supplied on command line.
  • Loading branch information
subogero committed Jun 14, 2016
1 parent 2336410 commit 5c73fce
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -22,6 +22,7 @@ install:
cp init $(DESTDIR)/usr/share/doc/omxd/
cp omxd.service $(DESTDIR)/usr/share/doc/omxd/
cp logrotate $(DESTDIR)/usr/share/doc/omxd/
cp omxwd $(DESTDIR)/usr/bin
-perl -lne 'print unless /^omxd$$/' -i $(DESTDIR)/etc/rc.local # Auto migrate from rc.local
uninstall:
-./prerm
Expand All @@ -32,6 +33,7 @@ uninstall:
-rm $(DESTDIR)/usr/share/man/man1/rpyt.1
rm $(DESTDIR)/usr/share/doc/omxd/init
rm $(DESTDIR)/usr/share/doc/omxd/logrotate
rm $(DESTDIR)/usr/bin/omxwd
-./postrm
start:
-./postinst
Expand Down
21 changes: 21 additions & 0 deletions omxwd
@@ -0,0 +1,21 @@
#!/bin/sh
if [ "$1" = -h ]; then
cat <<EOF
omxd watchdog
Usage: omxwd [pid]
pid Optional PID of an omxplayer process.
Kills all omxplayer.bin processes in pgrp, or just the child of pid.
EOF
exit
fi

p=$1

read pid comm state ppid pgrp rest </proc/$$/stat

ps -A -o pgid,ppid,pid,args | grep "^ *$pgrp" \
| while read pgid ppid pid args; do
case "$args" in
/usr/bin/omxplayer.bin*) [ -z "$p" -o "$p" = $ppid ] && kill -9 $pid;;
esac
done
24 changes: 23 additions & 1 deletion player.c
Expand Up @@ -11,6 +11,7 @@
#include <errno.h>

static void player_quit(int signum);
static void watchdog(int signum);
static void drop_priv(void);

struct player {
Expand Down Expand Up @@ -38,10 +39,31 @@ static void log_opts(char *prefix);
static struct { int argc; char **argv; } opts =
{ -1, NULL, };

static void watchdog(int signum)
{
char st[LINE_LENGTH] = { 0, };
char playing[LINE_LENGTH] = { 0, };
int t_play = 0;
int t_len = 0;
int pid = 0;
if (parse_status(st, playing, &t_play, &t_len, &pid) == 0 &&
pid > 0 && t_len > 0 && t_play > t_len) {
char cmd[50] = { 0, };
strcpy(cmd, "/usr/bin/omxwd ");
scatd(cmd, pid);
system(cmd);
}
alarm(10);
signal(SIGALRM, watchdog);
}

struct player *player_new(char *file, char *out, enum pstate state)
{
if (opts.argv == NULL)
if (opts.argv == NULL) {
init_opts();
alarm(10);
signal(SIGALRM, watchdog);
}
if (file == NULL || *file == 0)
return NULL;
struct player *this = find_free();
Expand Down

0 comments on commit 5c73fce

Please sign in to comment.