]> mj.ucw.cz Git - libucw.git/blob - ucw/daemon.h
13f8c37a144df01711d3a953ab50b33bdc24a888
[libucw.git] / ucw / daemon.h
1 /*
2  *      UCW Library -- Daemonization
3  *
4  *      (c) 2012 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _UCW_DAEMON_H
11 #define _UCW_DAEMON_H
12
13 #include <sys/types.h>
14
15 struct daemon_params {
16   uns flags;                            // DAEMON_FLAG_xxx
17   const char *pid_file;                 // A path to PID file (optional)
18   const char *run_as_user;              // User name or "#uid" (optional)
19   const char *run_as_group;             // Group name or "#gid" (optional)
20
21   // Internal
22   uid_t run_as_uid;
23   uid_t run_as_gid;
24   int want_setuid;
25   int want_setgid;
26   int pid_fd;
27 };
28
29 enum daemon_flags {
30   DAEMON_FLAG_PRESERVE_CWD = 1,         // Skip chdir("/")
31 };
32
33 void daemon_init(struct daemon_params *dp);
34
35 void daemon_run(struct daemon_params *dp, void (*body)(struct daemon_params *dp));
36
37 void daemon_exit(struct daemon_params *dp);
38
39 #endif