File: stop.cc

package info (click to toggle)
bobcat 1.11.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,344 kB
  • ctags: 473
  • sloc: makefile: 12,078; cpp: 5,121; ansic: 63; sh: 14
file content (55 lines) | stat: -rw-r--r-- 1,012 bytes parent folder | download | duplicates (2)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "process.ih"

int Process::stop()
{
    if (!pid())                     // pid = 0 occurs when a Process 
        return 0;                   // object was created, but did not yet
                                    // fork(), and its program terminates.
                                    // This may happen, e.g., in a daemon.

    if (d_child_inp.get())
    {
        ::close(d_child_inp->writeFd());
        d_child_inp.reset(0);
    }

    if (d_child_outp.get())
    {
        ::close(d_child_outp->readFd());
        d_child_outp.reset(0);
    }

    if (d_child_errp.get())
    {
        ::close(d_child_errp->readFd());
        d_child_errp.reset(0);
    }

    d_selector.setAlarm(d_waitSeconds);
    try
    {
        d_selector.wait();
    }
    catch(...)
    {}

    d_command.clear();

    if (pid_t p = pid())
        kill(p, SIGTERM);

    if (pid_t p = pid())
        kill(p, SIGTERM);

    if (pid_t p = pid())
        kill(p, SIGKILL);

    return d_ret = waitForChild();
}