tests: Add test suite for packets.h.
[openvswitch] / lib / daemon.h
1 /*
2  * Copyright (c) 2008, 2009, 2010 Nicira Networks.
3  *
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:
7  *
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.
15  */
16
17 #ifndef DAEMON_H
18 #define DAEMON_H 1
19
20 #include <limits.h>
21 #include <stdbool.h>
22 #include <sys/types.h>
23
24 enum {
25     OPT_DETACH = UCHAR_MAX + 2048,
26     OPT_NO_CHDIR,
27     OPT_OVERWRITE_PIDFILE,
28     OPT_PIDFILE,
29     OPT_MONITOR
30 };
31
32 #define DAEMON_LONG_OPTIONS                                          \
33         {"detach",            no_argument, 0, OPT_DETACH},           \
34         {"no-chdir",          no_argument, 0, OPT_NO_CHDIR},         \
35         {"pidfile",           optional_argument, 0, OPT_PIDFILE},    \
36         {"overwrite-pidfile", no_argument, 0, OPT_OVERWRITE_PIDFILE},\
37         {"monitor",           no_argument, 0, OPT_MONITOR}
38
39 #define DAEMON_OPTION_HANDLERS                  \
40         case OPT_DETACH:                        \
41             set_detach();                       \
42             break;                              \
43                                                 \
44         case OPT_NO_CHDIR:                      \
45             set_no_chdir();                     \
46             break;                              \
47                                                 \
48         case OPT_PIDFILE:                       \
49             set_pidfile(optarg);                \
50             break;                              \
51                                                 \
52         case OPT_OVERWRITE_PIDFILE:             \
53             ignore_existing_pidfile();          \
54             break;                              \
55                                                 \
56         case OPT_MONITOR:                       \
57             daemon_set_monitor();               \
58             break;
59
60 char *make_pidfile_name(const char *name);
61 void set_pidfile(const char *name);
62 const char *get_pidfile(void);
63 void set_no_chdir(void);
64 bool is_chdir_enabled(void);
65 void set_detach(void);
66 bool get_detach(void);
67 void daemon_set_monitor(void);
68 void daemonize(void);
69 void daemonize_start(void);
70 void daemonize_complete(void);
71 void die_if_already_running(void);
72 void ignore_existing_pidfile(void);
73 void daemon_usage(void);
74 pid_t read_pidfile(const char *name);
75
76 #endif /* daemon.h */