]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
c2f1db8f | 2 | #pragma once |
5cb5a6ff | 3 | |
a7334b09 LP |
4 | /*** |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2010 Lennart Poettering | |
a7334b09 LP |
8 | ***/ |
9 | ||
5cb5a6ff | 10 | typedef struct Service Service; |
a354329f | 11 | typedef struct ServiceFDStore ServiceFDStore; |
5cb5a6ff | 12 | |
71d35b6b TA |
13 | #include "exit-status.h" |
14 | #include "kill.h" | |
9cf3ab0e | 15 | #include "path.h" |
1e2e8133 | 16 | #include "ratelimit.h" |
57b7a260 FS |
17 | #include "socket.h" |
18 | #include "unit.h" | |
5cb5a6ff | 19 | |
034c6ed7 | 20 | typedef enum ServiceRestart { |
525ee6f4 | 21 | SERVICE_RESTART_NO, |
034c6ed7 | 22 | SERVICE_RESTART_ON_SUCCESS, |
50caaedb | 23 | SERVICE_RESTART_ON_FAILURE, |
6cfe2fde | 24 | SERVICE_RESTART_ON_ABNORMAL, |
dc99a976 | 25 | SERVICE_RESTART_ON_WATCHDOG, |
50caaedb | 26 | SERVICE_RESTART_ON_ABORT, |
94f04347 LP |
27 | SERVICE_RESTART_ALWAYS, |
28 | _SERVICE_RESTART_MAX, | |
29 | _SERVICE_RESTART_INVALID = -1 | |
034c6ed7 LP |
30 | } ServiceRestart; |
31 | ||
32 | typedef enum ServiceType { | |
05e343b7 | 33 | SERVICE_SIMPLE, /* we fork and go on right-away (i.e. modern socket activated daemons) */ |
1f48cf56 | 34 | SERVICE_FORKING, /* forks by itself (i.e. traditional daemons) */ |
34e9ba66 | 35 | SERVICE_ONESHOT, /* we fork and wait until the program finishes (i.e. programs like fsck which run and need to finish before we continue) */ |
05e343b7 | 36 | SERVICE_DBUS, /* we fork and wait until a specific D-Bus name appears on the bus */ |
8c47c732 | 37 | SERVICE_NOTIFY, /* we fork and wait until a daemon sends us a ready message with sd_notify() */ |
f2b68789 | 38 | SERVICE_IDLE, /* much like simple, but delay exec() until all jobs are dispatched. */ |
94f04347 LP |
39 | _SERVICE_TYPE_MAX, |
40 | _SERVICE_TYPE_INVALID = -1 | |
034c6ed7 | 41 | } ServiceType; |
5cb5a6ff LP |
42 | |
43 | typedef enum ServiceExecCommand { | |
44 | SERVICE_EXEC_START_PRE, | |
45 | SERVICE_EXEC_START, | |
46 | SERVICE_EXEC_START_POST, | |
5cb5a6ff | 47 | SERVICE_EXEC_RELOAD, |
5cb5a6ff LP |
48 | SERVICE_EXEC_STOP, |
49 | SERVICE_EXEC_STOP_POST, | |
e537352b LP |
50 | _SERVICE_EXEC_COMMAND_MAX, |
51 | _SERVICE_EXEC_COMMAND_INVALID = -1 | |
5cb5a6ff LP |
52 | } ServiceExecCommand; |
53 | ||
308d72dc LP |
54 | typedef enum NotifyState { |
55 | NOTIFY_UNKNOWN, | |
56 | NOTIFY_READY, | |
57 | NOTIFY_RELOADING, | |
58 | NOTIFY_STOPPING, | |
59 | _NOTIFY_STATE_MAX, | |
60 | _NOTIFY_STATE_INVALID = -1 | |
61 | } NotifyState; | |
62 | ||
a4e26faf JW |
63 | /* The values of this enum are referenced in man/systemd.exec.xml and src/shared/bus-unit-util.c. |
64 | * Update those sources for each change to this enum. */ | |
f42806df LP |
65 | typedef enum ServiceResult { |
66 | SERVICE_SUCCESS, | |
0b2de9d9 | 67 | SERVICE_FAILURE_RESOURCES, /* a bit of a misnomer, just our catch-all error for errnos we didn't expect */ |
c35755fb | 68 | SERVICE_FAILURE_PROTOCOL, |
f42806df LP |
69 | SERVICE_FAILURE_TIMEOUT, |
70 | SERVICE_FAILURE_EXIT_CODE, | |
71 | SERVICE_FAILURE_SIGNAL, | |
72 | SERVICE_FAILURE_CORE_DUMP, | |
bb242b7b | 73 | SERVICE_FAILURE_WATCHDOG, |
07299350 | 74 | SERVICE_FAILURE_START_LIMIT_HIT, |
f42806df LP |
75 | _SERVICE_RESULT_MAX, |
76 | _SERVICE_RESULT_INVALID = -1 | |
77 | } ServiceResult; | |
78 | ||
a354329f LP |
79 | struct ServiceFDStore { |
80 | Service *service; | |
81 | ||
82 | int fd; | |
8dd4c05b | 83 | char *fdname; |
a354329f LP |
84 | sd_event_source *event_source; |
85 | ||
86 | LIST_FIELDS(ServiceFDStore, fd_store); | |
87 | }; | |
88 | ||
5cb5a6ff | 89 | struct Service { |
ac155bb8 | 90 | Unit meta; |
5cb5a6ff | 91 | |
034c6ed7 LP |
92 | ServiceType type; |
93 | ServiceRestart restart; | |
37520c1b LP |
94 | ExitStatusSet restart_prevent_status; |
95 | ExitStatusSet restart_force_status; | |
96342de6 | 96 | ExitStatusSet success_status; |
034c6ed7 LP |
97 | |
98 | /* If set we'll read the main daemon PID from this file */ | |
99 | char *pid_file; | |
100 | ||
101 | usec_t restart_usec; | |
d568a335 MS |
102 | usec_t timeout_start_usec; |
103 | usec_t timeout_stop_usec; | |
36c16a7c | 104 | usec_t runtime_max_usec; |
5cb5a6ff | 105 | |
a6927d7f | 106 | dual_timestamp watchdog_timestamp; |
bb242b7b | 107 | usec_t watchdog_usec; |
2787d83c M |
108 | usec_t watchdog_override_usec; |
109 | bool watchdog_override_enable; | |
718db961 | 110 | sd_event_source *watchdog_event_source; |
a6927d7f | 111 | |
e537352b | 112 | ExecCommand* exec_command[_SERVICE_EXEC_COMMAND_MAX]; |
4819ff03 | 113 | |
5cb5a6ff | 114 | ExecContext exec_context; |
4819ff03 | 115 | KillContext kill_context; |
4ad49000 | 116 | CGroupContext cgroup_context; |
5cb5a6ff | 117 | |
a16e1123 | 118 | ServiceState state, deserialized_state; |
034c6ed7 | 119 | |
867b3b7d | 120 | /* The exit status of the real main process */ |
034c6ed7 LP |
121 | ExecStatus main_exec_status; |
122 | ||
867b3b7d | 123 | /* The currently executed control process */ |
034c6ed7 | 124 | ExecCommand *control_command; |
867b3b7d LP |
125 | |
126 | /* The currently executed main process, which may be NULL if | |
127 | * the main process got started via forking mode and not by | |
128 | * us */ | |
129 | ExecCommand *main_command; | |
130 | ||
131 | /* The ID of the control command currently being executed */ | |
a16e1123 | 132 | ServiceExecCommand control_command_id; |
867b3b7d | 133 | |
613b411c LP |
134 | /* Runtime data of the execution context */ |
135 | ExecRuntime *exec_runtime; | |
29206d46 | 136 | DynamicCreds dynamic_creds; |
613b411c | 137 | |
034c6ed7 | 138 | pid_t main_pid, control_pid; |
07459bb6 | 139 | int socket_fd; |
9d565427 | 140 | SocketPeer *peer; |
16115b0a | 141 | bool socket_fd_selinux_context_net; |
8fe914ec LP |
142 | |
143 | bool permissions_start_only; | |
144 | bool root_directory_start_only; | |
02ee865a | 145 | bool remain_after_exit; |
3185a36b | 146 | bool guess_main_pid; |
8fe914ec | 147 | |
05e343b7 | 148 | /* If we shut down, remember why */ |
f42806df LP |
149 | ServiceResult result; |
150 | ServiceResult reload_result; | |
e2f3b44c | 151 | |
5de6b302 | 152 | bool main_pid_known:1; |
6dfa5494 | 153 | bool main_pid_alien:1; |
05e343b7 | 154 | bool bus_name_good:1; |
47342320 | 155 | bool forbid_restart:1; |
deb4e708 MK |
156 | /* Keep restart intention between UNIT_FAILED and UNIT_ACTIVATING */ |
157 | bool will_auto_restart:1; | |
d568a335 | 158 | bool start_timeout_defined:1; |
2c4104f0 | 159 | |
05e343b7 | 160 | char *bus_name; |
d8ccf5fd | 161 | char *bus_name_owner; /* unique name of the current owner */ |
05e343b7 | 162 | |
8c47c732 | 163 | char *status_text; |
4774e357 | 164 | int status_errno; |
8c47c732 | 165 | |
57020a3a | 166 | UnitRef accept_socket; |
4f2d528d | 167 | |
718db961 | 168 | sd_event_source *timer_event_source; |
3a111838 | 169 | PathSpec *pid_file_pathspec; |
8fe914ec LP |
170 | |
171 | NotifyAccess notify_access; | |
308d72dc | 172 | NotifyState notify_state; |
a354329f LP |
173 | |
174 | ServiceFDStore *fd_store; | |
da6053d0 | 175 | size_t n_fd_store; |
a354329f | 176 | unsigned n_fd_store_max; |
7eb2a8a1 | 177 | unsigned n_keep_fd_store; |
6b7e5923 PS |
178 | |
179 | char *usb_function_descriptors; | |
180 | char *usb_function_strings; | |
a34ceba6 LP |
181 | |
182 | int stdin_fd; | |
183 | int stdout_fd; | |
184 | int stderr_fd; | |
7a0019d3 LP |
185 | |
186 | unsigned n_restarts; | |
187 | bool flush_n_restarts; | |
5cb5a6ff LP |
188 | }; |
189 | ||
47be870b | 190 | extern const UnitVTable service_vtable; |
5cb5a6ff | 191 | |
16115b0a | 192 | int service_set_socket_fd(Service *s, int fd, struct Socket *socket, bool selinux_context_net); |
3e7a1f50 | 193 | void service_close_socket_fd(Service *s); |
4f2d528d | 194 | |
44a6b1b6 ZJS |
195 | const char* service_restart_to_string(ServiceRestart i) _const_; |
196 | ServiceRestart service_restart_from_string(const char *s) _pure_; | |
94f04347 | 197 | |
44a6b1b6 ZJS |
198 | const char* service_type_to_string(ServiceType i) _const_; |
199 | ServiceType service_type_from_string(const char *s) _pure_; | |
94f04347 | 200 | |
44a6b1b6 ZJS |
201 | const char* service_exec_command_to_string(ServiceExecCommand i) _const_; |
202 | ServiceExecCommand service_exec_command_from_string(const char *s) _pure_; | |
94f04347 | 203 | |
308d72dc LP |
204 | const char* notify_state_to_string(NotifyState i) _const_; |
205 | NotifyState notify_state_from_string(const char *s) _pure_; | |
206 | ||
44a6b1b6 ZJS |
207 | const char* service_result_to_string(ServiceResult i) _const_; |
208 | ServiceResult service_result_from_string(const char *s) _pure_; | |
57b7a260 FS |
209 | |
210 | DEFINE_CAST(SERVICE, Service); |