]>
Commit | Line | Data |
---|---|---|
064af421 BP |
1 | /* |
2 | * Copyright (c) 2008 Nicira Networks. | |
3 | * | |
a14bc59f BP |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at: | |
064af421 | 7 | * |
a14bc59f BP |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
064af421 BP |
15 | */ |
16 | ||
17 | #ifndef DAEMON_H | |
18 | #define DAEMON_H 1 | |
19 | ||
91a1e24d | 20 | #include <limits.h> |
064af421 BP |
21 | #include <stdbool.h> |
22 | #include <sys/types.h> | |
23 | ||
91a1e24d | 24 | enum { |
e7bd7d78 JP |
25 | OPT_DETACH = UCHAR_MAX + 2048, |
26 | OPT_NO_CHDIR, | |
27 | OPT_OVERWRITE_PIDFILE, | |
28 | OPT_PIDFILE, | |
91a1e24d JP |
29 | }; |
30 | ||
e7bd7d78 JP |
31 | #define DAEMON_LONG_OPTIONS \ |
32 | {"detach", no_argument, 0, OPT_DETACH}, \ | |
33 | {"no-chdir", no_argument, 0, OPT_NO_CHDIR}, \ | |
34 | {"pidfile", optional_argument, 0, OPT_PIDFILE}, \ | |
35 | {"overwrite-pidfile", no_argument, 0, OPT_OVERWRITE_PIDFILE} | |
064af421 BP |
36 | |
37 | #define DAEMON_OPTION_HANDLERS \ | |
e7bd7d78 | 38 | case OPT_DETACH: \ |
064af421 BP |
39 | set_detach(); \ |
40 | break; \ | |
41 | \ | |
91a1e24d JP |
42 | case OPT_NO_CHDIR: \ |
43 | set_no_chdir(); \ | |
44 | break; \ | |
45 | \ | |
e7bd7d78 | 46 | case OPT_PIDFILE: \ |
064af421 BP |
47 | set_pidfile(optarg); \ |
48 | break; \ | |
49 | \ | |
e7bd7d78 | 50 | case OPT_OVERWRITE_PIDFILE: \ |
064af421 BP |
51 | ignore_existing_pidfile(); \ |
52 | break; | |
53 | ||
54 | char *make_pidfile_name(const char *name); | |
55 | void set_pidfile(const char *name); | |
56 | const char *get_pidfile(void); | |
91a1e24d | 57 | void set_no_chdir(void); |
064af421 BP |
58 | void set_detach(void); |
59 | void daemonize(void); | |
60 | void die_if_already_running(void); | |
61 | void ignore_existing_pidfile(void); | |
62 | void daemon_usage(void); | |
63 | pid_t read_pidfile(const char *name); | |
64 | ||
65 | #endif /* daemon.h */ |