// daemonize.h // PUBLIC DOMAIN // http:///www.purposeful.co.uk/software/yabaplib /* I, Tom Vajzovic, am the author of this software and its documentation. I permanently abandon all intellectual property rights in them, including copyright, trademarks, design rights, database right, patents, and the right to be identified as the author. I am fairly certain that the software does what the documentation says it does, but I do not guarantee that it does, or that it does what you think it should. I do not guarantee that it will not have undesirable side effects. You are free to use, modify and distribute this software as you please, but you do so at your own risk. If you do not pass on this warning then you may be responsible for any problems encountered by those who obtain the software through you. */ #ifndef DAEMONIZE_H_INCLUDED #define DAEMONIZE_H_INCLUDED #ifdef __cplusplus extern "C" { #endif // This function unmasks some signals and sets their handlers to the default // state or to be ignored, which might be desired before calling daemonize(). // void daemon_signals(void); // This function forks a new process, calls setsid and forks again. // // Any error results in a message to the standard error stream of the calling // process, which terminates with no new processes left behind. // // On success the only process left will be the grandchild of the calling // process. // // If there is an error in the calling process before the first fork, that // process terminates with exit(). If there is an error after the fork it // kills the child process and any grandchildren with SIGKILL and terminates // with _Exit(). The intermediate process always terminates with _Exit(). // // The arguments of this function are the same as for BSD daemon() but with // type safety. // // If nochdir is zero, daemonize() changes the process's current working // directory to the root directory ("/"); otherwise, the current working // directory is left unchanged. // // If noclose is zero, daemonize() redirects standard input, standard output // and standard error to /dev/null; otherwise, no changes are made to these // file descriptors. // enum nochdir { DAEMONIZE_CHDIR_ROOT = 0, DAEMONIZE_NO_CHDIR = 1, }; enum noclose { DAEMONIZE_CLOSE_STDIO = 0, DAEMONIZE_NOCLOSE_STDIO = 1, }; void daemonize(enum nochdir nochdir, enum noclose noclose); #ifdef __cplusplus } #endif #endif