File: auto_proc.cpp

package info (click to toggle)
videolink 1.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 368 kB
  • ctags: 502
  • sloc: cpp: 3,210; ansic: 880; makefile: 121
file content (40 lines) | stat: -rw-r--r-- 771 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2005 Ben Hutchings <ben@decadent.org.uk>.
// See the file "COPYING" for licence details.

#include <cassert>

#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <wait.h>

#include "auto_proc.hpp"

void auto_kill_proc_closer::operator()(pid_t pid) const
{
    assert(pid >= -1);

    if (pid > 0 && waitpid(pid, NULL, WNOHANG) == 0)
    {
	kill(pid, SIGTERM);
	while (waitpid(pid, NULL, 0) == -1)
	    if (errno != EINTR)
	    {
		assert(!"invalid pid in auto_kill_proc_closer");
		break;
	    }
    }
}

void auto_wait_proc_closer::operator()(pid_t pid) const
{
    assert(pid >= -1);

    if (pid > 0)
	while (waitpid(pid, NULL, 0) == -1)
	    if (errno != EINTR)
	    {
		assert(!"invalid pid in auto_wait_proc_closer");
		break;
	    }
}