Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 1 | /*-*- Mode: C; c-basic-offset: 8 -*-*/ |
| 2 | |
Lennart Poettering | a7334b0 | 2010-02-03 13:03:47 +0100 | [diff] [blame] | 3 | /*** |
| 4 | This file is part of systemd. |
| 5 | |
| 6 | Copyright 2010 Lennart Poettering |
| 7 | |
| 8 | systemd is free software; you can redistribute it and/or modify it |
| 9 | under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | systemd is distributed in the hope that it will be useful, but |
| 14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
| 20 | ***/ |
| 21 | |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 22 | #include <linux/oom.h> |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 23 | #include <assert.h> |
| 24 | #include <errno.h> |
| 25 | #include <string.h> |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 26 | #include <unistd.h> |
| 27 | #include <fcntl.h> |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 28 | #include <sched.h> |
| 29 | #include <sys/prctl.h> |
Lennart Poettering | 15ae422 | 2010-04-21 22:15:06 +0200 | [diff] [blame] | 30 | #include <sys/mount.h> |
Kay Sievers | 25e870b | 2010-04-24 05:05:01 +0200 | [diff] [blame] | 31 | #include <linux/fs.h> |
Lennart Poettering | 45fb069 | 2010-07-17 00:57:51 +0200 | [diff] [blame^] | 32 | #include <sys/stat.h> |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 33 | |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 34 | #include "unit.h" |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 35 | #include "strv.h" |
| 36 | #include "conf-parser.h" |
| 37 | #include "load-fragment.h" |
Lennart Poettering | 16354ef | 2010-01-20 19:19:53 +0100 | [diff] [blame] | 38 | #include "log.h" |
Lennart Poettering | 9eba9da | 2010-01-29 20:46:22 +0100 | [diff] [blame] | 39 | #include "ioprio.h" |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 40 | #include "securebits.h" |
| 41 | #include "missing.h" |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 42 | #include "unit-name.h" |
Lennart Poettering | 398ef8b | 2010-07-08 02:43:18 +0200 | [diff] [blame] | 43 | #include "bus-errors.h" |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 44 | |
Lennart Poettering | ddb26e1 | 2010-06-18 06:06:24 +0200 | [diff] [blame] | 45 | #define COMMENTS "#;\n" |
Lennart Poettering | ddb26e1 | 2010-06-18 06:06:24 +0200 | [diff] [blame] | 46 | |
Lennart Poettering | 42f4e3c | 2010-01-19 02:56:37 +0100 | [diff] [blame] | 47 | static int config_parse_deps( |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 48 | const char *filename, |
| 49 | unsigned line, |
| 50 | const char *section, |
| 51 | const char *lvalue, |
| 52 | const char *rvalue, |
| 53 | void *data, |
| 54 | void *userdata) { |
| 55 | |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 56 | UnitDependency d = PTR_TO_UINT(data); |
| 57 | Unit *u = userdata; |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 58 | char *w; |
| 59 | size_t l; |
| 60 | char *state; |
| 61 | |
| 62 | assert(filename); |
| 63 | assert(lvalue); |
| 64 | assert(rvalue); |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 65 | |
Lennart Poettering | f60f22d | 2010-07-07 20:58:41 +0200 | [diff] [blame] | 66 | FOREACH_WORD_QUOTED(w, l, rvalue, state) { |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 67 | char *t, *k; |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 68 | int r; |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 69 | |
| 70 | if (!(t = strndup(w, l))) |
| 71 | return -ENOMEM; |
| 72 | |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 73 | k = unit_name_printf(u, t); |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 74 | free(t); |
| 75 | |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 76 | if (!k) |
| 77 | return -ENOMEM; |
| 78 | |
Lennart Poettering | 701cc38 | 2010-04-21 06:01:13 +0200 | [diff] [blame] | 79 | r = unit_add_dependency_by_name(u, d, k, NULL, true); |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 80 | free(k); |
| 81 | |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 82 | if (r < 0) |
| 83 | return r; |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
Lennart Poettering | 42f4e3c | 2010-01-19 02:56:37 +0100 | [diff] [blame] | 89 | static int config_parse_names( |
Lennart Poettering | 87d1515 | 2010-01-18 23:50:13 +0100 | [diff] [blame] | 90 | const char *filename, |
| 91 | unsigned line, |
| 92 | const char *section, |
| 93 | const char *lvalue, |
| 94 | const char *rvalue, |
| 95 | void *data, |
| 96 | void *userdata) { |
| 97 | |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 98 | Unit *u = userdata; |
Lennart Poettering | 87d1515 | 2010-01-18 23:50:13 +0100 | [diff] [blame] | 99 | char *w; |
| 100 | size_t l; |
| 101 | char *state; |
| 102 | |
| 103 | assert(filename); |
| 104 | assert(lvalue); |
| 105 | assert(rvalue); |
| 106 | assert(data); |
| 107 | |
Lennart Poettering | f60f22d | 2010-07-07 20:58:41 +0200 | [diff] [blame] | 108 | FOREACH_WORD_QUOTED(w, l, rvalue, state) { |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 109 | char *t, *k; |
Lennart Poettering | 87d1515 | 2010-01-18 23:50:13 +0100 | [diff] [blame] | 110 | int r; |
Lennart Poettering | 87d1515 | 2010-01-18 23:50:13 +0100 | [diff] [blame] | 111 | |
| 112 | if (!(t = strndup(w, l))) |
| 113 | return -ENOMEM; |
| 114 | |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 115 | k = unit_name_printf(u, t); |
Lennart Poettering | 87d1515 | 2010-01-18 23:50:13 +0100 | [diff] [blame] | 116 | free(t); |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 117 | |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 118 | if (!k) |
| 119 | return -ENOMEM; |
| 120 | |
| 121 | r = unit_merge_by_name(u, k); |
| 122 | free(k); |
| 123 | |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 124 | if (r < 0) |
| 125 | return r; |
Lennart Poettering | 87d1515 | 2010-01-18 23:50:13 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
Lennart Poettering | f2d3769 | 2010-06-18 23:25:19 +0200 | [diff] [blame] | 131 | static int config_parse_string_printf( |
Lennart Poettering | 932921b | 2010-04-24 03:11:01 +0200 | [diff] [blame] | 132 | const char *filename, |
| 133 | unsigned line, |
| 134 | const char *section, |
| 135 | const char *lvalue, |
| 136 | const char *rvalue, |
| 137 | void *data, |
| 138 | void *userdata) { |
| 139 | |
| 140 | Unit *u = userdata; |
Lennart Poettering | f2d3769 | 2010-06-18 23:25:19 +0200 | [diff] [blame] | 141 | char **s = data; |
Lennart Poettering | 932921b | 2010-04-24 03:11:01 +0200 | [diff] [blame] | 142 | char *k; |
| 143 | |
| 144 | assert(filename); |
| 145 | assert(lvalue); |
| 146 | assert(rvalue); |
Lennart Poettering | f2d3769 | 2010-06-18 23:25:19 +0200 | [diff] [blame] | 147 | assert(s); |
| 148 | assert(u); |
Lennart Poettering | 932921b | 2010-04-24 03:11:01 +0200 | [diff] [blame] | 149 | |
| 150 | if (!(k = unit_full_printf(u, rvalue))) |
| 151 | return -ENOMEM; |
| 152 | |
Lennart Poettering | f2d3769 | 2010-06-18 23:25:19 +0200 | [diff] [blame] | 153 | free(*s); |
Lennart Poettering | 932921b | 2010-04-24 03:11:01 +0200 | [diff] [blame] | 154 | if (*k) |
Lennart Poettering | f2d3769 | 2010-06-18 23:25:19 +0200 | [diff] [blame] | 155 | *s = k; |
Lennart Poettering | 932921b | 2010-04-24 03:11:01 +0200 | [diff] [blame] | 156 | else { |
| 157 | free(k); |
Lennart Poettering | f2d3769 | 2010-06-18 23:25:19 +0200 | [diff] [blame] | 158 | *s = NULL; |
Lennart Poettering | 932921b | 2010-04-24 03:11:01 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
Lennart Poettering | 42f4e3c | 2010-01-19 02:56:37 +0100 | [diff] [blame] | 164 | static int config_parse_listen( |
| 165 | const char *filename, |
| 166 | unsigned line, |
| 167 | const char *section, |
| 168 | const char *lvalue, |
| 169 | const char *rvalue, |
| 170 | void *data, |
| 171 | void *userdata) { |
| 172 | |
Lennart Poettering | 16354ef | 2010-01-20 19:19:53 +0100 | [diff] [blame] | 173 | int r; |
Lennart Poettering | 542563b | 2010-01-23 03:35:54 +0100 | [diff] [blame] | 174 | SocketPort *p; |
| 175 | Socket *s; |
Lennart Poettering | 16354ef | 2010-01-20 19:19:53 +0100 | [diff] [blame] | 176 | |
Lennart Poettering | 42f4e3c | 2010-01-19 02:56:37 +0100 | [diff] [blame] | 177 | assert(filename); |
| 178 | assert(lvalue); |
| 179 | assert(rvalue); |
| 180 | assert(data); |
| 181 | |
Lennart Poettering | 542563b | 2010-01-23 03:35:54 +0100 | [diff] [blame] | 182 | s = (Socket*) data; |
| 183 | |
| 184 | if (!(p = new0(SocketPort, 1))) |
| 185 | return -ENOMEM; |
| 186 | |
| 187 | if (streq(lvalue, "ListenFIFO")) { |
| 188 | p->type = SOCKET_FIFO; |
| 189 | |
| 190 | if (!(p->path = strdup(rvalue))) { |
| 191 | free(p); |
| 192 | return -ENOMEM; |
| 193 | } |
Lennart Poettering | 01f7847 | 2010-05-24 05:25:33 +0200 | [diff] [blame] | 194 | |
| 195 | path_kill_slashes(p->path); |
Lennart Poettering | 542563b | 2010-01-23 03:35:54 +0100 | [diff] [blame] | 196 | } else { |
| 197 | p->type = SOCKET_SOCKET; |
| 198 | |
| 199 | if ((r = socket_address_parse(&p->address, rvalue)) < 0) { |
| 200 | log_error("[%s:%u] Failed to parse address value: %s", filename, line, rvalue); |
| 201 | free(p); |
| 202 | return r; |
| 203 | } |
| 204 | |
| 205 | if (streq(lvalue, "ListenStream")) |
| 206 | p->address.type = SOCK_STREAM; |
| 207 | else if (streq(lvalue, "ListenDatagram")) |
| 208 | p->address.type = SOCK_DGRAM; |
| 209 | else { |
| 210 | assert(streq(lvalue, "ListenSequentialPacket")); |
| 211 | p->address.type = SOCK_SEQPACKET; |
| 212 | } |
| 213 | |
| 214 | if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) { |
| 215 | free(p); |
| 216 | return -EPROTONOSUPPORT; |
| 217 | } |
Lennart Poettering | 16354ef | 2010-01-20 19:19:53 +0100 | [diff] [blame] | 218 | } |
| 219 | |
Lennart Poettering | 542563b | 2010-01-23 03:35:54 +0100 | [diff] [blame] | 220 | p->fd = -1; |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 221 | LIST_PREPEND(SocketPort, port, s->ports, p); |
Lennart Poettering | 542563b | 2010-01-23 03:35:54 +0100 | [diff] [blame] | 222 | |
Lennart Poettering | 16354ef | 2010-01-20 19:19:53 +0100 | [diff] [blame] | 223 | return 0; |
Lennart Poettering | 42f4e3c | 2010-01-19 02:56:37 +0100 | [diff] [blame] | 224 | } |
| 225 | |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 226 | static int config_parse_socket_bind( |
Lennart Poettering | 42f4e3c | 2010-01-19 02:56:37 +0100 | [diff] [blame] | 227 | const char *filename, |
| 228 | unsigned line, |
| 229 | const char *section, |
| 230 | const char *lvalue, |
| 231 | const char *rvalue, |
| 232 | void *data, |
| 233 | void *userdata) { |
| 234 | |
Lennart Poettering | 542563b | 2010-01-23 03:35:54 +0100 | [diff] [blame] | 235 | Socket *s; |
Lennart Poettering | c0120d9 | 2010-05-21 23:41:25 +0200 | [diff] [blame] | 236 | SocketAddressBindIPv6Only b; |
Lennart Poettering | 42f4e3c | 2010-01-19 02:56:37 +0100 | [diff] [blame] | 237 | |
| 238 | assert(filename); |
| 239 | assert(lvalue); |
| 240 | assert(rvalue); |
| 241 | assert(data); |
| 242 | |
Lennart Poettering | 542563b | 2010-01-23 03:35:54 +0100 | [diff] [blame] | 243 | s = (Socket*) data; |
| 244 | |
Lennart Poettering | c0120d9 | 2010-05-21 23:41:25 +0200 | [diff] [blame] | 245 | if ((b = socket_address_bind_ipv6_only_from_string(rvalue)) < 0) { |
| 246 | int r; |
Lennart Poettering | 42f4e3c | 2010-01-19 02:56:37 +0100 | [diff] [blame] | 247 | |
Lennart Poettering | c0120d9 | 2010-05-21 23:41:25 +0200 | [diff] [blame] | 248 | if ((r = parse_boolean(rvalue)) < 0) { |
| 249 | log_error("[%s:%u] Failed to parse bind IPv6 only value: %s", filename, line, rvalue); |
| 250 | return -EBADMSG; |
| 251 | } |
| 252 | |
| 253 | s->bind_ipv6_only = r ? SOCKET_ADDRESS_IPV6_ONLY : SOCKET_ADDRESS_BOTH; |
| 254 | } else |
| 255 | s->bind_ipv6_only = b; |
Lennart Poettering | 542563b | 2010-01-23 03:35:54 +0100 | [diff] [blame] | 256 | |
Lennart Poettering | 42f4e3c | 2010-01-19 02:56:37 +0100 | [diff] [blame] | 257 | return 0; |
| 258 | } |
| 259 | |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 260 | static int config_parse_nice( |
| 261 | const char *filename, |
| 262 | unsigned line, |
| 263 | const char *section, |
| 264 | const char *lvalue, |
| 265 | const char *rvalue, |
| 266 | void *data, |
| 267 | void *userdata) { |
| 268 | |
Lennart Poettering | fb33a39 | 2010-01-28 02:53:56 +0100 | [diff] [blame] | 269 | ExecContext *c = data; |
| 270 | int priority, r; |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 271 | |
| 272 | assert(filename); |
| 273 | assert(lvalue); |
| 274 | assert(rvalue); |
| 275 | assert(data); |
| 276 | |
| 277 | if ((r = safe_atoi(rvalue, &priority)) < 0) { |
| 278 | log_error("[%s:%u] Failed to parse nice priority: %s", filename, line, rvalue); |
| 279 | return r; |
| 280 | } |
| 281 | |
| 282 | if (priority < PRIO_MIN || priority >= PRIO_MAX) { |
| 283 | log_error("[%s:%u] Nice priority out of range: %s", filename, line, rvalue); |
| 284 | return -ERANGE; |
| 285 | } |
| 286 | |
Lennart Poettering | fb33a39 | 2010-01-28 02:53:56 +0100 | [diff] [blame] | 287 | c->nice = priority; |
| 288 | c->nice_set = false; |
| 289 | |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static int config_parse_oom_adjust( |
| 294 | const char *filename, |
| 295 | unsigned line, |
| 296 | const char *section, |
| 297 | const char *lvalue, |
| 298 | const char *rvalue, |
| 299 | void *data, |
| 300 | void *userdata) { |
| 301 | |
Lennart Poettering | fb33a39 | 2010-01-28 02:53:56 +0100 | [diff] [blame] | 302 | ExecContext *c = data; |
| 303 | int oa, r; |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 304 | |
| 305 | assert(filename); |
| 306 | assert(lvalue); |
| 307 | assert(rvalue); |
| 308 | assert(data); |
| 309 | |
| 310 | if ((r = safe_atoi(rvalue, &oa)) < 0) { |
| 311 | log_error("[%s:%u] Failed to parse OOM adjust value: %s", filename, line, rvalue); |
| 312 | return r; |
| 313 | } |
| 314 | |
| 315 | if (oa < OOM_DISABLE || oa > OOM_ADJUST_MAX) { |
| 316 | log_error("[%s:%u] OOM adjust value out of range: %s", filename, line, rvalue); |
| 317 | return -ERANGE; |
| 318 | } |
| 319 | |
Lennart Poettering | fb33a39 | 2010-01-28 02:53:56 +0100 | [diff] [blame] | 320 | c->oom_adjust = oa; |
| 321 | c->oom_adjust_set = true; |
| 322 | |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 323 | return 0; |
| 324 | } |
| 325 | |
Lennart Poettering | b5a0699 | 2010-02-12 02:02:14 +0100 | [diff] [blame] | 326 | static int config_parse_mode( |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 327 | const char *filename, |
| 328 | unsigned line, |
| 329 | const char *section, |
| 330 | const char *lvalue, |
| 331 | const char *rvalue, |
| 332 | void *data, |
| 333 | void *userdata) { |
| 334 | |
| 335 | mode_t *m = data; |
| 336 | long l; |
| 337 | char *x = NULL; |
| 338 | |
| 339 | assert(filename); |
| 340 | assert(lvalue); |
| 341 | assert(rvalue); |
| 342 | assert(data); |
| 343 | |
| 344 | errno = 0; |
| 345 | l = strtol(rvalue, &x, 8); |
| 346 | if (!x || *x || errno) { |
Lennart Poettering | b5a0699 | 2010-02-12 02:02:14 +0100 | [diff] [blame] | 347 | log_error("[%s:%u] Failed to parse mode value: %s", filename, line, rvalue); |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 348 | return errno ? -errno : -EINVAL; |
| 349 | } |
| 350 | |
Lennart Poettering | b5a0699 | 2010-02-12 02:02:14 +0100 | [diff] [blame] | 351 | if (l < 0000 || l > 07777) { |
| 352 | log_error("[%s:%u] mode value out of range: %s", filename, line, rvalue); |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 353 | return -ERANGE; |
| 354 | } |
| 355 | |
| 356 | *m = (mode_t) l; |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | static int config_parse_exec( |
| 361 | const char *filename, |
| 362 | unsigned line, |
| 363 | const char *section, |
| 364 | const char *lvalue, |
| 365 | const char *rvalue, |
| 366 | void *data, |
| 367 | void *userdata) { |
| 368 | |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 369 | ExecCommand **e = data, *nce; |
| 370 | char *path, **n; |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 371 | unsigned k; |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 372 | |
| 373 | assert(filename); |
| 374 | assert(lvalue); |
| 375 | assert(rvalue); |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 376 | assert(e); |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 377 | |
Lennart Poettering | 6c666e2 | 2010-05-19 21:51:53 +0200 | [diff] [blame] | 378 | /* We accept an absolute path as first argument, or |
| 379 | * alternatively an absolute prefixed with @ to allow |
| 380 | * overriding of argv[0]. */ |
| 381 | |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 382 | for (;;) { |
| 383 | char *w; |
| 384 | size_t l; |
| 385 | char *state; |
Lennart Poettering | b708e7c | 2010-07-12 02:25:42 +0200 | [diff] [blame] | 386 | bool honour_argv0 = false, ignore = false; |
Lennart Poettering | 6c666e2 | 2010-05-19 21:51:53 +0200 | [diff] [blame] | 387 | |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 388 | path = NULL; |
| 389 | nce = NULL; |
| 390 | n = NULL; |
Lennart Poettering | 6c666e2 | 2010-05-19 21:51:53 +0200 | [diff] [blame] | 391 | |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 392 | rvalue += strspn(rvalue, WHITESPACE); |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 393 | |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 394 | if (rvalue[0] == 0) |
| 395 | break; |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 396 | |
Lennart Poettering | b708e7c | 2010-07-12 02:25:42 +0200 | [diff] [blame] | 397 | if (rvalue[0] == '-') { |
| 398 | ignore = true; |
| 399 | rvalue ++; |
| 400 | } |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 401 | |
Lennart Poettering | b708e7c | 2010-07-12 02:25:42 +0200 | [diff] [blame] | 402 | if (rvalue[0] == '@') { |
| 403 | honour_argv0 = true; |
| 404 | rvalue ++; |
| 405 | } |
| 406 | |
| 407 | if (*rvalue != '/') { |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 408 | log_error("[%s:%u] Invalid executable path in command line: %s", filename, line, rvalue); |
| 409 | return -EINVAL; |
Lennart Poettering | 6c666e2 | 2010-05-19 21:51:53 +0200 | [diff] [blame] | 410 | } |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 411 | |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 412 | k = 0; |
| 413 | FOREACH_WORD_QUOTED(w, l, rvalue, state) { |
| 414 | if (strncmp(w, ";", l) == 0) |
| 415 | break; |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 416 | |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 417 | k++; |
| 418 | } |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 419 | |
Lennart Poettering | b708e7c | 2010-07-12 02:25:42 +0200 | [diff] [blame] | 420 | if (!(n = new(char*, k + !honour_argv0))) |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 421 | return -ENOMEM; |
| 422 | |
| 423 | k = 0; |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 424 | FOREACH_WORD_QUOTED(w, l, rvalue, state) { |
| 425 | if (strncmp(w, ";", l) == 0) |
| 426 | break; |
| 427 | |
Lennart Poettering | b708e7c | 2010-07-12 02:25:42 +0200 | [diff] [blame] | 428 | if (honour_argv0 && w == rvalue) { |
| 429 | assert(!path); |
| 430 | if (!(path = cunescape_length(w, l))) |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 431 | goto fail; |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 432 | } else { |
| 433 | if (!(n[k++] = cunescape_length(w, l))) |
| 434 | goto fail; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | n[k] = NULL; |
| 439 | |
| 440 | if (!n[0]) { |
| 441 | log_error("[%s:%u] Invalid command line: %s", filename, line, rvalue); |
| 442 | strv_free(n); |
| 443 | return -EINVAL; |
| 444 | } |
| 445 | |
| 446 | if (!path) |
| 447 | if (!(path = strdup(n[0]))) |
| 448 | goto fail; |
| 449 | |
| 450 | assert(path_is_absolute(path)); |
| 451 | |
| 452 | if (!(nce = new0(ExecCommand, 1))) |
Lennart Poettering | 6c666e2 | 2010-05-19 21:51:53 +0200 | [diff] [blame] | 453 | goto fail; |
| 454 | |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 455 | nce->argv = n; |
| 456 | nce->path = path; |
Lennart Poettering | b708e7c | 2010-07-12 02:25:42 +0200 | [diff] [blame] | 457 | nce->ignore = ignore; |
Lennart Poettering | 6c666e2 | 2010-05-19 21:51:53 +0200 | [diff] [blame] | 458 | |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 459 | path_kill_slashes(nce->path); |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 460 | |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 461 | exec_command_append_list(e, nce); |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 462 | |
Lennart Poettering | 61e5d8e | 2010-07-07 20:59:20 +0200 | [diff] [blame] | 463 | rvalue = state; |
| 464 | } |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 465 | |
| 466 | return 0; |
| 467 | |
| 468 | fail: |
Lennart Poettering | 6c666e2 | 2010-05-19 21:51:53 +0200 | [diff] [blame] | 469 | n[k] = NULL; |
| 470 | strv_free(n); |
| 471 | free(path); |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 472 | free(nce); |
| 473 | |
| 474 | return -ENOMEM; |
| 475 | } |
| 476 | |
| 477 | static int config_parse_usec( |
| 478 | const char *filename, |
| 479 | unsigned line, |
| 480 | const char *section, |
| 481 | const char *lvalue, |
| 482 | const char *rvalue, |
| 483 | void *data, |
| 484 | void *userdata) { |
| 485 | |
| 486 | usec_t *usec = data; |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 487 | int r; |
| 488 | |
| 489 | assert(filename); |
| 490 | assert(lvalue); |
| 491 | assert(rvalue); |
| 492 | assert(data); |
| 493 | |
Lennart Poettering | 24a6e4a | 2010-04-23 20:26:59 +0200 | [diff] [blame] | 494 | if ((r = parse_usec(rvalue, usec)) < 0) { |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 495 | log_error("[%s:%u] Failed to parse time value: %s", filename, line, rvalue); |
| 496 | return r; |
| 497 | } |
| 498 | |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 499 | return 0; |
| 500 | } |
| 501 | |
Lennart Poettering | 487393e | 2010-07-07 01:10:27 +0200 | [diff] [blame] | 502 | static DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type"); |
| 503 | static DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier"); |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 504 | |
Lennart Poettering | 47be870 | 2010-02-03 14:21:48 +0100 | [diff] [blame] | 505 | static int config_parse_bindtodevice( |
Lennart Poettering | acbb022 | 2010-01-27 04:31:52 +0100 | [diff] [blame] | 506 | const char *filename, |
| 507 | unsigned line, |
| 508 | const char *section, |
| 509 | const char *lvalue, |
| 510 | const char *rvalue, |
| 511 | void *data, |
| 512 | void *userdata) { |
| 513 | |
| 514 | Socket *s = data; |
| 515 | char *n; |
| 516 | |
| 517 | assert(filename); |
| 518 | assert(lvalue); |
| 519 | assert(rvalue); |
| 520 | assert(data); |
| 521 | |
| 522 | if (rvalue[0] && !streq(rvalue, "*")) { |
| 523 | if (!(n = strdup(rvalue))) |
| 524 | return -ENOMEM; |
| 525 | } else |
| 526 | n = NULL; |
| 527 | |
| 528 | free(s->bind_to_device); |
| 529 | s->bind_to_device = n; |
| 530 | |
| 531 | return 0; |
| 532 | } |
| 533 | |
Lennart Poettering | 487393e | 2010-07-07 01:10:27 +0200 | [diff] [blame] | 534 | static DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier"); |
| 535 | static DEFINE_CONFIG_PARSE_ENUM(config_parse_input, exec_input, ExecInput, "Failed to parse input specifier"); |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 536 | |
Lennart Poettering | 47be870 | 2010-02-03 14:21:48 +0100 | [diff] [blame] | 537 | static int config_parse_facility( |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 538 | const char *filename, |
| 539 | unsigned line, |
| 540 | const char *section, |
| 541 | const char *lvalue, |
| 542 | const char *rvalue, |
| 543 | void *data, |
| 544 | void *userdata) { |
| 545 | |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 546 | |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 547 | int *o = data, x; |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 548 | |
| 549 | assert(filename); |
| 550 | assert(lvalue); |
| 551 | assert(rvalue); |
| 552 | assert(data); |
| 553 | |
Lennart Poettering | 0d87eb4 | 2010-04-13 02:22:41 +0200 | [diff] [blame] | 554 | if ((x = log_facility_from_string(rvalue)) < 0) { |
| 555 | log_error("[%s:%u] Failed to parse log facility: %s", filename, line, rvalue); |
| 556 | return -EBADMSG; |
| 557 | } |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 558 | |
| 559 | *o = LOG_MAKEPRI(x, LOG_PRI(*o)); |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 560 | |
| 561 | return 0; |
| 562 | } |
| 563 | |
Lennart Poettering | 47be870 | 2010-02-03 14:21:48 +0100 | [diff] [blame] | 564 | static int config_parse_level( |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 565 | const char *filename, |
| 566 | unsigned line, |
| 567 | const char *section, |
| 568 | const char *lvalue, |
| 569 | const char *rvalue, |
| 570 | void *data, |
| 571 | void *userdata) { |
| 572 | |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 573 | |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 574 | int *o = data, x; |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 575 | |
| 576 | assert(filename); |
| 577 | assert(lvalue); |
| 578 | assert(rvalue); |
| 579 | assert(data); |
| 580 | |
Lennart Poettering | 0d87eb4 | 2010-04-13 02:22:41 +0200 | [diff] [blame] | 581 | if ((x = log_level_from_string(rvalue)) < 0) { |
| 582 | log_error("[%s:%u] Failed to parse log level: %s", filename, line, rvalue); |
| 583 | return -EBADMSG; |
| 584 | } |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 585 | |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 586 | *o = LOG_MAKEPRI(LOG_FAC(*o), x); |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 587 | return 0; |
| 588 | } |
| 589 | |
Lennart Poettering | 47be870 | 2010-02-03 14:21:48 +0100 | [diff] [blame] | 590 | static int config_parse_io_class( |
Lennart Poettering | 9eba9da | 2010-01-29 20:46:22 +0100 | [diff] [blame] | 591 | const char *filename, |
| 592 | unsigned line, |
| 593 | const char *section, |
| 594 | const char *lvalue, |
| 595 | const char *rvalue, |
| 596 | void *data, |
| 597 | void *userdata) { |
| 598 | |
Lennart Poettering | 9eba9da | 2010-01-29 20:46:22 +0100 | [diff] [blame] | 599 | ExecContext *c = data; |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 600 | int x; |
Lennart Poettering | 9eba9da | 2010-01-29 20:46:22 +0100 | [diff] [blame] | 601 | |
| 602 | assert(filename); |
| 603 | assert(lvalue); |
| 604 | assert(rvalue); |
| 605 | assert(data); |
| 606 | |
Lennart Poettering | 0d87eb4 | 2010-04-13 02:22:41 +0200 | [diff] [blame] | 607 | if ((x = ioprio_class_from_string(rvalue)) < 0) { |
| 608 | log_error("[%s:%u] Failed to parse IO scheduling class: %s", filename, line, rvalue); |
| 609 | return -EBADMSG; |
| 610 | } |
Lennart Poettering | 9eba9da | 2010-01-29 20:46:22 +0100 | [diff] [blame] | 611 | |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 612 | c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio)); |
Lennart Poettering | 9eba9da | 2010-01-29 20:46:22 +0100 | [diff] [blame] | 613 | c->ioprio_set = true; |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
Lennart Poettering | 47be870 | 2010-02-03 14:21:48 +0100 | [diff] [blame] | 618 | static int config_parse_io_priority( |
Lennart Poettering | 9eba9da | 2010-01-29 20:46:22 +0100 | [diff] [blame] | 619 | const char *filename, |
| 620 | unsigned line, |
| 621 | const char *section, |
| 622 | const char *lvalue, |
| 623 | const char *rvalue, |
| 624 | void *data, |
| 625 | void *userdata) { |
| 626 | |
| 627 | ExecContext *c = data; |
| 628 | int i; |
| 629 | |
| 630 | assert(filename); |
| 631 | assert(lvalue); |
| 632 | assert(rvalue); |
| 633 | assert(data); |
| 634 | |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 635 | if (safe_atoi(rvalue, &i) < 0 || i < 0 || i >= IOPRIO_BE_NR) { |
Lennart Poettering | 9eba9da | 2010-01-29 20:46:22 +0100 | [diff] [blame] | 636 | log_error("[%s:%u] Failed to parse io priority: %s", filename, line, rvalue); |
| 637 | return -EBADMSG; |
| 638 | } |
| 639 | |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 640 | c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i); |
Lennart Poettering | 9eba9da | 2010-01-29 20:46:22 +0100 | [diff] [blame] | 641 | c->ioprio_set = true; |
| 642 | |
| 643 | return 0; |
| 644 | } |
| 645 | |
Lennart Poettering | 47be870 | 2010-02-03 14:21:48 +0100 | [diff] [blame] | 646 | static int config_parse_cpu_sched_policy( |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 647 | const char *filename, |
| 648 | unsigned line, |
| 649 | const char *section, |
| 650 | const char *lvalue, |
| 651 | const char *rvalue, |
| 652 | void *data, |
| 653 | void *userdata) { |
| 654 | |
| 655 | |
| 656 | ExecContext *c = data; |
| 657 | int x; |
| 658 | |
| 659 | assert(filename); |
| 660 | assert(lvalue); |
| 661 | assert(rvalue); |
| 662 | assert(data); |
| 663 | |
Lennart Poettering | 0d87eb4 | 2010-04-13 02:22:41 +0200 | [diff] [blame] | 664 | if ((x = sched_policy_from_string(rvalue)) < 0) { |
| 665 | log_error("[%s:%u] Failed to parse CPU scheduling policy: %s", filename, line, rvalue); |
| 666 | return -EBADMSG; |
| 667 | } |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 668 | |
| 669 | c->cpu_sched_policy = x; |
| 670 | c->cpu_sched_set = true; |
| 671 | |
| 672 | return 0; |
| 673 | } |
| 674 | |
Lennart Poettering | 47be870 | 2010-02-03 14:21:48 +0100 | [diff] [blame] | 675 | static int config_parse_cpu_sched_prio( |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 676 | const char *filename, |
| 677 | unsigned line, |
| 678 | const char *section, |
| 679 | const char *lvalue, |
| 680 | const char *rvalue, |
| 681 | void *data, |
| 682 | void *userdata) { |
| 683 | |
| 684 | ExecContext *c = data; |
| 685 | int i; |
| 686 | |
| 687 | assert(filename); |
| 688 | assert(lvalue); |
| 689 | assert(rvalue); |
| 690 | assert(data); |
| 691 | |
| 692 | /* On Linux RR/FIFO have the same range */ |
| 693 | if (safe_atoi(rvalue, &i) < 0 || i < sched_get_priority_min(SCHED_RR) || i > sched_get_priority_max(SCHED_RR)) { |
| 694 | log_error("[%s:%u] Failed to parse CPU scheduling priority: %s", filename, line, rvalue); |
| 695 | return -EBADMSG; |
| 696 | } |
| 697 | |
| 698 | c->cpu_sched_priority = i; |
| 699 | c->cpu_sched_set = true; |
| 700 | |
| 701 | return 0; |
| 702 | } |
| 703 | |
Lennart Poettering | 47be870 | 2010-02-03 14:21:48 +0100 | [diff] [blame] | 704 | static int config_parse_cpu_affinity( |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 705 | const char *filename, |
| 706 | unsigned line, |
| 707 | const char *section, |
| 708 | const char *lvalue, |
| 709 | const char *rvalue, |
| 710 | void *data, |
| 711 | void *userdata) { |
| 712 | |
| 713 | ExecContext *c = data; |
| 714 | char *w; |
| 715 | size_t l; |
| 716 | char *state; |
| 717 | |
| 718 | assert(filename); |
| 719 | assert(lvalue); |
| 720 | assert(rvalue); |
| 721 | assert(data); |
| 722 | |
Lennart Poettering | f60f22d | 2010-07-07 20:58:41 +0200 | [diff] [blame] | 723 | FOREACH_WORD_QUOTED(w, l, rvalue, state) { |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 724 | char *t; |
| 725 | int r; |
| 726 | unsigned cpu; |
| 727 | |
| 728 | if (!(t = strndup(w, l))) |
| 729 | return -ENOMEM; |
| 730 | |
Lennart Poettering | 487393e | 2010-07-07 01:10:27 +0200 | [diff] [blame] | 731 | r = safe_atou(t, &cpu); |
| 732 | free(t); |
| 733 | |
Lennart Poettering | 82c121a | 2010-07-04 16:44:58 +0200 | [diff] [blame] | 734 | if (!(c->cpuset)) |
| 735 | if (!(c->cpuset = cpu_set_malloc(&c->cpuset_ncpus))) |
| 736 | return -ENOMEM; |
| 737 | |
Lennart Poettering | 82c121a | 2010-07-04 16:44:58 +0200 | [diff] [blame] | 738 | if (r < 0 || cpu >= c->cpuset_ncpus) { |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 739 | log_error("[%s:%u] Failed to parse CPU affinity: %s", filename, line, rvalue); |
| 740 | return -EBADMSG; |
| 741 | } |
| 742 | |
Lennart Poettering | 82c121a | 2010-07-04 16:44:58 +0200 | [diff] [blame] | 743 | CPU_SET_S(cpu, CPU_ALLOC_SIZE(c->cpuset_ncpus), c->cpuset); |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 744 | } |
| 745 | |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 746 | return 0; |
| 747 | } |
| 748 | |
Lennart Poettering | 47be870 | 2010-02-03 14:21:48 +0100 | [diff] [blame] | 749 | static int config_parse_capabilities( |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 750 | const char *filename, |
| 751 | unsigned line, |
| 752 | const char *section, |
| 753 | const char *lvalue, |
| 754 | const char *rvalue, |
| 755 | void *data, |
| 756 | void *userdata) { |
| 757 | |
| 758 | ExecContext *c = data; |
| 759 | cap_t cap; |
| 760 | |
| 761 | assert(filename); |
| 762 | assert(lvalue); |
| 763 | assert(rvalue); |
| 764 | assert(data); |
| 765 | |
| 766 | if (!(cap = cap_from_text(rvalue))) { |
| 767 | if (errno == ENOMEM) |
| 768 | return -ENOMEM; |
| 769 | |
| 770 | log_error("[%s:%u] Failed to parse capabilities: %s", filename, line, rvalue); |
| 771 | return -EBADMSG; |
| 772 | } |
| 773 | |
| 774 | if (c->capabilities) |
| 775 | cap_free(c->capabilities); |
| 776 | c->capabilities = cap; |
| 777 | |
| 778 | return 0; |
| 779 | } |
| 780 | |
Lennart Poettering | 47be870 | 2010-02-03 14:21:48 +0100 | [diff] [blame] | 781 | static int config_parse_secure_bits( |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 782 | const char *filename, |
| 783 | unsigned line, |
| 784 | const char *section, |
| 785 | const char *lvalue, |
| 786 | const char *rvalue, |
| 787 | void *data, |
| 788 | void *userdata) { |
| 789 | |
| 790 | ExecContext *c = data; |
| 791 | char *w; |
| 792 | size_t l; |
| 793 | char *state; |
| 794 | |
| 795 | assert(filename); |
| 796 | assert(lvalue); |
| 797 | assert(rvalue); |
| 798 | assert(data); |
| 799 | |
Lennart Poettering | f60f22d | 2010-07-07 20:58:41 +0200 | [diff] [blame] | 800 | FOREACH_WORD_QUOTED(w, l, rvalue, state) { |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 801 | if (first_word(w, "keep-caps")) |
| 802 | c->secure_bits |= SECURE_KEEP_CAPS; |
| 803 | else if (first_word(w, "keep-caps-locked")) |
| 804 | c->secure_bits |= SECURE_KEEP_CAPS_LOCKED; |
| 805 | else if (first_word(w, "no-setuid-fixup")) |
| 806 | c->secure_bits |= SECURE_NO_SETUID_FIXUP; |
| 807 | else if (first_word(w, "no-setuid-fixup-locked")) |
| 808 | c->secure_bits |= SECURE_NO_SETUID_FIXUP_LOCKED; |
| 809 | else if (first_word(w, "noroot")) |
| 810 | c->secure_bits |= SECURE_NOROOT; |
| 811 | else if (first_word(w, "noroot-locked")) |
| 812 | c->secure_bits |= SECURE_NOROOT_LOCKED; |
| 813 | else { |
| 814 | log_error("[%s:%u] Failed to parse secure bits: %s", filename, line, rvalue); |
| 815 | return -EBADMSG; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
Lennart Poettering | 47be870 | 2010-02-03 14:21:48 +0100 | [diff] [blame] | 822 | static int config_parse_bounding_set( |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 823 | const char *filename, |
| 824 | unsigned line, |
| 825 | const char *section, |
| 826 | const char *lvalue, |
| 827 | const char *rvalue, |
| 828 | void *data, |
| 829 | void *userdata) { |
| 830 | |
| 831 | ExecContext *c = data; |
| 832 | char *w; |
| 833 | size_t l; |
| 834 | char *state; |
| 835 | |
| 836 | assert(filename); |
| 837 | assert(lvalue); |
| 838 | assert(rvalue); |
| 839 | assert(data); |
| 840 | |
Lennart Poettering | f60f22d | 2010-07-07 20:58:41 +0200 | [diff] [blame] | 841 | FOREACH_WORD_QUOTED(w, l, rvalue, state) { |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 842 | char *t; |
| 843 | int r; |
| 844 | cap_value_t cap; |
| 845 | |
| 846 | if (!(t = strndup(w, l))) |
| 847 | return -ENOMEM; |
| 848 | |
| 849 | r = cap_from_name(t, &cap); |
| 850 | free(t); |
| 851 | |
| 852 | if (r < 0) { |
| 853 | log_error("[%s:%u] Failed to parse capability bounding set: %s", filename, line, rvalue); |
| 854 | return -EBADMSG; |
| 855 | } |
| 856 | |
| 857 | c->capability_bounding_set_drop |= 1 << cap; |
| 858 | } |
| 859 | |
| 860 | return 0; |
| 861 | } |
| 862 | |
Lennart Poettering | 03fae01 | 2010-07-04 21:12:10 +0200 | [diff] [blame] | 863 | static int config_parse_timer_slack_nsec( |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 864 | const char *filename, |
| 865 | unsigned line, |
| 866 | const char *section, |
| 867 | const char *lvalue, |
| 868 | const char *rvalue, |
| 869 | void *data, |
| 870 | void *userdata) { |
| 871 | |
| 872 | ExecContext *c = data; |
| 873 | unsigned long u; |
| 874 | int r; |
| 875 | |
| 876 | assert(filename); |
| 877 | assert(lvalue); |
| 878 | assert(rvalue); |
| 879 | assert(data); |
| 880 | |
| 881 | if ((r = safe_atolu(rvalue, &u)) < 0) { |
| 882 | log_error("[%s:%u] Failed to parse time slack value: %s", filename, line, rvalue); |
| 883 | return r; |
| 884 | } |
| 885 | |
Lennart Poettering | 03fae01 | 2010-07-04 21:12:10 +0200 | [diff] [blame] | 886 | c->timer_slack_nsec = u; |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 887 | |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | static int config_parse_limit( |
| 892 | const char *filename, |
| 893 | unsigned line, |
| 894 | const char *section, |
| 895 | const char *lvalue, |
| 896 | const char *rvalue, |
| 897 | void *data, |
| 898 | void *userdata) { |
| 899 | |
| 900 | struct rlimit **rl = data; |
| 901 | unsigned long long u; |
| 902 | int r; |
| 903 | |
| 904 | assert(filename); |
| 905 | assert(lvalue); |
| 906 | assert(rvalue); |
| 907 | assert(data); |
| 908 | |
| 909 | if ((r = safe_atollu(rvalue, &u)) < 0) { |
| 910 | log_error("[%s:%u] Failed to parse resource value: %s", filename, line, rvalue); |
| 911 | return r; |
| 912 | } |
| 913 | |
| 914 | if (!*rl) |
| 915 | if (!(*rl = new(struct rlimit, 1))) |
| 916 | return -ENOMEM; |
| 917 | |
| 918 | (*rl)->rlim_cur = (*rl)->rlim_max = (rlim_t) u; |
| 919 | return 0; |
| 920 | } |
| 921 | |
Lennart Poettering | 8e27452 | 2010-03-31 16:29:55 +0200 | [diff] [blame] | 922 | static int config_parse_cgroup( |
| 923 | const char *filename, |
| 924 | unsigned line, |
| 925 | const char *section, |
| 926 | const char *lvalue, |
| 927 | const char *rvalue, |
| 928 | void *data, |
| 929 | void *userdata) { |
| 930 | |
| 931 | Unit *u = userdata; |
| 932 | char *w; |
| 933 | size_t l; |
| 934 | char *state; |
| 935 | |
Lennart Poettering | f60f22d | 2010-07-07 20:58:41 +0200 | [diff] [blame] | 936 | FOREACH_WORD_QUOTED(w, l, rvalue, state) { |
Lennart Poettering | 8e27452 | 2010-03-31 16:29:55 +0200 | [diff] [blame] | 937 | char *t; |
| 938 | int r; |
| 939 | |
Lennart Poettering | f60f22d | 2010-07-07 20:58:41 +0200 | [diff] [blame] | 940 | if (!(t = cunescape_length(w, l))) |
Lennart Poettering | 8e27452 | 2010-03-31 16:29:55 +0200 | [diff] [blame] | 941 | return -ENOMEM; |
| 942 | |
| 943 | r = unit_add_cgroup_from_text(u, t); |
| 944 | free(t); |
| 945 | |
| 946 | if (r < 0) |
| 947 | return r; |
| 948 | } |
| 949 | |
| 950 | return 0; |
| 951 | } |
| 952 | |
Lennart Poettering | a9a1e00 | 2010-04-06 02:40:10 +0200 | [diff] [blame] | 953 | static int config_parse_sysv_priority( |
| 954 | const char *filename, |
| 955 | unsigned line, |
| 956 | const char *section, |
| 957 | const char *lvalue, |
| 958 | const char *rvalue, |
| 959 | void *data, |
| 960 | void *userdata) { |
| 961 | |
| 962 | int *priority = data; |
| 963 | int r, i; |
| 964 | |
| 965 | assert(filename); |
| 966 | assert(lvalue); |
| 967 | assert(rvalue); |
| 968 | assert(data); |
| 969 | |
| 970 | if ((r = safe_atoi(rvalue, &i)) < 0 || i < 0) { |
| 971 | log_error("[%s:%u] Failed to parse SysV start priority: %s", filename, line, rvalue); |
| 972 | return r; |
| 973 | } |
| 974 | |
| 975 | *priority = (int) i; |
| 976 | return 0; |
| 977 | } |
| 978 | |
Lennart Poettering | 487393e | 2010-07-07 01:10:27 +0200 | [diff] [blame] | 979 | static DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode"); |
Lennart Poettering | 50159e6 | 2010-04-08 00:52:14 +0200 | [diff] [blame] | 980 | |
Lennart Poettering | 2e22afe | 2010-07-10 04:49:37 +0200 | [diff] [blame] | 981 | static int config_parse_kill_signal( |
| 982 | const char *filename, |
| 983 | unsigned line, |
| 984 | const char *section, |
| 985 | const char *lvalue, |
| 986 | const char *rvalue, |
| 987 | void *data, |
| 988 | void *userdata) { |
| 989 | |
| 990 | int *sig = data; |
| 991 | int r; |
| 992 | |
| 993 | assert(filename); |
| 994 | assert(lvalue); |
| 995 | assert(rvalue); |
| 996 | assert(sig); |
| 997 | |
| 998 | if ((r = signal_from_string(rvalue)) <= 0) |
| 999 | if (startswith(rvalue, "SIG")) |
| 1000 | r = signal_from_string(rvalue+3); |
| 1001 | |
| 1002 | if (r <= 0) { |
| 1003 | log_error("[%s:%u] Failed to parse kill signal: %s", filename, line, rvalue); |
| 1004 | return -EINVAL; |
| 1005 | } |
| 1006 | |
| 1007 | *sig = r; |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
Lennart Poettering | 15ae422 | 2010-04-21 22:15:06 +0200 | [diff] [blame] | 1011 | static int config_parse_mount_flags( |
| 1012 | const char *filename, |
| 1013 | unsigned line, |
| 1014 | const char *section, |
| 1015 | const char *lvalue, |
| 1016 | const char *rvalue, |
| 1017 | void *data, |
| 1018 | void *userdata) { |
| 1019 | |
| 1020 | ExecContext *c = data; |
| 1021 | char *w; |
| 1022 | size_t l; |
| 1023 | char *state; |
| 1024 | unsigned long flags = 0; |
| 1025 | |
| 1026 | assert(filename); |
| 1027 | assert(lvalue); |
| 1028 | assert(rvalue); |
| 1029 | assert(data); |
| 1030 | |
Lennart Poettering | f60f22d | 2010-07-07 20:58:41 +0200 | [diff] [blame] | 1031 | FOREACH_WORD_QUOTED(w, l, rvalue, state) { |
Lennart Poettering | 15ae422 | 2010-04-21 22:15:06 +0200 | [diff] [blame] | 1032 | if (strncmp(w, "shared", l) == 0) |
| 1033 | flags |= MS_SHARED; |
| 1034 | else if (strncmp(w, "slave", l) == 0) |
| 1035 | flags |= MS_SLAVE; |
| 1036 | else if (strncmp(w, "private", l) == 0) |
| 1037 | flags |= MS_PRIVATE; |
| 1038 | else { |
| 1039 | log_error("[%s:%u] Failed to parse mount flags: %s", filename, line, rvalue); |
| 1040 | return -EINVAL; |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | c->mount_flags = flags; |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
Lennart Poettering | 871d7de | 2010-05-24 01:45:54 +0200 | [diff] [blame] | 1048 | static int config_parse_timer( |
| 1049 | const char *filename, |
| 1050 | unsigned line, |
| 1051 | const char *section, |
| 1052 | const char *lvalue, |
| 1053 | const char *rvalue, |
| 1054 | void *data, |
| 1055 | void *userdata) { |
| 1056 | |
| 1057 | Timer *t = data; |
| 1058 | usec_t u; |
| 1059 | int r; |
| 1060 | TimerValue *v; |
| 1061 | TimerBase b; |
| 1062 | |
| 1063 | assert(filename); |
| 1064 | assert(lvalue); |
| 1065 | assert(rvalue); |
| 1066 | assert(data); |
| 1067 | |
| 1068 | if ((b = timer_base_from_string(lvalue)) < 0) { |
| 1069 | log_error("[%s:%u] Failed to parse timer base: %s", filename, line, lvalue); |
| 1070 | return -EINVAL; |
| 1071 | } |
| 1072 | |
| 1073 | if ((r = parse_usec(rvalue, &u)) < 0) { |
| 1074 | log_error("[%s:%u] Failed to parse timer value: %s", filename, line, rvalue); |
| 1075 | return r; |
| 1076 | } |
| 1077 | |
| 1078 | if (!(v = new0(TimerValue, 1))) |
| 1079 | return -ENOMEM; |
| 1080 | |
| 1081 | v->base = b; |
| 1082 | v->value = u; |
| 1083 | |
| 1084 | LIST_PREPEND(TimerValue, value, t->values, v); |
| 1085 | |
| 1086 | return 0; |
| 1087 | } |
| 1088 | |
| 1089 | static int config_parse_timer_unit( |
| 1090 | const char *filename, |
| 1091 | unsigned line, |
| 1092 | const char *section, |
| 1093 | const char *lvalue, |
| 1094 | const char *rvalue, |
| 1095 | void *data, |
| 1096 | void *userdata) { |
| 1097 | |
| 1098 | Timer *t = data; |
| 1099 | int r; |
Lennart Poettering | 398ef8b | 2010-07-08 02:43:18 +0200 | [diff] [blame] | 1100 | DBusError error; |
| 1101 | |
| 1102 | assert(filename); |
| 1103 | assert(lvalue); |
| 1104 | assert(rvalue); |
| 1105 | assert(data); |
| 1106 | |
| 1107 | dbus_error_init(&error); |
Lennart Poettering | 871d7de | 2010-05-24 01:45:54 +0200 | [diff] [blame] | 1108 | |
| 1109 | if (endswith(rvalue, ".timer")) { |
| 1110 | log_error("[%s:%u] Unit cannot be of type timer: %s", filename, line, rvalue); |
| 1111 | return -EINVAL; |
| 1112 | } |
| 1113 | |
Lennart Poettering | 398ef8b | 2010-07-08 02:43:18 +0200 | [diff] [blame] | 1114 | if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, NULL, &t->unit)) < 0) { |
| 1115 | log_error("[%s:%u] Failed to load unit %s: %s", filename, line, rvalue, bus_error(&error, r)); |
| 1116 | dbus_error_free(&error); |
Lennart Poettering | 871d7de | 2010-05-24 01:45:54 +0200 | [diff] [blame] | 1117 | return r; |
| 1118 | } |
| 1119 | |
| 1120 | return 0; |
| 1121 | } |
| 1122 | |
Lennart Poettering | 01f7847 | 2010-05-24 05:25:33 +0200 | [diff] [blame] | 1123 | static int config_parse_path_spec( |
| 1124 | const char *filename, |
| 1125 | unsigned line, |
| 1126 | const char *section, |
| 1127 | const char *lvalue, |
| 1128 | const char *rvalue, |
| 1129 | void *data, |
| 1130 | void *userdata) { |
| 1131 | |
| 1132 | Path *p = data; |
| 1133 | PathSpec *s; |
| 1134 | PathType b; |
| 1135 | |
| 1136 | assert(filename); |
| 1137 | assert(lvalue); |
| 1138 | assert(rvalue); |
| 1139 | assert(data); |
| 1140 | |
| 1141 | if ((b = path_type_from_string(lvalue)) < 0) { |
| 1142 | log_error("[%s:%u] Failed to parse path type: %s", filename, line, lvalue); |
| 1143 | return -EINVAL; |
| 1144 | } |
| 1145 | |
| 1146 | if (!path_is_absolute(rvalue)) { |
| 1147 | log_error("[%s:%u] Path is not absolute: %s", filename, line, rvalue); |
| 1148 | return -EINVAL; |
| 1149 | } |
| 1150 | |
| 1151 | if (!(s = new0(PathSpec, 1))) |
| 1152 | return -ENOMEM; |
| 1153 | |
| 1154 | if (!(s->path = strdup(rvalue))) { |
| 1155 | free(s); |
| 1156 | return -ENOMEM; |
| 1157 | } |
| 1158 | |
| 1159 | path_kill_slashes(s->path); |
| 1160 | |
| 1161 | s->type = b; |
| 1162 | s->inotify_fd = -1; |
| 1163 | |
| 1164 | LIST_PREPEND(PathSpec, spec, p->specs, s); |
| 1165 | |
| 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | static int config_parse_path_unit( |
| 1170 | const char *filename, |
| 1171 | unsigned line, |
| 1172 | const char *section, |
| 1173 | const char *lvalue, |
| 1174 | const char *rvalue, |
| 1175 | void *data, |
| 1176 | void *userdata) { |
| 1177 | |
| 1178 | Path *t = data; |
| 1179 | int r; |
Lennart Poettering | 398ef8b | 2010-07-08 02:43:18 +0200 | [diff] [blame] | 1180 | DBusError error; |
| 1181 | |
| 1182 | assert(filename); |
| 1183 | assert(lvalue); |
| 1184 | assert(rvalue); |
| 1185 | assert(data); |
| 1186 | |
| 1187 | dbus_error_init(&error); |
Lennart Poettering | 01f7847 | 2010-05-24 05:25:33 +0200 | [diff] [blame] | 1188 | |
| 1189 | if (endswith(rvalue, ".path")) { |
| 1190 | log_error("[%s:%u] Unit cannot be of type path: %s", filename, line, rvalue); |
| 1191 | return -EINVAL; |
| 1192 | } |
| 1193 | |
Lennart Poettering | 398ef8b | 2010-07-08 02:43:18 +0200 | [diff] [blame] | 1194 | if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &error, &t->unit)) < 0) { |
| 1195 | log_error("[%s:%u] Failed to load unit %s: %s", filename, line, rvalue, bus_error(&error, r)); |
| 1196 | dbus_error_free(&error); |
Lennart Poettering | 01f7847 | 2010-05-24 05:25:33 +0200 | [diff] [blame] | 1197 | return r; |
| 1198 | } |
| 1199 | |
| 1200 | return 0; |
| 1201 | } |
| 1202 | |
Lennart Poettering | ddb26e1 | 2010-06-18 06:06:24 +0200 | [diff] [blame] | 1203 | static int config_parse_env_file( |
| 1204 | const char *filename, |
| 1205 | unsigned line, |
| 1206 | const char *section, |
| 1207 | const char *lvalue, |
| 1208 | const char *rvalue, |
| 1209 | void *data, |
| 1210 | void *userdata) { |
| 1211 | |
| 1212 | FILE *f; |
| 1213 | int r; |
| 1214 | char ***env = data; |
| 1215 | |
| 1216 | assert(filename); |
| 1217 | assert(lvalue); |
| 1218 | assert(rvalue); |
| 1219 | assert(data); |
| 1220 | |
| 1221 | if (!(f = fopen(rvalue, "re"))) { |
| 1222 | log_error("[%s:%u] Failed to open environment file '%s': %m", filename, line, rvalue); |
| 1223 | return -errno; |
| 1224 | } |
| 1225 | |
| 1226 | while (!feof(f)) { |
| 1227 | char l[LINE_MAX], *p; |
| 1228 | char **t; |
| 1229 | |
| 1230 | if (!fgets(l, sizeof(l), f)) { |
| 1231 | if (feof(f)) |
| 1232 | break; |
| 1233 | |
| 1234 | r = -errno; |
| 1235 | log_error("[%s:%u] Failed to read environment file '%s': %m", filename, line, rvalue); |
| 1236 | goto finish; |
| 1237 | } |
| 1238 | |
| 1239 | p = strstrip(l); |
| 1240 | |
| 1241 | if (!*p) |
| 1242 | continue; |
| 1243 | |
| 1244 | if (strchr(COMMENTS, *p)) |
| 1245 | continue; |
| 1246 | |
| 1247 | t = strv_env_set(*env, p); |
| 1248 | strv_free(*env); |
| 1249 | *env = t; |
| 1250 | } |
| 1251 | |
| 1252 | r = 0; |
| 1253 | |
| 1254 | finish: |
| 1255 | if (f) |
| 1256 | fclose(f); |
| 1257 | |
| 1258 | return r; |
| 1259 | } |
| 1260 | |
Lennart Poettering | 4fd5948 | 2010-07-01 00:29:17 +0200 | [diff] [blame] | 1261 | static int config_parse_ip_tos( |
| 1262 | const char *filename, |
| 1263 | unsigned line, |
| 1264 | const char *section, |
| 1265 | const char *lvalue, |
| 1266 | const char *rvalue, |
| 1267 | void *data, |
| 1268 | void *userdata) { |
| 1269 | |
| 1270 | int *ip_tos = data, x; |
| 1271 | int r; |
| 1272 | |
| 1273 | assert(filename); |
| 1274 | assert(lvalue); |
| 1275 | assert(rvalue); |
| 1276 | assert(data); |
| 1277 | |
| 1278 | if ((x = ip_tos_from_string(rvalue)) < 0) |
| 1279 | if ((r = safe_atoi(rvalue, &x)) < 0) { |
| 1280 | log_error("[%s:%u] Failed to parse IP TOS value: %s", filename, line, rvalue); |
| 1281 | return r; |
| 1282 | } |
| 1283 | |
| 1284 | *ip_tos = x; |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
Lennart Poettering | 487393e | 2010-07-07 01:10:27 +0200 | [diff] [blame] | 1288 | static DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier"); |
Lennart Poettering | c952c6e | 2010-06-18 23:12:48 +0200 | [diff] [blame] | 1289 | |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 1290 | #define FOLLOW_MAX 8 |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1291 | |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 1292 | static int open_follow(char **filename, FILE **_f, Set *names, char **_final) { |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1293 | unsigned c = 0; |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1294 | int fd, r; |
| 1295 | FILE *f; |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1296 | char *id = NULL; |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1297 | |
| 1298 | assert(filename); |
| 1299 | assert(*filename); |
| 1300 | assert(_f); |
| 1301 | assert(names); |
| 1302 | |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1303 | /* This will update the filename pointer if the loaded file is |
| 1304 | * reached by a symlink. The old string will be freed. */ |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1305 | |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1306 | for (;;) { |
Lennart Poettering | 2c7108c | 2010-06-16 01:56:00 +0200 | [diff] [blame] | 1307 | char *target, *name; |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1308 | |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1309 | if (c++ >= FOLLOW_MAX) |
| 1310 | return -ELOOP; |
| 1311 | |
Lennart Poettering | b08d03f | 2010-01-29 02:07:41 +0100 | [diff] [blame] | 1312 | path_kill_slashes(*filename); |
| 1313 | |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1314 | /* Add the file name we are currently looking at to |
| 1315 | * the names of this unit */ |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1316 | name = file_name_from_path(*filename); |
| 1317 | if (!(id = set_get(names, name))) { |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1318 | |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1319 | if (!(id = strdup(name))) |
| 1320 | return -ENOMEM; |
| 1321 | |
| 1322 | if ((r = set_put(names, id)) < 0) { |
| 1323 | free(id); |
| 1324 | return r; |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1325 | } |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1326 | } |
| 1327 | |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1328 | /* Try to open the file name, but don't if its a symlink */ |
| 1329 | if ((fd = open(*filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW)) >= 0) |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1330 | break; |
| 1331 | |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1332 | if (errno != ELOOP) |
| 1333 | return -errno; |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1334 | |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1335 | /* Hmm, so this is a symlink. Let's read the name, and follow it manually */ |
Lennart Poettering | 2c7108c | 2010-06-16 01:56:00 +0200 | [diff] [blame] | 1336 | if ((r = readlink_and_make_absolute(*filename, &target)) < 0) |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1337 | return r; |
| 1338 | |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1339 | free(*filename); |
Lennart Poettering | 2c7108c | 2010-06-16 01:56:00 +0200 | [diff] [blame] | 1340 | *filename = target; |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | if (!(f = fdopen(fd, "r"))) { |
| 1344 | r = -errno; |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 1345 | close_nointr_nofail(fd); |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1346 | return r; |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | *_f = f; |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 1350 | *_final = id; |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1351 | return 0; |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1352 | } |
| 1353 | |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1354 | static int merge_by_names(Unit **u, Set *names, const char *id) { |
| 1355 | char *k; |
| 1356 | int r; |
| 1357 | |
| 1358 | assert(u); |
| 1359 | assert(*u); |
| 1360 | assert(names); |
| 1361 | |
| 1362 | /* Let's try to add in all symlink names we found */ |
| 1363 | while ((k = set_steal_first(names))) { |
| 1364 | |
| 1365 | /* First try to merge in the other name into our |
| 1366 | * unit */ |
| 1367 | if ((r = unit_merge_by_name(*u, k)) < 0) { |
| 1368 | Unit *other; |
| 1369 | |
| 1370 | /* Hmm, we couldn't merge the other unit into |
| 1371 | * ours? Then let's try it the other way |
| 1372 | * round */ |
| 1373 | |
| 1374 | other = manager_get_unit((*u)->meta.manager, k); |
| 1375 | free(k); |
| 1376 | |
| 1377 | if (other) |
| 1378 | if ((r = unit_merge(other, *u)) >= 0) { |
| 1379 | *u = other; |
| 1380 | return merge_by_names(u, names, NULL); |
| 1381 | } |
| 1382 | |
| 1383 | return r; |
| 1384 | } |
| 1385 | |
| 1386 | if (id == k) |
| 1387 | unit_choose_id(*u, id); |
| 1388 | |
| 1389 | free(k); |
| 1390 | } |
| 1391 | |
| 1392 | return 0; |
| 1393 | } |
| 1394 | |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1395 | static void dump_items(FILE *f, const ConfigItem *items) { |
| 1396 | const ConfigItem *i; |
| 1397 | const char *prev_section = NULL; |
| 1398 | bool not_first = false; |
| 1399 | |
| 1400 | struct { |
| 1401 | ConfigParserCallback callback; |
| 1402 | const char *rvalue; |
| 1403 | } table[] = { |
| 1404 | { config_parse_int, "INTEGER" }, |
| 1405 | { config_parse_unsigned, "UNSIGNED" }, |
| 1406 | { config_parse_size, "SIZE" }, |
| 1407 | { config_parse_bool, "BOOLEAN" }, |
| 1408 | { config_parse_string, "STRING" }, |
| 1409 | { config_parse_path, "PATH" }, |
| 1410 | { config_parse_strv, "STRING [...]" }, |
| 1411 | { config_parse_nice, "NICE" }, |
| 1412 | { config_parse_oom_adjust, "OOMADJUST" }, |
| 1413 | { config_parse_io_class, "IOCLASS" }, |
| 1414 | { config_parse_io_priority, "IOPRIORITY" }, |
| 1415 | { config_parse_cpu_sched_policy, "CPUSCHEDPOLICY" }, |
| 1416 | { config_parse_cpu_sched_prio, "CPUSCHEDPRIO" }, |
| 1417 | { config_parse_cpu_affinity, "CPUAFFINITY" }, |
| 1418 | { config_parse_mode, "MODE" }, |
Lennart Poettering | ddb26e1 | 2010-06-18 06:06:24 +0200 | [diff] [blame] | 1419 | { config_parse_env_file, "FILE" }, |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1420 | { config_parse_output, "OUTPUT" }, |
| 1421 | { config_parse_input, "INPUT" }, |
| 1422 | { config_parse_facility, "FACILITY" }, |
| 1423 | { config_parse_level, "LEVEL" }, |
| 1424 | { config_parse_capabilities, "CAPABILITIES" }, |
| 1425 | { config_parse_secure_bits, "SECUREBITS" }, |
| 1426 | { config_parse_bounding_set, "BOUNDINGSET" }, |
Lennart Poettering | 03fae01 | 2010-07-04 21:12:10 +0200 | [diff] [blame] | 1427 | { config_parse_timer_slack_nsec, "TIMERSLACK" }, |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1428 | { config_parse_limit, "LIMIT" }, |
| 1429 | { config_parse_cgroup, "CGROUP [...]" }, |
| 1430 | { config_parse_deps, "UNIT [...]" }, |
| 1431 | { config_parse_names, "UNIT [...]" }, |
| 1432 | { config_parse_exec, "PATH [ARGUMENT [...]]" }, |
| 1433 | { config_parse_service_type, "SERVICETYPE" }, |
| 1434 | { config_parse_service_restart, "SERVICERESTART" }, |
| 1435 | { config_parse_sysv_priority, "SYSVPRIORITY" }, |
| 1436 | { config_parse_kill_mode, "KILLMODE" }, |
Lennart Poettering | 2e22afe | 2010-07-10 04:49:37 +0200 | [diff] [blame] | 1437 | { config_parse_kill_signal, "SIGNAL" }, |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1438 | { config_parse_listen, "SOCKET [...]" }, |
| 1439 | { config_parse_socket_bind, "SOCKETBIND" }, |
Lennart Poettering | 93ef5e8 | 2010-04-23 20:27:47 +0200 | [diff] [blame] | 1440 | { config_parse_bindtodevice, "NETWORKINTERFACE" }, |
| 1441 | { config_parse_usec, "SECONDS" }, |
| 1442 | { config_parse_path_strv, "PATH [...]" }, |
Lennart Poettering | 932921b | 2010-04-24 03:11:01 +0200 | [diff] [blame] | 1443 | { config_parse_mount_flags, "MOUNTFLAG [...]" }, |
Lennart Poettering | f2d3769 | 2010-06-18 23:25:19 +0200 | [diff] [blame] | 1444 | { config_parse_string_printf, "STRING" }, |
Lennart Poettering | 871d7de | 2010-05-24 01:45:54 +0200 | [diff] [blame] | 1445 | { config_parse_timer, "TIMER" }, |
| 1446 | { config_parse_timer_unit, "NAME" }, |
Lennart Poettering | c952c6e | 2010-06-18 23:12:48 +0200 | [diff] [blame] | 1447 | { config_parse_path_spec, "PATH" }, |
| 1448 | { config_parse_path_unit, "UNIT" }, |
Lennart Poettering | 8b03dae | 2010-07-01 16:34:26 +0200 | [diff] [blame] | 1449 | { config_parse_notify_access, "ACCESS" }, |
| 1450 | { config_parse_ip_tos, "TOS" }, |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1451 | }; |
| 1452 | |
| 1453 | assert(f); |
| 1454 | assert(items); |
| 1455 | |
| 1456 | for (i = items; i->lvalue; i++) { |
| 1457 | unsigned j; |
| 1458 | const char *rvalue = "OTHER"; |
| 1459 | |
| 1460 | if (!streq_ptr(i->section, prev_section)) { |
| 1461 | if (!not_first) |
| 1462 | not_first = true; |
| 1463 | else |
| 1464 | fputc('\n', f); |
| 1465 | |
| 1466 | fprintf(f, "[%s]\n", i->section); |
| 1467 | prev_section = i->section; |
| 1468 | } |
| 1469 | |
| 1470 | for (j = 0; j < ELEMENTSOF(table); j++) |
| 1471 | if (i->parse == table[j].callback) { |
| 1472 | rvalue = table[j].rvalue; |
| 1473 | break; |
| 1474 | } |
| 1475 | |
| 1476 | fprintf(f, "%s=%s\n", i->lvalue, rvalue); |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | static int load_from_path(Unit *u, const char *path) { |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1481 | |
| 1482 | static const char* const section_table[_UNIT_TYPE_MAX] = { |
| 1483 | [UNIT_SERVICE] = "Service", |
| 1484 | [UNIT_TIMER] = "Timer", |
| 1485 | [UNIT_SOCKET] = "Socket", |
| 1486 | [UNIT_TARGET] = "Target", |
| 1487 | [UNIT_DEVICE] = "Device", |
| 1488 | [UNIT_MOUNT] = "Mount", |
| 1489 | [UNIT_AUTOMOUNT] = "Automount", |
Maarten Lankhorst | 07b0b13 | 2010-05-09 18:44:11 +0200 | [diff] [blame] | 1490 | [UNIT_SNAPSHOT] = "Snapshot", |
Lennart Poettering | 01f7847 | 2010-05-24 05:25:33 +0200 | [diff] [blame] | 1491 | [UNIT_SWAP] = "Swap", |
| 1492 | [UNIT_PATH] = "Path" |
Lennart Poettering | 42f4e3c | 2010-01-19 02:56:37 +0100 | [diff] [blame] | 1493 | }; |
| 1494 | |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 1495 | #define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \ |
Lennart Poettering | 9eba9da | 2010-01-29 20:46:22 +0100 | [diff] [blame] | 1496 | { "WorkingDirectory", config_parse_path, &(context).working_directory, section }, \ |
| 1497 | { "RootDirectory", config_parse_path, &(context).root_directory, section }, \ |
Lennart Poettering | f2d3769 | 2010-06-18 23:25:19 +0200 | [diff] [blame] | 1498 | { "User", config_parse_string_printf, &(context).user, section }, \ |
| 1499 | { "Group", config_parse_string_printf, &(context).group, section }, \ |
Lennart Poettering | 1c01f82 | 2010-01-27 02:16:11 +0100 | [diff] [blame] | 1500 | { "SupplementaryGroups", config_parse_strv, &(context).supplementary_groups, section }, \ |
Lennart Poettering | fb33a39 | 2010-01-28 02:53:56 +0100 | [diff] [blame] | 1501 | { "Nice", config_parse_nice, &(context), section }, \ |
| 1502 | { "OOMAdjust", config_parse_oom_adjust, &(context), section }, \ |
Lennart Poettering | 9eba9da | 2010-01-29 20:46:22 +0100 | [diff] [blame] | 1503 | { "IOSchedulingClass", config_parse_io_class, &(context), section }, \ |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 1504 | { "IOSchedulingPriority", config_parse_io_priority, &(context), section }, \ |
| 1505 | { "CPUSchedulingPolicy", config_parse_cpu_sched_policy,&(context), section }, \ |
| 1506 | { "CPUSchedulingPriority", config_parse_cpu_sched_prio, &(context), section }, \ |
Lennart Poettering | 38b4875 | 2010-02-02 12:50:04 +0100 | [diff] [blame] | 1507 | { "CPUSchedulingResetOnFork", config_parse_bool, &(context).cpu_sched_reset_on_fork, section }, \ |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 1508 | { "CPUAffinity", config_parse_cpu_affinity, &(context), section }, \ |
Lennart Poettering | b5a0699 | 2010-02-12 02:02:14 +0100 | [diff] [blame] | 1509 | { "UMask", config_parse_mode, &(context).umask, section }, \ |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 1510 | { "Environment", config_parse_strv, &(context).environment, section }, \ |
Lennart Poettering | ddb26e1 | 2010-06-18 06:06:24 +0200 | [diff] [blame] | 1511 | { "EnvironmentFile", config_parse_env_file, &(context).environment, section }, \ |
Lennart Poettering | 80876c2 | 2010-04-13 02:06:27 +0200 | [diff] [blame] | 1512 | { "StandardInput", config_parse_input, &(context).std_input, section }, \ |
| 1513 | { "StandardOutput", config_parse_output, &(context).std_output, section }, \ |
Lennart Poettering | a4ddf82 | 2010-06-03 03:37:12 +0200 | [diff] [blame] | 1514 | { "StandardError", config_parse_output, &(context).std_error, section }, \ |
Lennart Poettering | 80876c2 | 2010-04-13 02:06:27 +0200 | [diff] [blame] | 1515 | { "TTYPath", config_parse_path, &(context).tty_path, section }, \ |
Lennart Poettering | f2d3769 | 2010-06-18 23:25:19 +0200 | [diff] [blame] | 1516 | { "SyslogIdentifier", config_parse_string_printf, &(context).syslog_identifier, section }, \ |
Lennart Poettering | 071830f | 2010-01-28 02:06:20 +0100 | [diff] [blame] | 1517 | { "SyslogFacility", config_parse_facility, &(context).syslog_priority, section }, \ |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 1518 | { "SyslogLevel", config_parse_level, &(context).syslog_priority, section }, \ |
Lennart Poettering | 7492290 | 2010-07-05 01:08:13 +0200 | [diff] [blame] | 1519 | { "SyslogLevelPrefix", config_parse_bool, &(context).syslog_level_prefix, section }, \ |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 1520 | { "Capabilities", config_parse_capabilities, &(context), section }, \ |
| 1521 | { "SecureBits", config_parse_secure_bits, &(context), section }, \ |
| 1522 | { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context), section }, \ |
Lennart Poettering | 03fae01 | 2010-07-04 21:12:10 +0200 | [diff] [blame] | 1523 | { "TimerSlackNSec", config_parse_timer_slack_nsec,&(context), section }, \ |
Lennart Poettering | 94f0434 | 2010-01-30 01:55:42 +0100 | [diff] [blame] | 1524 | { "LimitCPU", config_parse_limit, &(context).rlimit[RLIMIT_CPU], section }, \ |
| 1525 | { "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \ |
| 1526 | { "LimitDATA", config_parse_limit, &(context).rlimit[RLIMIT_DATA], section }, \ |
| 1527 | { "LimitSTACK", config_parse_limit, &(context).rlimit[RLIMIT_STACK], section }, \ |
| 1528 | { "LimitCORE", config_parse_limit, &(context).rlimit[RLIMIT_CORE], section }, \ |
| 1529 | { "LimitRSS", config_parse_limit, &(context).rlimit[RLIMIT_RSS], section }, \ |
| 1530 | { "LimitNOFILE", config_parse_limit, &(context).rlimit[RLIMIT_NOFILE], section }, \ |
| 1531 | { "LimitAS", config_parse_limit, &(context).rlimit[RLIMIT_AS], section }, \ |
| 1532 | { "LimitNPROC", config_parse_limit, &(context).rlimit[RLIMIT_NPROC], section }, \ |
| 1533 | { "LimitMEMLOCK", config_parse_limit, &(context).rlimit[RLIMIT_MEMLOCK], section }, \ |
| 1534 | { "LimitLOCKS", config_parse_limit, &(context).rlimit[RLIMIT_LOCKS], section }, \ |
| 1535 | { "LimitSIGPENDING", config_parse_limit, &(context).rlimit[RLIMIT_SIGPENDING], section }, \ |
| 1536 | { "LimitMSGQUEUE", config_parse_limit, &(context).rlimit[RLIMIT_MSGQUEUE], section }, \ |
| 1537 | { "LimitNICE", config_parse_limit, &(context).rlimit[RLIMIT_NICE], section }, \ |
| 1538 | { "LimitRTPRIO", config_parse_limit, &(context).rlimit[RLIMIT_RTPRIO], section }, \ |
Lennart Poettering | 451a074 | 2010-02-12 02:00:18 +0100 | [diff] [blame] | 1539 | { "LimitRTTIME", config_parse_limit, &(context).rlimit[RLIMIT_RTTIME], section }, \ |
Lennart Poettering | 15ae422 | 2010-04-21 22:15:06 +0200 | [diff] [blame] | 1540 | { "ControlGroup", config_parse_cgroup, u, section }, \ |
| 1541 | { "ReadWriteDirectories", config_parse_path_strv, &(context).read_write_dirs, section }, \ |
| 1542 | { "ReadOnlyDirectories", config_parse_path_strv, &(context).read_only_dirs, section }, \ |
| 1543 | { "InaccessibleDirectories",config_parse_path_strv, &(context).inaccessible_dirs, section }, \ |
| 1544 | { "PrivateTmp", config_parse_bool, &(context).private_tmp, section }, \ |
Lennart Poettering | df1f0af | 2010-06-16 16:25:42 +0200 | [diff] [blame] | 1545 | { "MountFlags", config_parse_mount_flags, &(context), section }, \ |
Lennart Poettering | f2d3769 | 2010-06-18 23:25:19 +0200 | [diff] [blame] | 1546 | { "TCPWrapName", config_parse_string_printf, &(context).tcpwrap_name, section }, \ |
Lennart Poettering | 2e22afe | 2010-07-10 04:49:37 +0200 | [diff] [blame] | 1547 | { "PAMName", config_parse_string_printf, &(context).pam_name, section }, \ |
| 1548 | { "KillMode", config_parse_kill_mode, &(context).kill_mode, section }, \ |
| 1549 | { "KillSignal", config_parse_kill_signal, &(context).kill_signal, section } |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 1550 | |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 1551 | const ConfigItem items[] = { |
Lennart Poettering | 0947726 | 2010-04-15 23:20:17 +0200 | [diff] [blame] | 1552 | { "Names", config_parse_names, u, "Unit" }, |
Lennart Poettering | f2d3769 | 2010-06-18 23:25:19 +0200 | [diff] [blame] | 1553 | { "Description", config_parse_string_printf, &u->meta.description, "Unit" }, |
Lennart Poettering | 0947726 | 2010-04-15 23:20:17 +0200 | [diff] [blame] | 1554 | { "Requires", config_parse_deps, UINT_TO_PTR(UNIT_REQUIRES), "Unit" }, |
| 1555 | { "RequiresOverridable", config_parse_deps, UINT_TO_PTR(UNIT_REQUIRES_OVERRIDABLE), "Unit" }, |
| 1556 | { "Requisite", config_parse_deps, UINT_TO_PTR(UNIT_REQUISITE), "Unit" }, |
| 1557 | { "RequisiteOverridable", config_parse_deps, UINT_TO_PTR(UNIT_REQUISITE_OVERRIDABLE), "Unit" }, |
| 1558 | { "Wants", config_parse_deps, UINT_TO_PTR(UNIT_WANTS), "Unit" }, |
| 1559 | { "Conflicts", config_parse_deps, UINT_TO_PTR(UNIT_CONFLICTS), "Unit" }, |
| 1560 | { "Before", config_parse_deps, UINT_TO_PTR(UNIT_BEFORE), "Unit" }, |
| 1561 | { "After", config_parse_deps, UINT_TO_PTR(UNIT_AFTER), "Unit" }, |
Lennart Poettering | 45fb069 | 2010-07-17 00:57:51 +0200 | [diff] [blame^] | 1562 | { "OnFailure", config_parse_deps, UINT_TO_PTR(UNIT_ON_FAILURE), "Unit" }, |
Lennart Poettering | 0947726 | 2010-04-15 23:20:17 +0200 | [diff] [blame] | 1563 | { "RecursiveStop", config_parse_bool, &u->meta.recursive_stop, "Unit" }, |
| 1564 | { "StopWhenUnneeded", config_parse_bool, &u->meta.stop_when_unneeded, "Unit" }, |
Lennart Poettering | bc0f877 | 2010-05-21 23:41:54 +0200 | [diff] [blame] | 1565 | { "OnlyByDependency", config_parse_bool, &u->meta.only_by_dependency, "Unit" }, |
Lennart Poettering | a40eb73 | 2010-07-03 19:48:33 +0200 | [diff] [blame] | 1566 | { "DefaultDependencies", config_parse_bool, &u->meta.default_dependencies, "Unit" }, |
Lennart Poettering | 3b6fdb5 | 2010-07-12 02:56:17 +0200 | [diff] [blame] | 1567 | { "IgnoreDependencyFailure",config_parse_bool, &u->meta.ignore_dependency_failure, "Unit" }, |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 1568 | |
Lennart Poettering | 1c01f82 | 2010-01-27 02:16:11 +0100 | [diff] [blame] | 1569 | { "PIDFile", config_parse_path, &u->service.pid_file, "Service" }, |
| 1570 | { "ExecStartPre", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START_PRE, "Service" }, |
| 1571 | { "ExecStart", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START, "Service" }, |
| 1572 | { "ExecStartPost", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START_POST, "Service" }, |
| 1573 | { "ExecReload", config_parse_exec, u->service.exec_command+SERVICE_EXEC_RELOAD, "Service" }, |
| 1574 | { "ExecStop", config_parse_exec, u->service.exec_command+SERVICE_EXEC_STOP, "Service" }, |
| 1575 | { "ExecStopPost", config_parse_exec, u->service.exec_command+SERVICE_EXEC_STOP_POST, "Service" }, |
| 1576 | { "RestartSec", config_parse_usec, &u->service.restart_usec, "Service" }, |
| 1577 | { "TimeoutSec", config_parse_usec, &u->service.timeout_usec, "Service" }, |
Lennart Poettering | 0d87eb4 | 2010-04-13 02:22:41 +0200 | [diff] [blame] | 1578 | { "Type", config_parse_service_type, &u->service.type, "Service" }, |
| 1579 | { "Restart", config_parse_service_restart, &u->service.restart, "Service" }, |
Lennart Poettering | 81a2b7c | 2010-02-14 22:43:08 +0100 | [diff] [blame] | 1580 | { "PermissionsStartOnly", config_parse_bool, &u->service.permissions_start_only, "Service" }, |
| 1581 | { "RootDirectoryStartOnly", config_parse_bool, &u->service.root_directory_start_only, "Service" }, |
Lennart Poettering | 8e27452 | 2010-03-31 16:29:55 +0200 | [diff] [blame] | 1582 | { "ValidNoProcess", config_parse_bool, &u->service.valid_no_process, "Service" }, |
Lennart Poettering | a9a1e00 | 2010-04-06 02:40:10 +0200 | [diff] [blame] | 1583 | { "SysVStartPriority", config_parse_sysv_priority, &u->service.sysv_start_priority, "Service" }, |
Lennart Poettering | b778d55 | 2010-04-10 17:48:41 +0200 | [diff] [blame] | 1584 | { "NonBlocking", config_parse_bool, &u->service.exec_context.non_blocking, "Service" }, |
Lennart Poettering | f2d3769 | 2010-06-18 23:25:19 +0200 | [diff] [blame] | 1585 | { "BusName", config_parse_string_printf, &u->service.bus_name, "Service" }, |
Lennart Poettering | c952c6e | 2010-06-18 23:12:48 +0200 | [diff] [blame] | 1586 | { "NotifyAccess", config_parse_notify_access, &u->service.notify_access, "Service" }, |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1587 | EXEC_CONTEXT_CONFIG_ITEMS(u->service.exec_context, "Service"), |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 1588 | |
Lennart Poettering | 1c01f82 | 2010-01-27 02:16:11 +0100 | [diff] [blame] | 1589 | { "ListenStream", config_parse_listen, &u->socket, "Socket" }, |
| 1590 | { "ListenDatagram", config_parse_listen, &u->socket, "Socket" }, |
| 1591 | { "ListenSequentialPacket", config_parse_listen, &u->socket, "Socket" }, |
| 1592 | { "ListenFIFO", config_parse_listen, &u->socket, "Socket" }, |
| 1593 | { "BindIPv6Only", config_parse_socket_bind, &u->socket, "Socket" }, |
| 1594 | { "Backlog", config_parse_unsigned, &u->socket.backlog, "Socket" }, |
Lennart Poettering | acbb022 | 2010-01-27 04:31:52 +0100 | [diff] [blame] | 1595 | { "BindToDevice", config_parse_bindtodevice, &u->socket, "Socket" }, |
Lennart Poettering | 1c01f82 | 2010-01-27 02:16:11 +0100 | [diff] [blame] | 1596 | { "ExecStartPre", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_START_PRE, "Socket" }, |
| 1597 | { "ExecStartPost", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_START_POST, "Socket" }, |
| 1598 | { "ExecStopPre", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_STOP_PRE, "Socket" }, |
| 1599 | { "ExecStopPost", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_STOP_POST, "Socket" }, |
Lennart Poettering | 108736d | 2010-04-10 17:50:54 +0200 | [diff] [blame] | 1600 | { "TimeoutSec", config_parse_usec, &u->socket.timeout_usec, "Socket" }, |
Lennart Poettering | b5a0699 | 2010-02-12 02:02:14 +0100 | [diff] [blame] | 1601 | { "DirectoryMode", config_parse_mode, &u->socket.directory_mode, "Socket" }, |
| 1602 | { "SocketMode", config_parse_mode, &u->socket.socket_mode, "Socket" }, |
Lennart Poettering | 4f2d528 | 2010-04-15 06:19:54 +0200 | [diff] [blame] | 1603 | { "Accept", config_parse_bool, &u->socket.accept, "Socket" }, |
Lennart Poettering | 6cf6bbc | 2010-06-19 04:25:28 +0200 | [diff] [blame] | 1604 | { "MaxConnections", config_parse_unsigned, &u->socket.max_connections, "Socket" }, |
Lennart Poettering | 4fd5948 | 2010-07-01 00:29:17 +0200 | [diff] [blame] | 1605 | { "KeepAlive", config_parse_bool, &u->socket.keep_alive, "Socket" }, |
| 1606 | { "Priority", config_parse_int, &u->socket.priority, "Socket" }, |
| 1607 | { "ReceiveBuffer", config_parse_size, &u->socket.receive_buffer, "Socket" }, |
| 1608 | { "SendBuffer", config_parse_size, &u->socket.send_buffer, "Socket" }, |
| 1609 | { "IPTOS", config_parse_ip_tos, &u->socket.ip_tos, "Socket" }, |
| 1610 | { "IPTTL", config_parse_int, &u->socket.ip_ttl, "Socket" }, |
| 1611 | { "Mark", config_parse_int, &u->socket.mark, "Socket" }, |
| 1612 | { "PipeSize", config_parse_size, &u->socket.pipe_size, "Socket" }, |
| 1613 | { "FreeBind", config_parse_bool, &u->socket.free_bind, "Socket" }, |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1614 | EXEC_CONTEXT_CONFIG_ITEMS(u->socket.exec_context, "Socket"), |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 1615 | |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1616 | { "What", config_parse_string, &u->mount.parameters_fragment.what, "Mount" }, |
| 1617 | { "Where", config_parse_path, &u->mount.where, "Mount" }, |
| 1618 | { "Options", config_parse_string, &u->mount.parameters_fragment.options, "Mount" }, |
| 1619 | { "Type", config_parse_string, &u->mount.parameters_fragment.fstype, "Mount" }, |
| 1620 | { "TimeoutSec", config_parse_usec, &u->mount.timeout_usec, "Mount" }, |
Lennart Poettering | 3e5235b | 2010-07-02 00:28:44 +0200 | [diff] [blame] | 1621 | { "DirectoryMode", config_parse_mode, &u->mount.directory_mode, "Mount" }, |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1622 | EXEC_CONTEXT_CONFIG_ITEMS(u->mount.exec_context, "Mount"), |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 1623 | |
Lennart Poettering | 8d56758 | 2010-04-16 23:24:39 +0200 | [diff] [blame] | 1624 | { "Where", config_parse_path, &u->automount.where, "Automount" }, |
Lennart Poettering | 1cf18f2 | 2010-07-02 01:17:21 +0200 | [diff] [blame] | 1625 | { "DirectoryMode", config_parse_mode, &u->automount.directory_mode, "Automount" }, |
Lennart Poettering | 8d56758 | 2010-04-16 23:24:39 +0200 | [diff] [blame] | 1626 | |
Lennart Poettering | 01f7847 | 2010-05-24 05:25:33 +0200 | [diff] [blame] | 1627 | { "What", config_parse_path, &u->swap.parameters_fragment.what, "Swap" }, |
| 1628 | { "Priority", config_parse_int, &u->swap.parameters_fragment.priority, "Swap" }, |
Maarten Lankhorst | 07b0b13 | 2010-05-09 18:44:11 +0200 | [diff] [blame] | 1629 | |
Lennart Poettering | 03fae01 | 2010-07-04 21:12:10 +0200 | [diff] [blame] | 1630 | { "OnActiveSec", config_parse_timer, &u->timer, "Timer" }, |
| 1631 | { "OnBootSec", config_parse_timer, &u->timer, "Timer" }, |
| 1632 | { "OnStartupSec", config_parse_timer, &u->timer, "Timer" }, |
| 1633 | { "OnUnitActiveSec", config_parse_timer, &u->timer, "Timer" }, |
| 1634 | { "OnUnitInactiveSec", config_parse_timer, &u->timer, "Timer" }, |
Lennart Poettering | 01f7847 | 2010-05-24 05:25:33 +0200 | [diff] [blame] | 1635 | { "Unit", config_parse_timer_unit, &u->timer, "Timer" }, |
| 1636 | |
| 1637 | { "PathExists", config_parse_path_spec, &u->path, "Path" }, |
| 1638 | { "PathChanged", config_parse_path_spec, &u->path, "Path" }, |
| 1639 | { "DirectoryNotEmpty", config_parse_path_spec, &u->path, "Path" }, |
| 1640 | { "Unit", config_parse_path_unit, &u->path, "Path" }, |
Lennart Poettering | 871d7de | 2010-05-24 01:45:54 +0200 | [diff] [blame] | 1641 | |
Lennart Poettering | 10e87ee | 2010-06-16 01:58:50 +0200 | [diff] [blame] | 1642 | /* The [Install] section is ignored here. */ |
| 1643 | { "Alias", NULL, NULL, "Install" }, |
| 1644 | { "WantedBy", NULL, NULL, "Install" }, |
| 1645 | { "Also", NULL, NULL, "Install" }, |
| 1646 | |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 1647 | { NULL, NULL, NULL, NULL } |
| 1648 | }; |
| 1649 | |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 1650 | #undef EXEC_CONTEXT_CONFIG_ITEMS |
Lennart Poettering | 42f4e3c | 2010-01-19 02:56:37 +0100 | [diff] [blame] | 1651 | |
Lennart Poettering | 10e87ee | 2010-06-16 01:58:50 +0200 | [diff] [blame] | 1652 | const char *sections[4]; |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1653 | int r; |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1654 | Set *symlink_names; |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1655 | FILE *f = NULL; |
| 1656 | char *filename = NULL, *id = NULL; |
| 1657 | Unit *merged; |
Lennart Poettering | 45fb069 | 2010-07-17 00:57:51 +0200 | [diff] [blame^] | 1658 | struct stat st; |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1659 | |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1660 | if (!u) { |
| 1661 | /* Dirty dirty hack. */ |
| 1662 | dump_items((FILE*) path, items); |
| 1663 | return 0; |
| 1664 | } |
| 1665 | |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1666 | assert(u); |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1667 | assert(path); |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 1668 | |
Lennart Poettering | 0947726 | 2010-04-15 23:20:17 +0200 | [diff] [blame] | 1669 | sections[0] = "Unit"; |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1670 | sections[1] = section_table[u->meta.type]; |
Lennart Poettering | 10e87ee | 2010-06-16 01:58:50 +0200 | [diff] [blame] | 1671 | sections[2] = "Install"; |
| 1672 | sections[3] = NULL; |
Lennart Poettering | 42f4e3c | 2010-01-19 02:56:37 +0100 | [diff] [blame] | 1673 | |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1674 | if (!(symlink_names = set_new(string_hash_func, string_compare_func))) |
| 1675 | return -ENOMEM; |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 1676 | |
Lennart Poettering | 036643a | 2010-02-13 01:07:02 +0100 | [diff] [blame] | 1677 | if (path_is_absolute(path)) { |
| 1678 | |
| 1679 | if (!(filename = strdup(path))) { |
| 1680 | r = -ENOMEM; |
| 1681 | goto finish; |
| 1682 | } |
| 1683 | |
| 1684 | if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) { |
| 1685 | free(filename); |
| 1686 | filename = NULL; |
| 1687 | |
| 1688 | if (r != -ENOENT) |
| 1689 | goto finish; |
| 1690 | } |
| 1691 | |
| 1692 | } else { |
| 1693 | char **p; |
| 1694 | |
Lennart Poettering | 84e3543 | 2010-06-15 14:45:15 +0200 | [diff] [blame] | 1695 | STRV_FOREACH(p, u->meta.manager->lookup_paths.unit_path) { |
Lennart Poettering | 036643a | 2010-02-13 01:07:02 +0100 | [diff] [blame] | 1696 | |
| 1697 | /* Instead of opening the path right away, we manually |
| 1698 | * follow all symlinks and add their name to our unit |
| 1699 | * name set while doing so */ |
| 1700 | if (!(filename = path_make_absolute(path, *p))) { |
| 1701 | r = -ENOMEM; |
| 1702 | goto finish; |
| 1703 | } |
| 1704 | |
Lennart Poettering | fe51822 | 2010-07-11 00:52:00 +0200 | [diff] [blame] | 1705 | if (u->meta.manager->unit_path_cache && |
| 1706 | !set_get(u->meta.manager->unit_path_cache, filename)) |
| 1707 | r = -ENOENT; |
| 1708 | else |
| 1709 | r = open_follow(&filename, &f, symlink_names, &id); |
| 1710 | |
| 1711 | if (r < 0) { |
Lennart Poettering | 036643a | 2010-02-13 01:07:02 +0100 | [diff] [blame] | 1712 | char *sn; |
| 1713 | |
| 1714 | free(filename); |
| 1715 | filename = NULL; |
| 1716 | |
| 1717 | if (r != -ENOENT) |
| 1718 | goto finish; |
| 1719 | |
| 1720 | /* Empty the symlink names for the next run */ |
| 1721 | while ((sn = set_steal_first(symlink_names))) |
| 1722 | free(sn); |
| 1723 | |
| 1724 | continue; |
| 1725 | } |
| 1726 | |
| 1727 | break; |
| 1728 | } |
Lennart Poettering | 034c6ed | 2010-01-26 04:18:44 +0100 | [diff] [blame] | 1729 | } |
| 1730 | |
Lennart Poettering | 036643a | 2010-02-13 01:07:02 +0100 | [diff] [blame] | 1731 | if (!filename) { |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1732 | r = 0; |
| 1733 | goto finish; |
| 1734 | } |
| 1735 | |
| 1736 | merged = u; |
| 1737 | if ((r = merge_by_names(&merged, symlink_names, id)) < 0) |
| 1738 | goto finish; |
| 1739 | |
| 1740 | if (merged != u) { |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1741 | u->meta.load_state = UNIT_MERGED; |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1742 | r = 0; |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1743 | goto finish; |
| 1744 | } |
| 1745 | |
Lennart Poettering | 45fb069 | 2010-07-17 00:57:51 +0200 | [diff] [blame^] | 1746 | zero(st); |
| 1747 | if (fstat(fileno(f), &st) < 0) { |
| 1748 | r = -errno; |
| 1749 | goto finish; |
| 1750 | } |
| 1751 | |
| 1752 | if (!S_ISREG(st.st_mode)) { |
| 1753 | r = -ENOENT; |
| 1754 | goto finish; |
| 1755 | } |
| 1756 | |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1757 | /* Now, parse the file contents */ |
Lennart Poettering | 10e87ee | 2010-06-16 01:58:50 +0200 | [diff] [blame] | 1758 | if ((r = config_parse(filename, f, sections, items, false, u)) < 0) |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1759 | goto finish; |
| 1760 | |
Lennart Poettering | 6be1e7d | 2010-02-14 01:01:10 +0100 | [diff] [blame] | 1761 | free(u->meta.fragment_path); |
| 1762 | u->meta.fragment_path = filename; |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1763 | filename = NULL; |
| 1764 | |
Lennart Poettering | 45fb069 | 2010-07-17 00:57:51 +0200 | [diff] [blame^] | 1765 | u->meta.fragment_mtime = timespec_load(&st.st_mtim); |
| 1766 | |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1767 | u->meta.load_state = UNIT_LOADED; |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1768 | r = 0; |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1769 | |
| 1770 | finish: |
Lennart Poettering | 53ec43c | 2010-06-15 02:45:26 +0200 | [diff] [blame] | 1771 | set_free_free(symlink_names); |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1772 | free(filename); |
| 1773 | |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1774 | if (f) |
| 1775 | fclose(f); |
| 1776 | |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1777 | return r; |
| 1778 | } |
| 1779 | |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1780 | int unit_load_fragment(Unit *u) { |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1781 | int r; |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1782 | |
| 1783 | assert(u); |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1784 | |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1785 | if (u->meta.fragment_path) { |
| 1786 | |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1787 | if ((r = load_from_path(u, u->meta.fragment_path)) < 0) |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1788 | return r; |
| 1789 | |
| 1790 | } else { |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1791 | Iterator i; |
Lennart Poettering | 890f434 | 2010-02-14 01:08:20 +0100 | [diff] [blame] | 1792 | const char *t; |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1793 | |
Lennart Poettering | 890f434 | 2010-02-14 01:08:20 +0100 | [diff] [blame] | 1794 | /* Try to find the unit under its id */ |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 1795 | if ((r = load_from_path(u, u->meta.id)) < 0) |
| 1796 | return r; |
Lennart Poettering | 890f434 | 2010-02-14 01:08:20 +0100 | [diff] [blame] | 1797 | |
| 1798 | /* Try to find an alias we can load this with */ |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1799 | if (u->meta.load_state == UNIT_STUB) |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1800 | SET_FOREACH(t, u->meta.names, i) { |
| 1801 | |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 1802 | if (t == u->meta.id) |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1803 | continue; |
| 1804 | |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1805 | if ((r = load_from_path(u, t)) < 0) |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1806 | return r; |
| 1807 | |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1808 | if (u->meta.load_state != UNIT_STUB) |
Lennart Poettering | 890f434 | 2010-02-14 01:08:20 +0100 | [diff] [blame] | 1809 | break; |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1810 | } |
Lennart Poettering | 9e2f7c1 | 2010-04-15 03:11:11 +0200 | [diff] [blame] | 1811 | |
| 1812 | /* Now, follow the same logic, but look for a template */ |
| 1813 | if (u->meta.load_state == UNIT_STUB && u->meta.instance) { |
| 1814 | char *k; |
| 1815 | |
| 1816 | if (!(k = unit_name_template(u->meta.id))) |
| 1817 | return -ENOMEM; |
| 1818 | |
| 1819 | r = load_from_path(u, k); |
| 1820 | free(k); |
| 1821 | |
| 1822 | if (r < 0) |
| 1823 | return r; |
| 1824 | |
| 1825 | if (u->meta.load_state == UNIT_STUB) |
| 1826 | SET_FOREACH(t, u->meta.names, i) { |
| 1827 | |
| 1828 | if (t == u->meta.id) |
| 1829 | continue; |
| 1830 | |
| 1831 | if (!(k = unit_name_template(t))) |
| 1832 | return -ENOMEM; |
| 1833 | |
| 1834 | r = load_from_path(u, k); |
| 1835 | free(k); |
| 1836 | |
| 1837 | if (r < 0) |
| 1838 | return r; |
| 1839 | |
| 1840 | if (u->meta.load_state != UNIT_STUB) |
| 1841 | break; |
| 1842 | } |
| 1843 | } |
Lennart Poettering | 0301abf | 2010-01-27 00:15:56 +0100 | [diff] [blame] | 1844 | } |
Lennart Poettering | 87f0e41 | 2010-01-26 21:39:06 +0100 | [diff] [blame] | 1845 | |
Lennart Poettering | 23a177e | 2010-04-06 02:43:58 +0200 | [diff] [blame] | 1846 | return 0; |
Lennart Poettering | 3efd419 | 2009-11-19 23:13:20 +0100 | [diff] [blame] | 1847 | } |
Lennart Poettering | e537352 | 2010-04-10 17:53:17 +0200 | [diff] [blame] | 1848 | |
| 1849 | void unit_dump_config_items(FILE *f) { |
| 1850 | /* OK, this wins a prize for extreme ugliness. */ |
| 1851 | |
| 1852 | load_from_path(NULL, (const void*) f); |
| 1853 | } |