chiark / gitweb /
implement trivial socket activated logger daemon
[elogind.git] / socket.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #ifndef foosockethfoo
4 #define foosockethfoo
5
6 typedef struct Socket Socket;
7
8 #include "manager.h"
9 #include "unit.h"
10 #include "socket-util.h"
11
12 typedef enum SocketState {
13         SOCKET_DEAD,
14         SOCKET_START_PRE,
15         SOCKET_START_POST,
16         SOCKET_LISTENING,
17         SOCKET_RUNNING,
18         SOCKET_STOP_PRE,
19         SOCKET_STOP_PRE_SIGTERM,
20         SOCKET_STOP_PRE_SIGKILL,
21         SOCKET_STOP_POST,
22         SOCKET_STOP_POST_SIGTERM,
23         SOCKET_STOP_POST_SIGKILL,
24         SOCKET_MAINTAINANCE,
25         _SOCKET_STATE_MAX
26 } SocketState;
27
28 typedef enum SocketExecCommand {
29         SOCKET_EXEC_START_PRE,
30         SOCKET_EXEC_START_POST,
31         SOCKET_EXEC_STOP_PRE,
32         SOCKET_EXEC_STOP_POST,
33         _SOCKET_EXEC_MAX
34 } SocketExecCommand;
35
36 typedef enum SocketType {
37         SOCKET_SOCKET,
38         SOCKET_FIFO
39 } SocketType;
40
41 typedef struct SocketPort SocketPort;
42
43 struct SocketPort {
44         SocketType type;
45
46         SocketAddress address;
47         char *path;
48
49         int fd;
50         Watch fd_watch;
51
52         LIST_FIELDS(SocketPort, port);
53 };
54
55 struct Socket {
56         Meta meta;
57
58         LIST_HEAD(SocketPort, ports);
59
60         /* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */
61         bool bind_ipv6_only;
62         unsigned backlog;
63
64         usec_t timeout_usec;
65
66         ExecCommand* exec_command[_SOCKET_EXEC_MAX];
67         ExecContext exec_context;
68
69         Service *service;
70
71         SocketState state;
72
73         ExecCommand* control_command;
74         pid_t control_pid;
75
76         char *bind_to_device;
77
78         bool failure;
79         Watch timer_watch;
80 };
81
82 /* Called from the service code when collecting fds */
83 int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds);
84
85 /* Called from the service when it shut down */
86 void socket_notify_service_dead(Socket *s);
87
88 extern const UnitVTable socket_vtable;
89
90 #endif