blob: 5eca82ad26c423c3ca7320eb20eecb9e98c83de6 [file] [log] [blame]
Lennart Poettering5008d582010-09-28 02:34:02 +02001/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02006 Copyright 2010 Lennart Poettering, Kay Sievers
Lennart Poettering5008d582010-09-28 02:34:02 +02007
8 systemd is free software; you can redistribute it and/or modify it
Lennart Poettering5430f7f2012-04-12 00:20:58 +02009 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
Lennart Poettering5008d582010-09-28 02:34:02 +020011 (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
Lennart Poettering5430f7f2012-04-12 00:20:58 +020016 Lesser General Public License for more details.
Lennart Poettering5008d582010-09-28 02:34:02 +020017
Lennart Poettering5430f7f2012-04-12 00:20:58 +020018 You should have received a copy of the GNU Lesser General Public License
Lennart Poettering5008d582010-09-28 02:34:02 +020019 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <unistd.h>
23#include <fcntl.h>
24#include <errno.h>
25#include <string.h>
26#include <sys/stat.h>
27#include <limits.h>
28#include <dirent.h>
29#include <grp.h>
30#include <pwd.h>
Lennart Poettering3b63d2d2010-10-18 22:38:41 +020031#include <stdio.h>
32#include <stdlib.h>
33#include <stddef.h>
34#include <getopt.h>
35#include <stdbool.h>
36#include <time.h>
37#include <sys/types.h>
38#include <sys/param.h>
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +010039#include <glob.h>
40#include <fnmatch.h>
Lennart Poetteringcb7ed9d2012-09-05 23:39:55 -070041#include <sys/capability.h>
Lennart Poettering5008d582010-09-28 02:34:02 +020042
43#include "log.h"
44#include "util.h"
Dave Reisner54693d92012-09-15 12:58:49 -040045#include "macro.h"
Zbigniew Jędrzejewski-Szmekd39efe72013-03-13 20:20:54 -040046#include "missing.h"
Kay Sievers49e942b2012-04-10 21:54:31 +020047#include "mkdir.h"
Kay Sievers9eb977d2012-05-07 21:36:12 +020048#include "path-util.h"
Lennart Poettering5008d582010-09-28 02:34:02 +020049#include "strv.h"
50#include "label.h"
Lennart Poettering3b63d2d2010-10-18 22:38:41 +020051#include "set.h"
Kay Sievers2c210442012-05-07 18:55:45 +020052#include "conf-files.h"
Lennart Poetteringcb7ed9d2012-09-05 23:39:55 -070053#include "capability.h"
Lennart Poettering5008d582010-09-28 02:34:02 +020054
Andreas Jaeger01000472010-09-29 10:08:24 +020055/* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
Lennart Poettering5008d582010-09-28 02:34:02 +020056 * them in the file system. This is intended to be used to create
Kay Sieversdb019b82011-04-04 15:33:00 +020057 * properly owned directories beneath /tmp, /var/tmp, /run, which are
58 * volatile and hence need to be recreated on bootup. */
Lennart Poettering5008d582010-09-28 02:34:02 +020059
Michal Schmidt66ccd032011-12-15 21:31:14 +010060typedef enum ItemType {
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +010061 /* These ones take file names */
Lennart Poettering3b63d2d2010-10-18 22:38:41 +020062 CREATE_FILE = 'f',
63 TRUNCATE_FILE = 'F',
Lennart Poettering31ed59c2012-01-18 16:39:04 +010064 WRITE_FILE = 'w',
Lennart Poettering3b63d2d2010-10-18 22:38:41 +020065 CREATE_DIRECTORY = 'd',
66 TRUNCATE_DIRECTORY = 'D',
Lennart Poetteringee17ee72011-07-12 03:56:56 +020067 CREATE_FIFO = 'p',
Lennart Poettering468d7262012-01-17 15:04:12 +010068 CREATE_SYMLINK = 'L',
69 CREATE_CHAR_DEVICE = 'c',
70 CREATE_BLOCK_DEVICE = 'b',
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +010071
72 /* These ones take globs */
Lennart Poettering3b63d2d2010-10-18 22:38:41 +020073 IGNORE_PATH = 'x',
Michal Sekletar78a92a52013-01-18 16:13:08 +010074 IGNORE_DIRECTORY_PATH = 'X',
Lennart Poettering3b63d2d2010-10-18 22:38:41 +020075 REMOVE_PATH = 'r',
Michal Schmidta8d88782011-12-15 23:11:07 +010076 RECURSIVE_REMOVE_PATH = 'R',
Michal Schmidt777b87e2011-12-16 18:27:35 +010077 RELABEL_PATH = 'z',
Michal Schmidta8d88782011-12-15 23:11:07 +010078 RECURSIVE_RELABEL_PATH = 'Z'
Michal Schmidt66ccd032011-12-15 21:31:14 +010079} ItemType;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +020080
81typedef struct Item {
Michal Schmidt66ccd032011-12-15 21:31:14 +010082 ItemType type;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +020083
84 char *path;
Lennart Poettering468d7262012-01-17 15:04:12 +010085 char *argument;
Lennart Poettering5008d582010-09-28 02:34:02 +020086 uid_t uid;
87 gid_t gid;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +020088 mode_t mode;
89 usec_t age;
90
Lennart Poettering468d7262012-01-17 15:04:12 +010091 dev_t major_minor;
92
Lennart Poettering3b63d2d2010-10-18 22:38:41 +020093 bool uid_set:1;
94 bool gid_set:1;
95 bool mode_set:1;
96 bool age_set:1;
Lennart Poettering24f3a372012-06-20 09:05:50 +020097
98 bool keep_first_level:1;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +020099} Item;
100
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +0100101static Hashmap *items = NULL, *globs = NULL;
Lennart Poettering17b90522011-02-14 21:55:06 +0100102static Set *unix_sockets = NULL;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200103
104static bool arg_create = false;
105static bool arg_clean = false;
106static bool arg_remove = false;
107
Dave Reisnera2aced42013-07-24 11:10:05 -0400108static char **include_prefixes = NULL;
Dave Reisner5c795112013-07-24 11:19:24 -0400109static char **exclude_prefixes = NULL;
Lennart Poetteringfba6e682011-02-13 14:00:54 +0100110
Lennart Poetteringfabe5c02013-02-11 23:48:36 +0100111static const char conf_file_dirs[] =
112 "/etc/tmpfiles.d\0"
113 "/run/tmpfiles.d\0"
114 "/usr/local/lib/tmpfiles.d\0"
115 "/usr/lib/tmpfiles.d\0"
Lennart Poettering3f2afb22012-07-20 16:24:55 +0200116#ifdef HAVE_SPLIT_USR
Lennart Poetteringfabe5c02013-02-11 23:48:36 +0100117 "/lib/tmpfiles.d\0"
Lennart Poettering3f2afb22012-07-20 16:24:55 +0200118#endif
Lennart Poetteringfabe5c02013-02-11 23:48:36 +0100119 ;
Dave Reisner91256702012-06-08 22:31:19 -0400120
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200121#define MAX_DEPTH 256
122
Michal Schmidt66ccd032011-12-15 21:31:14 +0100123static bool needs_glob(ItemType t) {
Michal Sekletar78a92a52013-01-18 16:13:08 +0100124 return t == IGNORE_PATH || t == IGNORE_DIRECTORY_PATH || t == REMOVE_PATH || t == RECURSIVE_REMOVE_PATH || t == RELABEL_PATH || t == RECURSIVE_RELABEL_PATH;
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +0100125}
126
127static struct Item* find_glob(Hashmap *h, const char *match) {
128 Item *j;
129 Iterator i;
130
131 HASHMAP_FOREACH(j, h, i)
132 if (fnmatch(j->path, match, FNM_PATHNAME|FNM_PERIOD) == 0)
133 return j;
134
135 return NULL;
136}
137
Lennart Poettering17b90522011-02-14 21:55:06 +0100138static void load_unix_sockets(void) {
Harald Hoyer7fd1b192013-04-18 09:11:22 +0200139 _cleanup_fclose_ FILE *f = NULL;
Lennart Poettering17b90522011-02-14 21:55:06 +0100140 char line[LINE_MAX];
141
142 if (unix_sockets)
143 return;
144
145 /* We maintain a cache of the sockets we found in
146 * /proc/net/unix to speed things up a little. */
147
Lennart Poetteringfdcad0c2012-01-11 22:07:35 +0100148 unix_sockets = set_new(string_hash_func, string_compare_func);
149 if (!unix_sockets)
Lennart Poettering17b90522011-02-14 21:55:06 +0100150 return;
151
Lennart Poetteringfdcad0c2012-01-11 22:07:35 +0100152 f = fopen("/proc/net/unix", "re");
153 if (!f)
Lennart Poettering17b90522011-02-14 21:55:06 +0100154 return;
155
Lennart Poetteringfdcad0c2012-01-11 22:07:35 +0100156 /* Skip header */
157 if (!fgets(line, sizeof(line), f))
Lennart Poettering17b90522011-02-14 21:55:06 +0100158 goto fail;
159
160 for (;;) {
161 char *p, *s;
162 int k;
163
Lennart Poetteringfdcad0c2012-01-11 22:07:35 +0100164 if (!fgets(line, sizeof(line), f))
Lennart Poettering17b90522011-02-14 21:55:06 +0100165 break;
166
167 truncate_nl(line);
168
Lennart Poetteringfdcad0c2012-01-11 22:07:35 +0100169 p = strchr(line, ':');
170 if (!p)
Lennart Poettering17b90522011-02-14 21:55:06 +0100171 continue;
172
Lennart Poetteringfdcad0c2012-01-11 22:07:35 +0100173 if (strlen(p) < 37)
174 continue;
175
176 p += 37;
Lennart Poettering17b90522011-02-14 21:55:06 +0100177 p += strspn(p, WHITESPACE);
Lennart Poetteringfdcad0c2012-01-11 22:07:35 +0100178 p += strcspn(p, WHITESPACE); /* skip one more word */
Lennart Poettering17b90522011-02-14 21:55:06 +0100179 p += strspn(p, WHITESPACE);
180
181 if (*p != '/')
182 continue;
183
Lennart Poetteringfdcad0c2012-01-11 22:07:35 +0100184 s = strdup(p);
185 if (!s)
Lennart Poettering17b90522011-02-14 21:55:06 +0100186 goto fail;
187
Lennart Poettering4ff21d82011-02-17 13:13:34 +0100188 path_kill_slashes(s);
189
Zbigniew Jędrzejewski-Szmekef422022013-04-22 23:12:15 -0400190 k = set_consume(unix_sockets, s);
191 if (k < 0 && k != -EEXIST)
192 goto fail;
Lennart Poettering17b90522011-02-14 21:55:06 +0100193 }
194
195 return;
196
197fail:
198 set_free_free(unix_sockets);
199 unix_sockets = NULL;
Lennart Poettering17b90522011-02-14 21:55:06 +0100200}
201
202static bool unix_socket_alive(const char *fn) {
203 assert(fn);
204
205 load_unix_sockets();
206
207 if (unix_sockets)
208 return !!set_get(unix_sockets, (char*) fn);
209
210 /* We don't know, so assume yes */
211 return true;
212}
213
Kay Sievers99d680a2013-03-13 13:12:36 +0100214static int dir_is_mount_point(DIR *d, const char *subdir) {
215 struct file_handle *h;
216 int mount_id_parent, mount_id;
217 int r_p, r;
218
219 h = alloca(MAX_HANDLE_SZ);
220
221 h->handle_bytes = MAX_HANDLE_SZ;
222 r_p = name_to_handle_at(dirfd(d), ".", h, &mount_id_parent, 0);
223 if (r_p < 0)
224 r_p = -errno;
225
226 h->handle_bytes = MAX_HANDLE_SZ;
227 r = name_to_handle_at(dirfd(d), subdir, h, &mount_id, 0);
228 if (r < 0)
229 r = -errno;
230
231 /* got no handle; make no assumptions, return error */
232 if (r_p < 0 && r < 0)
233 return r_p;
234
235 /* got both handles; if they differ, it is a mount point */
236 if (r_p >= 0 && r >= 0)
237 return mount_id_parent != mount_id;
238
239 /* got only one handle; assume different mount points if one
240 * of both queries was not supported by the filesystem */
241 if (r_p == -ENOSYS || r_p == -ENOTSUP || r == -ENOSYS || r == -ENOTSUP)
242 return true;
243
244 /* return error */
245 if (r_p < 0)
246 return r_p;
247 return r;
248}
249
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200250static int dir_cleanup(
Michal Sekletar78a92a52013-01-18 16:13:08 +0100251 Item *i,
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200252 const char *p,
253 DIR *d,
254 const struct stat *ds,
255 usec_t cutoff,
256 dev_t rootdev,
257 bool mountpoint,
Lennart Poettering24f3a372012-06-20 09:05:50 +0200258 int maxdepth,
259 bool keep_this_level)
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200260{
261 struct dirent *dent;
262 struct timespec times[2];
263 bool deleted = false;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200264 int r = 0;
265
266 while ((dent = readdir(d))) {
267 struct stat s;
268 usec_t age;
Harald Hoyer7fd1b192013-04-18 09:11:22 +0200269 _cleanup_free_ char *sub_path = NULL;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200270
271 if (streq(dent->d_name, ".") ||
272 streq(dent->d_name, ".."))
273 continue;
274
275 if (fstatat(dirfd(d), dent->d_name, &s, AT_SYMLINK_NOFOLLOW) < 0) {
276
277 if (errno != ENOENT) {
278 log_error("stat(%s/%s) failed: %m", p, dent->d_name);
279 r = -errno;
280 }
281
282 continue;
283 }
284
285 /* Stay on the same filesystem */
286 if (s.st_dev != rootdev)
287 continue;
288
Kay Sievers99d680a2013-03-13 13:12:36 +0100289 /* Try to detect bind mounts of the same filesystem instance; they
290 * do not differ in device major/minors. This type of query is not
291 * supported on all kernels or filesystem types though. */
292 if (S_ISDIR(s.st_mode) && dir_is_mount_point(d, dent->d_name) > 0)
293 continue;
294
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200295 /* Do not delete read-only files owned by root */
296 if (s.st_uid == 0 && !(s.st_mode & S_IWUSR))
297 continue;
298
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200299 if (asprintf(&sub_path, "%s/%s", p, dent->d_name) < 0) {
Shawn Landden0d0f0c52012-07-25 14:55:59 -0700300 r = log_oom();
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200301 goto finish;
302 }
303
304 /* Is there an item configured for this path? */
305 if (hashmap_get(items, sub_path))
306 continue;
307
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +0100308 if (find_glob(globs, sub_path))
309 continue;
310
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200311 if (S_ISDIR(s.st_mode)) {
312
313 if (mountpoint &&
314 streq(dent->d_name, "lost+found") &&
315 s.st_uid == 0)
316 continue;
317
318 if (maxdepth <= 0)
319 log_warning("Reached max depth on %s.", sub_path);
320 else {
Harald Hoyer7fd1b192013-04-18 09:11:22 +0200321 _cleanup_closedir_ DIR *sub_dir;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200322 int q;
323
Kay Sieverse5f3d1b2012-04-11 21:33:12 +0200324 sub_dir = xopendirat(dirfd(d), dent->d_name, O_NOFOLLOW|O_NOATIME);
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200325 if (sub_dir == NULL) {
326 if (errno != ENOENT) {
327 log_error("opendir(%s/%s) failed: %m", p, dent->d_name);
328 r = -errno;
329 }
330
331 continue;
332 }
333
Michal Sekletar78a92a52013-01-18 16:13:08 +0100334 q = dir_cleanup(i, sub_path, sub_dir, &s, cutoff, rootdev, false, maxdepth-1, false);
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200335
336 if (q < 0)
337 r = q;
338 }
339
Lennart Poettering24f3a372012-06-20 09:05:50 +0200340 /* Note: if you are wondering why we don't
341 * support the sticky bit for excluding
342 * directories from cleaning like we do it for
343 * other file system objects: well, the sticky
344 * bit already has a meaning for directories,
345 * so we don't want to overload that. */
346
347 if (keep_this_level)
348 continue;
349
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200350 /* Ignore ctime, we change it when deleting */
351 age = MAX(timespec_load(&s.st_mtim),
352 timespec_load(&s.st_atim));
353 if (age >= cutoff)
354 continue;
355
Lukas Nykryna6187d42013-03-01 18:29:59 +0100356 if (i->type != IGNORE_DIRECTORY_PATH || !streq(dent->d_name, p)) {
Michal Sekletar78a92a52013-01-18 16:13:08 +0100357 log_debug("rmdir '%s'\n", sub_path);
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200358
Michal Sekletar78a92a52013-01-18 16:13:08 +0100359 if (unlinkat(dirfd(d), dent->d_name, AT_REMOVEDIR) < 0) {
360 if (errno != ENOENT && errno != ENOTEMPTY) {
361 log_error("rmdir(%s): %m", sub_path);
362 r = -errno;
363 }
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200364 }
365 }
366
367 } else {
Lennart Poettering9c737362010-11-14 20:12:51 +0100368 /* Skip files for which the sticky bit is
369 * set. These are semantics we define, and are
370 * unknown elsewhere. See XDG_RUNTIME_DIR
371 * specification for details. */
372 if (s.st_mode & S_ISVTX)
373 continue;
374
Lennart Poettering17b90522011-02-14 21:55:06 +0100375 if (mountpoint && S_ISREG(s.st_mode)) {
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200376 if (streq(dent->d_name, ".journal") &&
377 s.st_uid == 0)
378 continue;
379
380 if (streq(dent->d_name, "aquota.user") ||
381 streq(dent->d_name, "aquota.group"))
382 continue;
383 }
384
Lennart Poettering17b90522011-02-14 21:55:06 +0100385 /* Ignore sockets that are listed in /proc/net/unix */
386 if (S_ISSOCK(s.st_mode) && unix_socket_alive(sub_path))
387 continue;
388
Lennart Poettering78ab08e2011-02-19 14:20:16 +0100389 /* Ignore device nodes */
390 if (S_ISCHR(s.st_mode) || S_ISBLK(s.st_mode))
391 continue;
392
Lennart Poettering24f3a372012-06-20 09:05:50 +0200393 /* Keep files on this level around if this is
394 * requested */
395 if (keep_this_level)
396 continue;
397
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200398 age = MAX3(timespec_load(&s.st_mtim),
399 timespec_load(&s.st_atim),
400 timespec_load(&s.st_ctim));
401
402 if (age >= cutoff)
403 continue;
404
405 log_debug("unlink '%s'\n", sub_path);
406
407 if (unlinkat(dirfd(d), dent->d_name, 0) < 0) {
408 if (errno != ENOENT) {
409 log_error("unlink(%s): %m", sub_path);
410 r = -errno;
411 }
412 }
413
414 deleted = true;
415 }
416 }
417
418finish:
419 if (deleted) {
420 /* Restore original directory timestamps */
421 times[0] = ds->st_atim;
422 times[1] = ds->st_mtim;
423
424 if (futimens(dirfd(d), times) < 0)
425 log_error("utimensat(%s): %m", p);
426 }
427
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200428 return r;
429}
430
Michal Schmidt062e01b2011-12-16 18:00:11 +0100431static int item_set_perms(Item *i, const char *path) {
432 /* not using i->path directly because it may be a glob */
433 if (i->mode_set)
434 if (chmod(path, i->mode) < 0) {
435 log_error("chmod(%s) failed: %m", path);
436 return -errno;
437 }
438
439 if (i->uid_set || i->gid_set)
440 if (chown(path,
441 i->uid_set ? i->uid : (uid_t) -1,
442 i->gid_set ? i->gid : (gid_t) -1) < 0) {
443
444 log_error("chown(%s) failed: %m", path);
445 return -errno;
446 }
447
Lennart Poetteringc9bc0762012-07-03 16:25:50 +0200448 return label_fix(path, false, false);
Michal Schmidt062e01b2011-12-16 18:00:11 +0100449}
450
Dave Reisnerd4e9eb92012-09-03 17:13:18 -0400451static int write_one_file(Item *i, const char *path) {
452 int r, e, fd, flags;
453 struct stat st;
Dave Reisnerd4e9eb92012-09-03 17:13:18 -0400454
455 flags = i->type == CREATE_FILE ? O_CREAT|O_APPEND :
456 i->type == TRUNCATE_FILE ? O_CREAT|O_TRUNC : 0;
457
Lennart Poettering5c0d3982013-04-04 03:39:39 +0200458 RUN_WITH_UMASK(0) {
459 label_context_set(path, S_IFREG);
460 fd = open(path, flags|O_NDELAY|O_CLOEXEC|O_WRONLY|O_NOCTTY|O_NOFOLLOW, i->mode);
461 e = errno;
462 label_context_clear();
463 errno = e;
464 }
Dave Reisnerd4e9eb92012-09-03 17:13:18 -0400465
466 if (fd < 0) {
467 if (i->type == WRITE_FILE && errno == ENOENT)
468 return 0;
469
470 log_error("Failed to create file %s: %m", path);
471 return -errno;
472 }
473
474 if (i->argument) {
475 ssize_t n;
476 size_t l;
Dave Reisner54693d92012-09-15 12:58:49 -0400477 _cleanup_free_ char *unescaped;
Dave Reisnerd4e9eb92012-09-03 17:13:18 -0400478
Dave Reisner54693d92012-09-15 12:58:49 -0400479 unescaped = cunescape(i->argument);
Thomas Jarosch3785ba62012-12-25 13:46:46 +0100480 if (unescaped == NULL) {
481 close_nointr_nofail(fd);
Dave Reisner54693d92012-09-15 12:58:49 -0400482 return log_oom();
Thomas Jarosch3785ba62012-12-25 13:46:46 +0100483 }
Dave Reisnerd4e9eb92012-09-03 17:13:18 -0400484
Dave Reisner54693d92012-09-15 12:58:49 -0400485 l = strlen(unescaped);
486 n = write(fd, unescaped, l);
Dave Reisnerd4e9eb92012-09-03 17:13:18 -0400487
Dave Reisnerd4e9eb92012-09-03 17:13:18 -0400488 if (n < 0 || (size_t) n < l) {
489 log_error("Failed to write file %s: %s", path, n < 0 ? strerror(-n) : "Short write");
490 close_nointr_nofail(fd);
491 return n < 0 ? n : -EIO;
492 }
493 }
494
Dave Reisner3612fbc2012-09-12 16:21:00 -0400495 close_nointr_nofail(fd);
496
Dave Reisnerd4e9eb92012-09-03 17:13:18 -0400497 if (stat(path, &st) < 0) {
498 log_error("stat(%s) failed: %m", path);
499 return -errno;
500 }
501
502 if (!S_ISREG(st.st_mode)) {
503 log_error("%s is not a file.", path);
504 return -EEXIST;
505 }
506
507 r = item_set_perms(i, path);
508 if (r < 0)
509 return r;
510
511 return 0;
512}
513
Michal Schmidt062e01b2011-12-16 18:00:11 +0100514static int recursive_relabel_children(Item *i, const char *path) {
Harald Hoyer7fd1b192013-04-18 09:11:22 +0200515 _cleanup_closedir_ DIR *d;
Michal Schmidta8d88782011-12-15 23:11:07 +0100516 int ret = 0;
517
518 /* This returns the first error we run into, but nevertheless
519 * tries to go on */
520
521 d = opendir(path);
522 if (!d)
523 return errno == ENOENT ? 0 : -errno;
524
525 for (;;) {
Lennart Poettering7d5e9c02012-09-19 22:21:09 +0200526 struct dirent *de;
527 union dirent_storage buf;
Michal Schmidta8d88782011-12-15 23:11:07 +0100528 bool is_dir;
529 int r;
Harald Hoyer7fd1b192013-04-18 09:11:22 +0200530 _cleanup_free_ char *entry_path = NULL;
Michal Schmidta8d88782011-12-15 23:11:07 +0100531
Lennart Poettering7d5e9c02012-09-19 22:21:09 +0200532 r = readdir_r(d, &buf.de, &de);
Michal Schmidta8d88782011-12-15 23:11:07 +0100533 if (r != 0) {
534 if (ret == 0)
535 ret = -r;
536 break;
537 }
538
539 if (!de)
540 break;
541
542 if (streq(de->d_name, ".") || streq(de->d_name, ".."))
543 continue;
544
545 if (asprintf(&entry_path, "%s/%s", path, de->d_name) < 0) {
546 if (ret == 0)
547 ret = -ENOMEM;
548 continue;
549 }
550
551 if (de->d_type == DT_UNKNOWN) {
552 struct stat st;
553
554 if (lstat(entry_path, &st) < 0) {
555 if (ret == 0 && errno != ENOENT)
556 ret = -errno;
Michal Schmidta8d88782011-12-15 23:11:07 +0100557 continue;
558 }
559
560 is_dir = S_ISDIR(st.st_mode);
561
562 } else
563 is_dir = de->d_type == DT_DIR;
564
Michal Schmidt062e01b2011-12-16 18:00:11 +0100565 r = item_set_perms(i, entry_path);
Michal Schmidta8d88782011-12-15 23:11:07 +0100566 if (r < 0) {
567 if (ret == 0 && r != -ENOENT)
568 ret = r;
Michal Schmidta8d88782011-12-15 23:11:07 +0100569 continue;
570 }
571
572 if (is_dir) {
Michal Schmidt062e01b2011-12-16 18:00:11 +0100573 r = recursive_relabel_children(i, entry_path);
Michal Schmidta8d88782011-12-15 23:11:07 +0100574 if (r < 0 && ret == 0)
575 ret = r;
576 }
Michal Schmidta8d88782011-12-15 23:11:07 +0100577 }
578
Michal Schmidta8d88782011-12-15 23:11:07 +0100579 return ret;
580}
581
582static int recursive_relabel(Item *i, const char *path) {
583 int r;
584 struct stat st;
585
Michal Schmidt062e01b2011-12-16 18:00:11 +0100586 r = item_set_perms(i, path);
Michal Schmidta8d88782011-12-15 23:11:07 +0100587 if (r < 0)
588 return r;
589
590 if (lstat(path, &st) < 0)
591 return -errno;
592
593 if (S_ISDIR(st.st_mode))
Michal Schmidt062e01b2011-12-16 18:00:11 +0100594 r = recursive_relabel_children(i, path);
Michal Schmidta8d88782011-12-15 23:11:07 +0100595
596 return r;
597}
598
Michal Schmidt99e68c02011-12-15 23:45:26 +0100599static int glob_item(Item *i, int (*action)(Item *, const char *)) {
600 int r = 0, k;
Harald Hoyer7fd1b192013-04-18 09:11:22 +0200601 _cleanup_globfree_ glob_t g = {};
Michal Schmidt99e68c02011-12-15 23:45:26 +0100602 char **fn;
603
Michal Schmidt99e68c02011-12-15 23:45:26 +0100604 errno = 0;
Zbigniew Jędrzejewski-Szmekc84a9482013-03-24 19:09:19 -0400605 k = glob(i->path, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
606 if (k != 0)
Michal Schmidt99e68c02011-12-15 23:45:26 +0100607 if (k != GLOB_NOMATCH) {
Zbigniew Jędrzejewski-Szmek8333c772013-03-28 09:24:15 -0400608 if (errno > 0)
Michal Schmidt99e68c02011-12-15 23:45:26 +0100609 errno = EIO;
610
611 log_error("glob(%s) failed: %m", i->path);
612 return -errno;
613 }
Zbigniew Jędrzejewski-Szmekc84a9482013-03-24 19:09:19 -0400614
615 STRV_FOREACH(fn, g.gl_pathv) {
616 k = action(i, *fn);
617 if (k < 0)
618 r = k;
Michal Schmidt99e68c02011-12-15 23:45:26 +0100619 }
620
Michal Schmidt99e68c02011-12-15 23:45:26 +0100621 return r;
622}
623
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200624static int create_item(Item *i) {
Kay Sieverse9a5ef72012-04-17 16:05:03 +0200625 int r, e;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200626 struct stat st;
627
628 assert(i);
629
630 switch (i->type) {
631
632 case IGNORE_PATH:
Michal Sekletar78a92a52013-01-18 16:13:08 +0100633 case IGNORE_DIRECTORY_PATH:
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200634 case REMOVE_PATH:
635 case RECURSIVE_REMOVE_PATH:
636 return 0;
637
638 case CREATE_FILE:
Lennart Poettering31ed59c2012-01-18 16:39:04 +0100639 case TRUNCATE_FILE:
Dave Reisner1845fdd2012-09-27 20:48:13 -0400640 r = write_one_file(i, i->path);
641 if (r < 0)
642 return r;
643 break;
Dave Reisnerd4e9eb92012-09-03 17:13:18 -0400644 case WRITE_FILE:
645 r = glob_item(i, write_one_file);
Michal Schmidtf05bc3f2011-12-15 23:44:23 +0100646 if (r < 0)
647 return r;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200648
649 break;
650
651 case TRUNCATE_DIRECTORY:
652 case CREATE_DIRECTORY:
653
Lennart Poettering5c0d3982013-04-04 03:39:39 +0200654 RUN_WITH_UMASK(0000) {
655 mkdir_parents_label(i->path, 0755);
656 r = mkdir(i->path, i->mode);
657 }
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200658
659 if (r < 0 && errno != EEXIST) {
660 log_error("Failed to create directory %s: %m", i->path);
Michal Schmidtf05bc3f2011-12-15 23:44:23 +0100661 return -errno;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200662 }
663
664 if (stat(i->path, &st) < 0) {
665 log_error("stat(%s) failed: %m", i->path);
Michal Schmidtf05bc3f2011-12-15 23:44:23 +0100666 return -errno;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200667 }
668
669 if (!S_ISDIR(st.st_mode)) {
670 log_error("%s is not a directory.", i->path);
Michal Schmidtf05bc3f2011-12-15 23:44:23 +0100671 return -EEXIST;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200672 }
673
Michal Schmidt062e01b2011-12-16 18:00:11 +0100674 r = item_set_perms(i, i->path);
Michal Schmidtf05bc3f2011-12-15 23:44:23 +0100675 if (r < 0)
676 return r;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200677
678 break;
Lennart Poetteringee17ee72011-07-12 03:56:56 +0200679
680 case CREATE_FIFO:
681
Lennart Poettering5c0d3982013-04-04 03:39:39 +0200682 RUN_WITH_UMASK(0000) {
683 r = mkfifo(i->path, i->mode);
684 }
Lennart Poetteringee17ee72011-07-12 03:56:56 +0200685
686 if (r < 0 && errno != EEXIST) {
687 log_error("Failed to create fifo %s: %m", i->path);
Michal Schmidtf05bc3f2011-12-15 23:44:23 +0100688 return -errno;
Lennart Poetteringee17ee72011-07-12 03:56:56 +0200689 }
690
691 if (stat(i->path, &st) < 0) {
692 log_error("stat(%s) failed: %m", i->path);
Michal Schmidtf05bc3f2011-12-15 23:44:23 +0100693 return -errno;
Lennart Poetteringee17ee72011-07-12 03:56:56 +0200694 }
695
696 if (!S_ISFIFO(st.st_mode)) {
697 log_error("%s is not a fifo.", i->path);
Michal Schmidtf05bc3f2011-12-15 23:44:23 +0100698 return -EEXIST;
Lennart Poetteringee17ee72011-07-12 03:56:56 +0200699 }
700
Michal Schmidt062e01b2011-12-16 18:00:11 +0100701 r = item_set_perms(i, i->path);
Michal Schmidtf05bc3f2011-12-15 23:44:23 +0100702 if (r < 0)
703 return r;
Lennart Poetteringee17ee72011-07-12 03:56:56 +0200704
705 break;
Michal Schmidta8d88782011-12-15 23:11:07 +0100706
Lennart Poettering468d7262012-01-17 15:04:12 +0100707 case CREATE_SYMLINK: {
708 char *x;
709
Kay Sieverse9a5ef72012-04-17 16:05:03 +0200710 label_context_set(i->path, S_IFLNK);
Lennart Poettering468d7262012-01-17 15:04:12 +0100711 r = symlink(i->argument, i->path);
Kay Sieverse9a5ef72012-04-17 16:05:03 +0200712 e = errno;
713 label_context_clear();
714 errno = e;
715
Lennart Poettering468d7262012-01-17 15:04:12 +0100716 if (r < 0 && errno != EEXIST) {
717 log_error("symlink(%s, %s) failed: %m", i->argument, i->path);
718 return -errno;
719 }
720
721 r = readlink_malloc(i->path, &x);
722 if (r < 0) {
723 log_error("readlink(%s) failed: %s", i->path, strerror(-r));
724 return -errno;
725 }
726
727 if (!streq(i->argument, x)) {
728 free(x);
729 log_error("%s is not the right symlinks.", i->path);
730 return -EEXIST;
731 }
732
733 free(x);
734 break;
735 }
736
737 case CREATE_BLOCK_DEVICE:
738 case CREATE_CHAR_DEVICE: {
Lennart Poetteringcb7ed9d2012-09-05 23:39:55 -0700739 mode_t file_type;
740
741 if (have_effective_cap(CAP_MKNOD) == 0) {
742 /* In a container we lack CAP_MKNOD. We
Anatol Pomozovab06eef2013-04-14 19:37:54 -0700743 shouldn't attempt to create the device node in
Lennart Poetteringcb7ed9d2012-09-05 23:39:55 -0700744 that case to avoid noise, and we don't support
745 virtualized devices in containers anyway. */
746
747 log_debug("We lack CAP_MKNOD, skipping creation of device node %s.", i->path);
748 return 0;
749 }
750
751 file_type = (i->type == CREATE_BLOCK_DEVICE ? S_IFBLK : S_IFCHR);
Lennart Poettering468d7262012-01-17 15:04:12 +0100752
Lennart Poettering5c0d3982013-04-04 03:39:39 +0200753 RUN_WITH_UMASK(0000) {
754 label_context_set(i->path, file_type);
755 r = mknod(i->path, i->mode | file_type, i->major_minor);
756 e = errno;
757 label_context_clear();
758 errno = e;
759 }
Lennart Poettering468d7262012-01-17 15:04:12 +0100760
761 if (r < 0 && errno != EEXIST) {
762 log_error("Failed to create device node %s: %m", i->path);
763 return -errno;
764 }
765
766 if (stat(i->path, &st) < 0) {
767 log_error("stat(%s) failed: %m", i->path);
768 return -errno;
769 }
770
Michal Schmidte7aee752012-06-14 16:01:19 +0200771 if ((st.st_mode & S_IFMT) != file_type) {
Lennart Poettering468d7262012-01-17 15:04:12 +0100772 log_error("%s is not a device node.", i->path);
773 return -EEXIST;
774 }
775
776 r = item_set_perms(i, i->path);
777 if (r < 0)
778 return r;
779
780 break;
781 }
782
Michal Schmidt777b87e2011-12-16 18:27:35 +0100783 case RELABEL_PATH:
784
785 r = glob_item(i, item_set_perms);
786 if (r < 0)
Lennart Poettering96ca8192013-06-21 15:57:42 +0200787 return r;
Michal Schmidt777b87e2011-12-16 18:27:35 +0100788 break;
789
Michal Schmidta8d88782011-12-15 23:11:07 +0100790 case RECURSIVE_RELABEL_PATH:
791
792 r = glob_item(i, recursive_relabel);
793 if (r < 0)
794 return r;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200795 }
796
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200797 log_debug("%s created successfully.", i->path);
798
Michal Schmidtf05bc3f2011-12-15 23:44:23 +0100799 return 0;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200800}
801
Michal Schmidta0896122011-12-15 21:32:50 +0100802static int remove_item_instance(Item *i, const char *instance) {
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200803 int r;
804
805 assert(i);
806
807 switch (i->type) {
808
809 case CREATE_FILE:
810 case TRUNCATE_FILE:
811 case CREATE_DIRECTORY:
Lennart Poetteringee17ee72011-07-12 03:56:56 +0200812 case CREATE_FIFO:
Lennart Poettering468d7262012-01-17 15:04:12 +0100813 case CREATE_SYMLINK:
814 case CREATE_BLOCK_DEVICE:
815 case CREATE_CHAR_DEVICE:
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200816 case IGNORE_PATH:
Michal Sekletar78a92a52013-01-18 16:13:08 +0100817 case IGNORE_DIRECTORY_PATH:
Michal Schmidt777b87e2011-12-16 18:27:35 +0100818 case RELABEL_PATH:
Michal Schmidta8d88782011-12-15 23:11:07 +0100819 case RECURSIVE_RELABEL_PATH:
Lennart Poettering31ed59c2012-01-18 16:39:04 +0100820 case WRITE_FILE:
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200821 break;
822
823 case REMOVE_PATH:
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +0100824 if (remove(instance) < 0 && errno != ENOENT) {
825 log_error("remove(%s): %m", instance);
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200826 return -errno;
827 }
828
829 break;
830
831 case TRUNCATE_DIRECTORY:
832 case RECURSIVE_REMOVE_PATH:
Lennart Poetteringd139b242012-06-20 14:31:00 +0200833 /* FIXME: we probably should use dir_cleanup() here
834 * instead of rm_rf() so that 'x' is honoured. */
Lennart Poetteringf56d5db2012-07-10 19:05:58 +0200835 r = rm_rf_dangerous(instance, false, i->type == RECURSIVE_REMOVE_PATH, false);
Lennart Poettering468d7262012-01-17 15:04:12 +0100836 if (r < 0 && r != -ENOENT) {
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +0100837 log_error("rm_rf(%s): %s", instance, strerror(-r));
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200838 return r;
839 }
840
841 break;
842 }
843
844 return 0;
845}
846
Michal Schmidta0896122011-12-15 21:32:50 +0100847static int remove_item(Item *i) {
Michal Schmidt99e68c02011-12-15 23:45:26 +0100848 int r = 0;
849
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +0100850 assert(i);
851
852 switch (i->type) {
853
854 case CREATE_FILE:
855 case TRUNCATE_FILE:
856 case CREATE_DIRECTORY:
Lennart Poetteringee17ee72011-07-12 03:56:56 +0200857 case CREATE_FIFO:
Lennart Poettering468d7262012-01-17 15:04:12 +0100858 case CREATE_SYMLINK:
859 case CREATE_CHAR_DEVICE:
860 case CREATE_BLOCK_DEVICE:
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +0100861 case IGNORE_PATH:
Michal Sekletar78a92a52013-01-18 16:13:08 +0100862 case IGNORE_DIRECTORY_PATH:
Michal Schmidt777b87e2011-12-16 18:27:35 +0100863 case RELABEL_PATH:
Michal Schmidta8d88782011-12-15 23:11:07 +0100864 case RECURSIVE_RELABEL_PATH:
Lennart Poettering31ed59c2012-01-18 16:39:04 +0100865 case WRITE_FILE:
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +0100866 break;
867
868 case REMOVE_PATH:
869 case TRUNCATE_DIRECTORY:
Michal Schmidt99e68c02011-12-15 23:45:26 +0100870 case RECURSIVE_REMOVE_PATH:
871 r = glob_item(i, remove_item_instance);
872 break;
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +0100873 }
874
Michal Schmidt99e68c02011-12-15 23:45:26 +0100875 return r;
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +0100876}
877
Michal Sekletar78a92a52013-01-18 16:13:08 +0100878static int clean_item_instance(Item *i, const char* instance) {
Harald Hoyer7fd1b192013-04-18 09:11:22 +0200879 _cleanup_closedir_ DIR *d = NULL;
Michal Sekletar78a92a52013-01-18 16:13:08 +0100880 struct stat s, ps;
881 bool mountpoint;
882 int r;
883 usec_t cutoff, n;
884
885 assert(i);
886
887 if (!i->age_set)
888 return 0;
889
890 n = now(CLOCK_REALTIME);
891 if (n < i->age)
892 return 0;
893
894 cutoff = n - i->age;
895
896 d = opendir(instance);
897 if (!d) {
898 if (errno == ENOENT || errno == ENOTDIR)
899 return 0;
900
901 log_error("Failed to open directory %s: %m", i->path);
902 return -errno;
903 }
904
905 if (fstat(dirfd(d), &s) < 0) {
906 log_error("stat(%s) failed: %m", i->path);
Zbigniew Jędrzejewski-Szmek19fbec12013-03-03 18:42:52 -0500907 return -errno;
Michal Sekletar78a92a52013-01-18 16:13:08 +0100908 }
909
910 if (!S_ISDIR(s.st_mode)) {
911 log_error("%s is not a directory.", i->path);
Zbigniew Jędrzejewski-Szmek19fbec12013-03-03 18:42:52 -0500912 return -ENOTDIR;
Michal Sekletar78a92a52013-01-18 16:13:08 +0100913 }
914
915 if (fstatat(dirfd(d), "..", &ps, AT_SYMLINK_NOFOLLOW) != 0) {
916 log_error("stat(%s/..) failed: %m", i->path);
Zbigniew Jędrzejewski-Szmek19fbec12013-03-03 18:42:52 -0500917 return -errno;
Michal Sekletar78a92a52013-01-18 16:13:08 +0100918 }
919
920 mountpoint = s.st_dev != ps.st_dev ||
921 (s.st_dev == ps.st_dev && s.st_ino == ps.st_ino);
922
Zbigniew Jędrzejewski-Szmek19fbec12013-03-03 18:42:52 -0500923 r = dir_cleanup(i, instance, d, &s, cutoff, s.st_dev, mountpoint,
924 MAX_DEPTH, i->keep_first_level);
Michal Sekletar78a92a52013-01-18 16:13:08 +0100925 return r;
926}
927
928static int clean_item(Item *i) {
929 int r = 0;
930
931 assert(i);
932
933 switch (i->type) {
934 case CREATE_DIRECTORY:
935 case TRUNCATE_DIRECTORY:
936 case IGNORE_PATH:
937 clean_item_instance(i, i->path);
938 break;
939 case IGNORE_DIRECTORY_PATH:
940 r = glob_item(i, clean_item_instance);
941 break;
942 default:
943 break;
944 }
945
946 return r;
947}
948
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200949static int process_item(Item *i) {
950 int r, q, p;
951
952 assert(i);
953
954 r = arg_create ? create_item(i) : 0;
Michal Schmidta0896122011-12-15 21:32:50 +0100955 q = arg_remove ? remove_item(i) : 0;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200956 p = arg_clean ? clean_item(i) : 0;
957
958 if (r < 0)
959 return r;
960
961 if (q < 0)
962 return q;
963
964 return p;
965}
966
967static void item_free(Item *i) {
968 assert(i);
969
970 free(i->path);
Lennart Poettering468d7262012-01-17 15:04:12 +0100971 free(i->argument);
Lennart Poettering3b63d2d2010-10-18 22:38:41 +0200972 free(i);
973}
974
Maciej Wereskie2f2fb72013-07-19 15:43:12 +0200975static inline void item_freep(Item **i) {
976 if (*i)
977 item_free(*i);
978}
979#define _cleanup_item_free_ _cleanup_(item_freep)
980
Lennart Poetteringbfe95f32011-04-08 04:49:43 +0200981static bool item_equal(Item *a, Item *b) {
982 assert(a);
983 assert(b);
984
985 if (!streq_ptr(a->path, b->path))
986 return false;
987
988 if (a->type != b->type)
989 return false;
990
991 if (a->uid_set != b->uid_set ||
992 (a->uid_set && a->uid != b->uid))
993 return false;
994
995 if (a->gid_set != b->gid_set ||
996 (a->gid_set && a->gid != b->gid))
997 return false;
998
999 if (a->mode_set != b->mode_set ||
1000 (a->mode_set && a->mode != b->mode))
1001 return false;
1002
1003 if (a->age_set != b->age_set ||
1004 (a->age_set && a->age != b->age))
1005 return false;
1006
Lennart Poettering31ed59c2012-01-18 16:39:04 +01001007 if ((a->type == CREATE_FILE ||
1008 a->type == TRUNCATE_FILE ||
1009 a->type == WRITE_FILE ||
1010 a->type == CREATE_SYMLINK) &&
Lennart Poettering1733ca52012-01-22 18:19:24 +01001011 !streq_ptr(a->argument, b->argument))
Lennart Poettering468d7262012-01-17 15:04:12 +01001012 return false;
1013
1014 if ((a->type == CREATE_CHAR_DEVICE ||
1015 a->type == CREATE_BLOCK_DEVICE) &&
1016 a->major_minor != b->major_minor)
1017 return false;
1018
Lennart Poetteringbfe95f32011-04-08 04:49:43 +02001019 return true;
1020}
1021
Dave Reisnera2aced42013-07-24 11:10:05 -04001022static bool should_include_path(const char *path) {
1023 char **prefix;
1024
Dave Reisner5c795112013-07-24 11:19:24 -04001025 STRV_FOREACH(prefix, exclude_prefixes) {
1026 if (path_startswith(path, *prefix))
1027 return false;
1028 }
Dave Reisnera2aced42013-07-24 11:10:05 -04001029
1030 STRV_FOREACH(prefix, include_prefixes) {
1031 if (path_startswith(path, *prefix))
1032 return true;
1033 }
1034
Dave Reisner5c795112013-07-24 11:19:24 -04001035 /* no matches, so we should include this path only if we
1036 * have no whitelist at all */
1037 return strv_length(include_prefixes) == 0;
Dave Reisnera2aced42013-07-24 11:10:05 -04001038}
1039
Lennart Poetteringfba6e682011-02-13 14:00:54 +01001040static int parse_line(const char *fname, unsigned line, const char *buffer) {
Maciej Wereskie2f2fb72013-07-19 15:43:12 +02001041 _cleanup_item_free_ Item *i = NULL;
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001042 Item *existing;
Harald Hoyer7fd1b192013-04-18 09:11:22 +02001043 _cleanup_free_ char
Zbigniew Jędrzejewski-Szmek19fbec12013-03-03 18:42:52 -05001044 *mode = NULL, *user = NULL, *group = NULL, *age = NULL;
Michal Schmidt66ccd032011-12-15 21:31:14 +01001045 char type;
Lennart Poetteringbfe95f32011-04-08 04:49:43 +02001046 Hashmap *h;
Lennart Poettering31ed59c2012-01-18 16:39:04 +01001047 int r, n = -1;
Lennart Poettering5008d582010-09-28 02:34:02 +02001048
1049 assert(fname);
1050 assert(line >= 1);
1051 assert(buffer);
1052
Lennart Poettering468d7262012-01-17 15:04:12 +01001053 i = new0(Item, 1);
Shawn Landden0d0f0c52012-07-25 14:55:59 -07001054 if (!i)
1055 return log_oom();
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001056
Zbigniew Jędrzejewski-Szmek19fbec12013-03-03 18:42:52 -05001057 r = sscanf(buffer,
1058 "%c %ms %ms %ms %ms %ms %n",
Michal Schmidt66ccd032011-12-15 21:31:14 +01001059 &type,
Lennart Poetteringbd40a2d2011-01-22 02:18:59 +01001060 &i->path,
1061 &mode,
1062 &user,
1063 &group,
Lennart Poettering468d7262012-01-17 15:04:12 +01001064 &age,
Zbigniew Jędrzejewski-Szmek19fbec12013-03-03 18:42:52 -05001065 &n);
1066 if (r < 2) {
Lennart Poettering5008d582010-09-28 02:34:02 +02001067 log_error("[%s:%u] Syntax error.", fname, line);
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001068 return -EIO;
Lennart Poettering5008d582010-09-28 02:34:02 +02001069 }
1070
Lennart Poettering31ed59c2012-01-18 16:39:04 +01001071 if (n >= 0) {
1072 n += strspn(buffer+n, WHITESPACE);
1073 if (buffer[n] != 0 && (buffer[n] != '-' || buffer[n+1] != 0)) {
1074 i->argument = unquote(buffer+n, "\"");
Shawn Landden0d0f0c52012-07-25 14:55:59 -07001075 if (!i->argument)
1076 return log_oom();
Lennart Poettering31ed59c2012-01-18 16:39:04 +01001077 }
1078 }
1079
Michal Schmidt777b87e2011-12-16 18:27:35 +01001080 switch(type) {
Lennart Poettering468d7262012-01-17 15:04:12 +01001081
Michal Schmidt777b87e2011-12-16 18:27:35 +01001082 case CREATE_FILE:
1083 case TRUNCATE_FILE:
1084 case CREATE_DIRECTORY:
1085 case TRUNCATE_DIRECTORY:
1086 case CREATE_FIFO:
1087 case IGNORE_PATH:
Michal Sekletar78a92a52013-01-18 16:13:08 +01001088 case IGNORE_DIRECTORY_PATH:
Michal Schmidt777b87e2011-12-16 18:27:35 +01001089 case REMOVE_PATH:
1090 case RECURSIVE_REMOVE_PATH:
1091 case RELABEL_PATH:
1092 case RECURSIVE_RELABEL_PATH:
1093 break;
Lennart Poettering468d7262012-01-17 15:04:12 +01001094
1095 case CREATE_SYMLINK:
1096 if (!i->argument) {
1097 log_error("[%s:%u] Symlink file requires argument.", fname, line);
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001098 return -EBADMSG;
Lennart Poettering468d7262012-01-17 15:04:12 +01001099 }
1100 break;
1101
Lennart Poettering31ed59c2012-01-18 16:39:04 +01001102 case WRITE_FILE:
1103 if (!i->argument) {
1104 log_error("[%s:%u] Write file requires argument.", fname, line);
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001105 return -EBADMSG;
Lennart Poettering31ed59c2012-01-18 16:39:04 +01001106 }
1107 break;
1108
Lennart Poettering468d7262012-01-17 15:04:12 +01001109 case CREATE_CHAR_DEVICE:
1110 case CREATE_BLOCK_DEVICE: {
1111 unsigned major, minor;
1112
1113 if (!i->argument) {
1114 log_error("[%s:%u] Device file requires argument.", fname, line);
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001115 return -EBADMSG;
Lennart Poettering468d7262012-01-17 15:04:12 +01001116 }
1117
1118 if (sscanf(i->argument, "%u:%u", &major, &minor) != 2) {
1119 log_error("[%s:%u] Can't parse device file major/minor '%s'.", fname, line, i->argument);
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001120 return -EBADMSG;
Lennart Poettering468d7262012-01-17 15:04:12 +01001121 }
1122
1123 i->major_minor = makedev(major, minor);
1124 break;
1125 }
1126
Michal Schmidt777b87e2011-12-16 18:27:35 +01001127 default:
Michal Schmidta8d88782011-12-15 23:11:07 +01001128 log_error("[%s:%u] Unknown file type '%c'.", fname, line, type);
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001129 return -EBADMSG;
Lennart Poettering5008d582010-09-28 02:34:02 +02001130 }
Lennart Poettering468d7262012-01-17 15:04:12 +01001131
Michal Schmidta8d88782011-12-15 23:11:07 +01001132 i->type = type;
Lennart Poettering5008d582010-09-28 02:34:02 +02001133
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001134 if (!path_is_absolute(i->path)) {
1135 log_error("[%s:%u] Path '%s' not absolute.", fname, line, i->path);
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001136 return -EBADMSG;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001137 }
1138
1139 path_kill_slashes(i->path);
1140
Dave Reisnera2aced42013-07-24 11:10:05 -04001141 if (!should_include_path(i->path))
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001142 return 0;
Lennart Poettering5008d582010-09-28 02:34:02 +02001143
1144 if (user && !streq(user, "-")) {
Lennart Poettering4b678342011-07-23 01:17:59 +02001145 const char *u = user;
Lennart Poettering5008d582010-09-28 02:34:02 +02001146
Lennart Poetteringd05c5032012-07-16 12:34:54 +02001147 r = get_user_creds(&u, &i->uid, NULL, NULL, NULL);
Lennart Poettering4b678342011-07-23 01:17:59 +02001148 if (r < 0) {
Lennart Poettering5008d582010-09-28 02:34:02 +02001149 log_error("[%s:%u] Unknown user '%s'.", fname, line, user);
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001150 return r;
Lennart Poettering5008d582010-09-28 02:34:02 +02001151 }
1152
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001153 i->uid_set = true;
Lennart Poettering5008d582010-09-28 02:34:02 +02001154 }
1155
1156 if (group && !streq(group, "-")) {
Lennart Poettering4b678342011-07-23 01:17:59 +02001157 const char *g = group;
Lennart Poettering5008d582010-09-28 02:34:02 +02001158
Lennart Poettering4b678342011-07-23 01:17:59 +02001159 r = get_group_creds(&g, &i->gid);
1160 if (r < 0) {
Lennart Poettering5008d582010-09-28 02:34:02 +02001161 log_error("[%s:%u] Unknown group '%s'.", fname, line, group);
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001162 return r;
Lennart Poettering5008d582010-09-28 02:34:02 +02001163 }
1164
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001165 i->gid_set = true;
Lennart Poettering5008d582010-09-28 02:34:02 +02001166 }
1167
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001168 if (mode && !streq(mode, "-")) {
1169 unsigned m;
Lennart Poettering5008d582010-09-28 02:34:02 +02001170
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001171 if (sscanf(mode, "%o", &m) != 1) {
1172 log_error("[%s:%u] Invalid mode '%s'.", fname, line, mode);
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001173 return -ENOENT;
Lennart Poettering5008d582010-09-28 02:34:02 +02001174 }
1175
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001176 i->mode = m;
1177 i->mode_set = true;
1178 } else
Lennart Poettering468d7262012-01-17 15:04:12 +01001179 i->mode =
1180 i->type == CREATE_DIRECTORY ||
1181 i->type == TRUNCATE_DIRECTORY ? 0755 : 0644;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001182
1183 if (age && !streq(age, "-")) {
Lennart Poettering24f3a372012-06-20 09:05:50 +02001184 const char *a = age;
1185
1186 if (*a == '~') {
1187 i->keep_first_level = true;
1188 a++;
1189 }
1190
Lennart Poettering7f602782013-04-02 20:38:16 +02001191 if (parse_sec(a, &i->age) < 0) {
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001192 log_error("[%s:%u] Invalid age '%s'.", fname, line, age);
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001193 return -EBADMSG;
Lennart Poettering5008d582010-09-28 02:34:02 +02001194 }
1195
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001196 i->age_set = true;
Lennart Poettering5008d582010-09-28 02:34:02 +02001197 }
1198
Lennart Poetteringbfe95f32011-04-08 04:49:43 +02001199 h = needs_glob(i->type) ? globs : items;
Lennart Poettering022707d2011-01-05 16:11:15 +01001200
Lennart Poettering468d7262012-01-17 15:04:12 +01001201 existing = hashmap_get(h, i->path);
1202 if (existing) {
Lennart Poetteringbfe95f32011-04-08 04:49:43 +02001203
1204 /* Two identical items are fine */
1205 if (!item_equal(existing, i))
1206 log_warning("Two or more conflicting lines for %s configured, ignoring.", i->path);
1207
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001208 return 0;
Lennart Poetteringbfe95f32011-04-08 04:49:43 +02001209 }
1210
Lennart Poettering468d7262012-01-17 15:04:12 +01001211 r = hashmap_put(h, i->path, i);
1212 if (r < 0) {
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001213 log_error("Failed to insert item %s: %s", i->path, strerror(-r));
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001214 return r;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001215 }
Lennart Poettering5008d582010-09-28 02:34:02 +02001216
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001217 i = NULL; /* avoid cleanup */
Lennart Poettering5008d582010-09-28 02:34:02 +02001218
Zbigniew Jędrzejewski-Szmek7f2c1f42013-03-31 16:29:46 -04001219 return 0;
Lennart Poettering5008d582010-09-28 02:34:02 +02001220}
1221
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001222static int help(void) {
1223
Lennart Poettering522d4a42011-02-13 15:08:15 +01001224 printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
1225 "Creates, deletes and cleans up volatile and temporary files and directories.\n\n"
Dave Reisner5c795112013-07-24 11:19:24 -04001226 " -h --help Show this help\n"
1227 " --create Create marked files/directories\n"
1228 " --clean Clean up marked directories\n"
1229 " --remove Remove marked files/directories\n"
1230 " --prefix=PATH Only apply rules that apply to paths with the specified prefix\n"
1231 " --exclude-prefix=PATH Ignore rules that apply to paths with the specified prefix\n",
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001232 program_invocation_short_name);
1233
1234 return 0;
1235}
1236
1237static int parse_argv(int argc, char *argv[]) {
1238
1239 enum {
1240 ARG_CREATE,
1241 ARG_CLEAN,
Lennart Poetteringfba6e682011-02-13 14:00:54 +01001242 ARG_REMOVE,
Dave Reisner5c795112013-07-24 11:19:24 -04001243 ARG_PREFIX,
1244 ARG_EXCLUDE_PREFIX,
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001245 };
1246
1247 static const struct option options[] = {
Dave Reisner5c795112013-07-24 11:19:24 -04001248 { "help", no_argument, NULL, 'h' },
1249 { "create", no_argument, NULL, ARG_CREATE },
1250 { "clean", no_argument, NULL, ARG_CLEAN },
1251 { "remove", no_argument, NULL, ARG_REMOVE },
1252 { "prefix", required_argument, NULL, ARG_PREFIX },
1253 { "exclude-prefix", required_argument, NULL, ARG_EXCLUDE_PREFIX },
1254 { NULL, 0, NULL, 0 }
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001255 };
1256
1257 int c;
1258
1259 assert(argc >= 0);
1260 assert(argv);
1261
1262 while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
1263
1264 switch (c) {
1265
1266 case 'h':
1267 help();
1268 return 0;
1269
1270 case ARG_CREATE:
1271 arg_create = true;
1272 break;
1273
1274 case ARG_CLEAN:
1275 arg_clean = true;
1276 break;
1277
1278 case ARG_REMOVE:
1279 arg_remove = true;
1280 break;
1281
Lennart Poetteringfba6e682011-02-13 14:00:54 +01001282 case ARG_PREFIX:
Dave Reisnera2aced42013-07-24 11:10:05 -04001283 if (strv_extend(&include_prefixes, optarg) < 0)
1284 return log_oom();
Lennart Poetteringfba6e682011-02-13 14:00:54 +01001285 break;
1286
Dave Reisner5c795112013-07-24 11:19:24 -04001287 case ARG_EXCLUDE_PREFIX:
1288 if (strv_extend(&exclude_prefixes, optarg) < 0)
1289 return log_oom();
1290 break;
1291
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001292 case '?':
1293 return -EINVAL;
1294
1295 default:
1296 log_error("Unknown option code %c", c);
1297 return -EINVAL;
1298 }
1299 }
1300
1301 if (!arg_clean && !arg_create && !arg_remove) {
Harald Hoyer35b8ca32011-02-21 15:32:17 +01001302 log_error("You need to specify at least one of --clean, --create or --remove.");
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001303 return -EINVAL;
1304 }
1305
1306 return 1;
1307}
1308
Lennart Poetteringfba6e682011-02-13 14:00:54 +01001309static int read_config_file(const char *fn, bool ignore_enoent) {
1310 FILE *f;
1311 unsigned v = 0;
Lennart Poetteringfabe5c02013-02-11 23:48:36 +01001312 int r;
Michal Sekletar78a92a52013-01-18 16:13:08 +01001313 Iterator iterator;
1314 Item *i;
Lennart Poetteringfba6e682011-02-13 14:00:54 +01001315
1316 assert(fn);
1317
Lennart Poetteringfabe5c02013-02-11 23:48:36 +01001318 r = search_and_fopen_nulstr(fn, "re", conf_file_dirs, &f);
1319 if (r < 0) {
1320 if (ignore_enoent && r == -ENOENT)
Lennart Poetteringfba6e682011-02-13 14:00:54 +01001321 return 0;
1322
Lennart Poetteringfabe5c02013-02-11 23:48:36 +01001323 log_error("Failed to open '%s', ignoring: %s", fn, strerror(-r));
1324 return r;
Lennart Poetteringfba6e682011-02-13 14:00:54 +01001325 }
1326
Kay Sievers772f8372011-04-25 21:38:21 +02001327 log_debug("apply: %s\n", fn);
Lennart Poetteringfba6e682011-02-13 14:00:54 +01001328 for (;;) {
1329 char line[LINE_MAX], *l;
1330 int k;
1331
1332 if (!(fgets(line, sizeof(line), f)))
1333 break;
1334
1335 v++;
1336
1337 l = strstrip(line);
1338 if (*l == '#' || *l == 0)
1339 continue;
1340
1341 if ((k = parse_line(fn, v, l)) < 0)
1342 if (r == 0)
1343 r = k;
1344 }
1345
Michal Sekletar78a92a52013-01-18 16:13:08 +01001346 /* we have to determine age parameter for each entry of type X */
1347 HASHMAP_FOREACH(i, globs, iterator) {
1348 Iterator iter;
1349 Item *j, *candidate_item = NULL;
1350
1351 if (i->type != IGNORE_DIRECTORY_PATH)
1352 continue;
1353
1354 HASHMAP_FOREACH(j, items, iter) {
1355 if (j->type != CREATE_DIRECTORY && j->type != TRUNCATE_DIRECTORY)
1356 continue;
1357
1358 if (path_equal(j->path, i->path)) {
1359 candidate_item = j;
1360 break;
1361 }
1362
1363 if ((!candidate_item && path_startswith(i->path, j->path)) ||
1364 (candidate_item && path_startswith(j->path, candidate_item->path) && (fnmatch(i->path, j->path, FNM_PATHNAME | FNM_PERIOD) == 0)))
1365 candidate_item = j;
1366 }
1367
1368 if (candidate_item) {
1369 i->age = candidate_item->age;
1370 i->age_set = true;
1371 }
1372 }
1373
Lennart Poetteringfba6e682011-02-13 14:00:54 +01001374 if (ferror(f)) {
1375 log_error("Failed to read from file %s: %m", fn);
1376 if (r == 0)
1377 r = -EIO;
1378 }
1379
1380 fclose(f);
1381
1382 return r;
1383}
1384
Lennart Poettering5008d582010-09-28 02:34:02 +02001385int main(int argc, char *argv[]) {
Lennart Poetteringfabe5c02013-02-11 23:48:36 +01001386 int r, k;
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001387 Item *i;
1388 Iterator iterator;
Lennart Poettering5008d582010-09-28 02:34:02 +02001389
Lennart Poetteringfdcad0c2012-01-11 22:07:35 +01001390 r = parse_argv(argc, argv);
1391 if (r <= 0)
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001392 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
1393
Lennart Poetteringeb0ca9e2011-02-12 09:31:38 +01001394 log_set_target(LOG_TARGET_AUTO);
Lennart Poettering5008d582010-09-28 02:34:02 +02001395 log_parse_environment();
1396 log_open();
1397
Lennart Poettering4c126262011-08-01 20:52:18 +02001398 umask(0022);
1399
Kay Sieverse9a5ef72012-04-17 16:05:03 +02001400 label_init(NULL);
Lennart Poettering5008d582010-09-28 02:34:02 +02001401
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +01001402 items = hashmap_new(string_hash_func, string_compare_func);
1403 globs = hashmap_new(string_hash_func, string_compare_func);
1404
1405 if (!items || !globs) {
Lennart Poetteringfabe5c02013-02-11 23:48:36 +01001406 r = log_oom();
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001407 goto finish;
1408 }
1409
Lennart Poetteringfabe5c02013-02-11 23:48:36 +01001410 r = 0;
Lennart Poettering5008d582010-09-28 02:34:02 +02001411
Lennart Poetteringfba6e682011-02-13 14:00:54 +01001412 if (optind < argc) {
1413 int j;
Lennart Poettering5008d582010-09-28 02:34:02 +02001414
Dave Reisner91256702012-06-08 22:31:19 -04001415 for (j = optind; j < argc; j++) {
Lennart Poetteringfabe5c02013-02-11 23:48:36 +01001416 k = read_config_file(argv[j], false);
1417 if (k < 0 && r == 0)
1418 r = k;
Dave Reisner91256702012-06-08 22:31:19 -04001419 }
Lennart Poettering5008d582010-09-28 02:34:02 +02001420
Lennart Poetteringfba6e682011-02-13 14:00:54 +01001421 } else {
Lennart Poetteringfabe5c02013-02-11 23:48:36 +01001422 _cleanup_strv_free_ char **files = NULL;
1423 char **f;
Lennart Poettering5008d582010-09-28 02:34:02 +02001424
Lennart Poetteringfabe5c02013-02-11 23:48:36 +01001425 r = conf_files_list_nulstr(&files, ".conf", NULL, conf_file_dirs);
Kay Sievers44143302011-04-28 23:51:24 +02001426 if (r < 0) {
Kay Sievers44143302011-04-28 23:51:24 +02001427 log_error("Failed to enumerate tmpfiles.d files: %s", strerror(-r));
1428 goto finish;
1429 }
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001430
Kay Sievers772f8372011-04-25 21:38:21 +02001431 STRV_FOREACH(f, files) {
Lennart Poetteringfabe5c02013-02-11 23:48:36 +01001432 k = read_config_file(*f, true);
1433 if (k < 0 && r == 0)
1434 r = k;
Lennart Poettering5008d582010-09-28 02:34:02 +02001435 }
Lennart Poettering5008d582010-09-28 02:34:02 +02001436 }
1437
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +01001438 HASHMAP_FOREACH(i, globs, iterator)
Lennart Poettering21bdae12011-07-02 01:44:49 +02001439 process_item(i);
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +01001440
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001441 HASHMAP_FOREACH(i, items, iterator)
Lennart Poettering21bdae12011-07-02 01:44:49 +02001442 process_item(i);
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001443
Lennart Poettering5008d582010-09-28 02:34:02 +02001444finish:
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001445 while ((i = hashmap_steal_first(items)))
1446 item_free(i);
1447
Lennart Poettering17b90522011-02-14 21:55:06 +01001448 while ((i = hashmap_steal_first(globs)))
1449 item_free(i);
1450
Lennart Poettering3b63d2d2010-10-18 22:38:41 +02001451 hashmap_free(items);
Lennart Poetteringb8bb3e82011-02-12 09:31:25 +01001452 hashmap_free(globs);
Lennart Poettering5008d582010-09-28 02:34:02 +02001453
Dave Reisnera2aced42013-07-24 11:10:05 -04001454 strv_free(include_prefixes);
1455
Lennart Poettering17b90522011-02-14 21:55:06 +01001456 set_free_free(unix_sockets);
1457
Lennart Poettering29003cf2010-10-19 19:36:45 +02001458 label_finish();
1459
Lennart Poetteringfabe5c02013-02-11 23:48:36 +01001460 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
Lennart Poettering5008d582010-09-28 02:34:02 +02001461}