-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnofork.c
More file actions
44 lines (36 loc) · 728 Bytes
/
nofork.c
File metadata and controls
44 lines (36 loc) · 728 Bytes
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
/*
* nofork.c
* Copyright (C) 2010 Adrian Perez <aperez@igalia.com>
*
* Distributed under terms of the MIT license.
*/
#define _POSIX_C_SOURCE 200809L
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include "util.h"
pid_t
fork (void)
{
return 0;
}
int
daemon (int nochdir, int noclose)
{
if (!nochdir) {
if (chdir ("/"))
return -1;
}
if (!noclose) {
safe_close (0);
if (safe_openat(AT_FDCWD, "/dev/null", O_RDONLY) == -1)
return -1;
safe_close(1);
if (safe_openat(AT_FDCWD, "/dev/null", O_WRONLY) != 1)
return -1;
safe_close(2);
if (dup (1) != 2)
return -1;
}
return 0;
}