]> git.decadent.org.uk Git - videolink.git/blob - auto_proc.cpp
Imported version 0.1
[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         kill(pid, SIGTERM);
19 }
20
21 void auto_wait_proc_closer::operator()(pid_t pid) const
22 {
23     assert(pid >= -1);
24
25     if (pid > 0)
26         while (waitpid(pid, NULL, 0) == -1)
27             if (errno != EINTR)
28             {
29                 assert(!"invalid pid in auto_wait_proc_closer");
30                 break;
31             }
32 }