diff options
author | Johns <johns98@gmx.net> | 2012-01-24 22:20:17 +0100 |
---|---|---|
committer | Johns <johns98@gmx.net> | 2012-01-24 22:20:17 +0100 |
commit | c7cebe1aeb54b7f2d500b130cde8dd10074c6ac1 (patch) | |
tree | bef941a7c822b4b2d9299ac1b0693bd78c02c8bf /softhddev.c | |
parent | 037f582badb9c1b9defc83a737bd1e5ed458473c (diff) | |
download | vdr-plugin-softhddevice-c7cebe1aeb54b7f2d500b130cde8dd10074c6ac1.tar.gz vdr-plugin-softhddevice-c7cebe1aeb54b7f2d500b130cde8dd10074c6ac1.tar.bz2 |
Wait for X11 exit and kill it, if not.
Diffstat (limited to 'softhddev.c')
-rw-r--r-- | softhddev.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/softhddev.c b/softhddev.c index b998b7d..7a9272d 100644 --- a/softhddev.c +++ b/softhddev.c @@ -1216,8 +1216,34 @@ void SoftHdDeviceExit(void) Debug(3, "x-setup: Stop x11 server\n"); if (X11ServerPid) { + int waittime; + int timeout; + pid_t wpid; + int status; + kill(X11ServerPid, SIGTERM); - // FIXME: wait for x11 finishing + waittime = 0; + timeout = 500; // 0.5s + // wait for x11 finishing, with timeout + do { + wpid = waitpid(X11ServerPid, &status, WNOHANG); + if (wpid) { + break; + } + if (waittime++ < timeout) { + usleep(1 * 1000); + continue; + } + kill(X11ServerPid, SIGKILL); + } while (waittime < timeout); + if (wpid && WIFEXITED(status)) { + Debug(3, "x-setup: x11 server exited (%d)\n", + WEXITSTATUS(status)); + } + if (wpid && WIFSIGNALED(status)) { + Debug(3, "x-setup: x11 server killed (%d)\n", + WTERMSIG(status)); + } } } |