chiark / gitweb /
mount: parse both parts of the mount options from /proc/self/mountinfo
[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. To
34  * simplify porting we provide this reference
35  * implementation. Applications are welcome to reimplement the
36  * algorithms described here, if they do not want to include these two
37  * source files. */
38
39 /*
40   Log levels for usage on stderr:
41
42           fprintf(stderr, SD_NOTICE "Hello World!");
43
44   This is similar to printk() usage in the kernel.
45 */
46
47 #define SD_EMERG   "<0>"  /* system is unusable */
48 #define SD_ALERT   "<1>"  /* action must be taken immediately */
49 #define SD_CRIT    "<2>"  /* critical conditions */
50 #define SD_ERR     "<3>"  /* error conditions */
51 #define SD_WARNING "<4>"  /* warning conditions */
52 #define SD_NOTICE  "<5>"  /* normal but significant condition */
53 #define SD_INFO    "<6>"  /* informational */
54 #define SD_DEBUG   "<7>"  /* debug-level messages */
55
56 /* The first passed file descriptor is fd 3 */
57 #define SD_LISTEN_FDS_START 3
58
59 /* Returns how many file descriptors have been passed, or a negative
60  * errno code on failure. Optionally, removes the $LISTEN_FDS and
61  * $LISTEN_PID file descriptors from the environment (recommended, but
62  * problematic in threaded environments). If r is the return value of
63  * this function you'll find the file descriptors passed as fds
64  * SD_LISTEN_FDS_START to SD_LISTEN_FDS_START+r-1. Returns a negative
65  * errno style error code on failure. This function call ensures that
66  * the FD_CLOEXEC flag is set for the passed file descriptors, to make
67  * sure they are not passed on to child processes. If FD_CLOEXEC shall
68  * not be set, the caller needs to unset it after this call for all file
69  * descriptors that are used.*/
70 int sd_listen_fds(int unset_environment);
71
72 /* Helper call for identifying a passed file descriptor. Returns 1 if
73  * the file descriptor is a FIFO in the file system stored under the
74  * specified path, 0 otherwise. If path is NULL a path name check will
75  * not be done and the call only verifies if the file descriptor
76  * refers to a FIFO. Returns a negative errno style error code on
77  * failure. */
78 int sd_is_fifo(int fd, const char *path);
79
80 /* Helper call for identifying a passed file descriptor. Returns 1 if
81  * the file descriptor is a socket of the specified family (AF_INET,
82  * ...) and type (SOCK_DGRAM, SOCK_STREAM, ...), 0 otherwise. If
83  * family is 0 a socket family check will not be done. If type is 0 a
84  * socket type check will not be done and the call only verifies if
85  * the file descriptor refers to a socket. If listening is > 0 it is
86  * verified that the socket is in listening mode. (i.e. listen() has
87  * been called) If listening is == 0 it is verified that the socket is
88  * not in listening mode. If listening is < 0 no listening mode check
89  * is done. Returns a negative errno style error code on failure. */
90 int sd_is_socket(int fd, int family, int type, int listening);
91
92 /* Helper call for identifying a passed file descriptor. Returns 1 if
93  * the file descriptor is an Internet socket, of the specified family
94  * (either AF_INET or AF_INET6) and the specified type (SOCK_DGRAM,
95  * SOCK_STREAM, ...), 0 otherwise. If version is 0 a protocol version
96  * check is not done. If type is 0 a socket type check will not be
97  * done. If port is 0 a socket port check will not be done. The
98  * listening flag is used the same way as in sd_is_socket(). Returns a
99  * negative errno style error code on failure. */
100 int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port);
101
102 /* Helper call for identifying a passed file descriptor. Returns 1 if
103  * the file descriptor is an AF_UNIX socket of the specified type
104  * (SOCK_DGRAM, SOCK_STREAM, ...) and path, 0 otherwise. If type is 0
105  * a socket type check will not be done. If path is NULL a socket path
106  * check will not be done. For normal AF_UNIX sockets set length to
107  * 0. For abstract namespace sockets set length to the length of the
108  * socket name (including the initial 0 byte), and pass the full
109  * socket path in path (including the initial 0 byte). The listening
110  * flag is used the same way as in sd_is_socket(). Returns a negative
111  * errno style error code on failure. */
112 int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length);
113
114 #endif