File: maybebackground.cc

package info (click to toggle)
stealth 1.47.4-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 780 kB
  • ctags: 190
  • sloc: cpp: 1,710; makefile: 155; sh: 62
file content (26 lines) | stat: -rw-r--r-- 549 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
#include "util.ih"

void Util::maybeBackground()
{
    if (keepAlive())
    {
        char const *runfile = s_runFilename.c_str();

        ofstream out(runfile);
        if (!out)
            exit("Can't write `%s'", runfile);

        int pid = fork();
        if (pid < 0)
            exit("--keepalive failed due to failing fork() system call.");

        if (pid > 0)        // parent process (gets child pid)
        {
            out << pid << endl;
            throw OK;       // ::exit(0);
        }
        s_mainProcess = true;
    }
}