Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: fusl/src/legacy/daemon.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/src/legacy/cuserid.c ('k') | fusl/src/legacy/err.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #define _GNU_SOURCE
2 #include <fcntl.h>
3 #include <unistd.h>
4
5 int daemon(int nochdir, int noclose)
6 {
7 if (!nochdir && chdir("/"))
8 return -1;
9 if (!noclose) {
10 int fd, failed = 0;
11 if ((fd = open("/dev/null", O_RDWR)) < 0) return -1;
12 if (dup2(fd, 0) < 0 || dup2(fd, 1) < 0 || dup2(fd, 2) < 0)
13 failed++;
14 if (fd > 2) close(fd);
15 if (failed) return -1;
16 }
17
18 switch(fork()) {
19 case 0: break;
20 case -1: return -1;
21 default: _exit(0);
22 }
23
24 if (setsid() < 0) return -1;
25
26 switch(fork()) {
27 case 0: break;
28 case -1: return -1;
29 default: _exit(0);
30 }
31
32 return 0;
33 }
OLDNEW
« no previous file with comments | « fusl/src/legacy/cuserid.c ('k') | fusl/src/legacy/err.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698