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