]> git.decadent.org.uk Git - videolink.git/blob - auto_proc.cpp
Corrected handling of fragments. Added support for linking to chapters using fragments.
[videolink.git] / auto_proc.cpp
1 // Copyright 2005 Ben Hutchings <ben@decadentplace.org.uk>.
2 // See the file "COPYING" for licence details.
3
4 #include <cassert>
5
6 #include <errno.h>
7 #include <signal.h>
8 #include <unistd.h>
9 #include <wait.h>
10
11 #include "auto_proc.hpp"
12
13 void auto_kill_proc_closer::operator()(pid_t pid) const
14 {
15     assert(pid >= -1);
16
17     if (pid > 0 && waitpid(pid, NULL, WNOHANG) == 0)
18     {
19         kill(pid, SIGTERM);
20         while (waitpid(pid, NULL, 0) == -1)
21             if (errno != EINTR)
22             {
23                 assert(!"invalid pid in auto_kill_proc_closer");
24                 break;
25             }
26     }
27 }
28
29 void auto_wait_proc_closer::operator()(pid_t pid) const
30 {
31     assert(pid >= -1);
32
33     if (pid > 0)
34         while (waitpid(pid, NULL, 0) == -1)
35             if (errno != EINTR)
36             {
37                 assert(!"invalid pid in auto_wait_proc_closer");
38                 break;
39             }
40 }