chiark / gitweb /
service: interpret Debian-style X-Interactive LSB header field
[elogind.git] / src / sd-daemon.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #ifndef foosddaemonhfoo
4 #define foosddaemonhfoo
5
6 /***
7   Copyright 2010 Lennart Poettering
8
9   Permission is hereby granted, free of charge, to any person
10   obtaining a copy of this software and associated documentation files
11   (the "Software"), to deal in the Software without restriction,
12   including without limitation the rights to use, copy, modify, merge,
13   publish, distribute, sublicense, and/or sell copies of the Software,
14   and to permit persons to whom the Software is furnished to do so,
15   subject to the following conditions:
16
17   The above copyright notice and this permission notice shall be
18   included in all copies or substantial portions of the Software.
19
20   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27   SOFTWARE.
28 ***/
29
30 #include <inttypes.h>
31
32 /* Reference implementation of a few systemd related interfaces for
33  * writing daemons. These interfaces are trivial to implement, however
34  * to simplify porting we provide this reference
35  * implementation. Applications are free to reimplement the algorithms
36  * described here. */
37
38 /*
39   Log levels for usage on stderr:
40
41           fprintf(stderr, SD_NOTICE "Hello World!");
42
43   This is similar to printk() usage in the kernel.
44 */
45
46 #define SD_EMERG   "<0>"  /* system is unusable */
47 #define SD_ALERT   "<1>"  /* action must be taken immediately */
48 #define SD_CRIT    "<2>"  /* critical conditions */
49 #define SD_ERR     "<3>"  /* error conditions */
50 #define SD_WARNING "<4>"  /* warning conditions */
51 #define SD_NOTICE  "<5>"  /* normal but significant condition */
52 #define SD_INFO    "<6>"  /* informational */
53 #define SD_DEBUG   "<7>"  /* debug-level messages */
54
55 /* The first passed file descriptor is fd 3 */
56 #define SD_LISTEN_FDS_START 3
57
58 /* Returns how many file descriptors have been passed, or a negative
59  * errno code on failure. Optionally removes the $LISTEN_FDS and
60  * $LISTEN_PID file descriptors from the environment
61  * (recommended). You'll find the file descriptors passed as fds
62  * SD_LISTEN_FDS_START to SD_LISTEN_FDS_START+r-1 if r is the return
63  * value of this functioin. Returns a negative errno style error code
64  * on failure. */
65 int sd_listen_fds(int unset_environment);
66
67 /* Helper call for identifying a passed file descriptor. Returns 1 if
68  * the file descriptor is a FIFO in the file system stored under the
69  * specified path, 0 otherwise. If path is NULL a path name check will
70  * not be done and the call only verifies if the file descriptor
71  * refers to a FIFO. Returns a negative errno style error code on
72  * failure. */
73 int sd_is_fifo(int fd, const char *path);
74
75 /* Helper call for identifying a passed file descriptor. Returns 1 if
76  * the file descriptor is a socket of the specified family (AF_INET,
77  * ...) and type (SOCK_DGRAM, SOCK_STREAM, ...), 0 otherwise. If
78  * family is 0 a socket family check will not be done. If type is 0 a
79  * socket type check will not be done and the call only verifies if
80  * the file descriptor refers to a socket. If listening is > 0 it is
81  * verified that the socket is in listening mode. (i.e. listen() has
82  * been called) If listening is == 0 it is verified that the socket is
83  * not in listening mode. If listening is < 0 no listening mode check
84  * is done. Returns a negative errno style error code on failure. */
85 int sd_is_socket(int fd, int family, int type, int listening);
86
87 /* Helper call for identifying a passed file descriptor. Returns 1 if
88  * the file descriptor is an Internet socket, of the specified family
89  * (either AF_INET or AF_INET6) of the specified type (SOCK_DGRAM,
90  * SOCK_STREAM, ...), 0 otherwise. If version is 0 a protocol version
91  * check is not done. If type is 0 a socket type check will not be
92  * done. If port is 0 a socket port check will not be done. The
93  * listening flag is used the same way as in sd_is_socket(). Returns a
94  * negative errno style error code on failure. */
95 int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port);
96
97 /* Helper call for identifying a passed file descriptor. Returns 1 if
98  * the file descriptor is an AF_UNIX socket of the specified type
99  * (SOCK_DGRAM, SOCK_STREAM, ...) and path, 0 otherwise. If type is 0
100  * a socket type check will not be done. If path is NULL a socket path
101  * check will not be done. For normal AF_UNIX sockets set length to
102  * 0. For abstract namespace sockets set length to the length of the
103  * socket name (including the initial 0 byte), and pass the full
104  * socket path in path (including the initial 0 byte). The listening
105  * flag is used the same way as in sd_is_socket(). Returns a negative
106  * errno style error code on failure. */
107 int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length);
108
109 #endif