Difference between revisions of "Daemonise.c"
m |
m |
||
Line 1: | Line 1: | ||
+ | // [[[[http://www.organicdesign.co.nz/peerd|peerd]]]] - nodal p2p wiki daemon | ||
+ | // This article and all its includes are licenced under LGPL | ||
+ | // GPL: [[[[http://www.gnu.org/copyleft/lesser.html]]]] | ||
+ | // SRC: [[[[http://www.organicdesign.co.nz/daemonise.c]]]] | ||
+ | // included in [[[[http://www.organicdesign.co.nz/category:peerd/files/C|peerd]]]][[[[http://www.organicdesign.co.nz/peerd.c|/peerd.c]]]] | ||
+ | |||
int peerdInit() { | int peerdInit() { | ||
Revision as of 12:09, 18 August 2006
// [[[[1]]]] - nodal p2p wiki daemon // This article and all its includes are licenced under LGPL // GPL: [[[[2]]]] // SRC: [[[[3]]]] // included in [[[[4]]]][[[[5]]]]
int peerdInit() {
errno = 0;
// Fork so parent can exit and return control to what invoked it pid_t pid = fork(); if (pid > 0) exit(EXIT_SUCCESS); if (pid < 0) exit(logErr("First fork() failed!"));
// Become a new session leader with no controlling term if (setsid() < 0) exit(logErr("setsid() failed!"));
// Fork again to be a non-session-leader which can't gain a controlling term pid = fork(); if (pid > 0) exit(EXIT_SUCCESS); if (pid < 0) exit(logErr("Second fork() failed!"));
// Should be /home/lc(peer) chdir("/home/peerd");
// Don't inherit any file perms mask umask(0);
//close(STDIN_FILENO); //close(STDOUT_FILENO); //close(STDERR_FILENO);
return errno; }