1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering, Kay Sievers
8 systemd is free software; you can redistribute it and/or modify it
9 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
11 (at your option) any later version.
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 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
37 #include <sys/types.h>
38 #include <sys/param.h>
41 #include <sys/capability.h>
48 #include "path-util.h"
52 #include "conf-files.h"
53 #include "capability.h"
55 /* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
56 * them in the file system. This is intended to be used to create
57 * properly owned directories beneath /tmp, /var/tmp, /run, which are
58 * volatile and hence need to be recreated on bootup. */
60 typedef enum ItemType {
61 /* These ones take file names */
65 CREATE_DIRECTORY = 'd',
66 TRUNCATE_DIRECTORY = 'D',
69 CREATE_CHAR_DEVICE = 'c',
70 CREATE_BLOCK_DEVICE = 'b',
72 /* These ones take globs */
74 IGNORE_DIRECTORY_PATH = 'X',
76 RECURSIVE_REMOVE_PATH = 'R',
78 RECURSIVE_RELABEL_PATH = 'Z'
98 bool keep_first_level:1;
101 static Hashmap *items = NULL, *globs = NULL;
102 static Set *unix_sockets = NULL;
104 static bool arg_create = false;
105 static bool arg_clean = false;
106 static bool arg_remove = false;
108 static const char *arg_prefix = NULL;
110 static const char conf_file_dirs[] =
113 "/usr/local/lib/tmpfiles.d\0"
114 "/usr/lib/tmpfiles.d\0"
115 #ifdef HAVE_SPLIT_USR
120 #define MAX_DEPTH 256
122 static bool needs_glob(ItemType t) {
123 return t == IGNORE_PATH || t == IGNORE_DIRECTORY_PATH || t == REMOVE_PATH || t == RECURSIVE_REMOVE_PATH || t == RELABEL_PATH || t == RECURSIVE_RELABEL_PATH;
126 static struct Item* find_glob(Hashmap *h, const char *match) {
130 HASHMAP_FOREACH(j, h, i)
131 if (fnmatch(j->path, match, FNM_PATHNAME|FNM_PERIOD) == 0)
137 static void load_unix_sockets(void) {
138 FILE _cleanup_fclose_ *f = NULL;
144 /* We maintain a cache of the sockets we found in
145 * /proc/net/unix to speed things up a little. */
147 unix_sockets = set_new(string_hash_func, string_compare_func);
151 f = fopen("/proc/net/unix", "re");
156 if (!fgets(line, sizeof(line), f))
163 if (!fgets(line, sizeof(line), f))
168 p = strchr(line, ':');
176 p += strspn(p, WHITESPACE);
177 p += strcspn(p, WHITESPACE); /* skip one more word */
178 p += strspn(p, WHITESPACE);
187 path_kill_slashes(s);
189 k = set_put(unix_sockets, s);
201 set_free_free(unix_sockets);
205 static bool unix_socket_alive(const char *fn) {
211 return !!set_get(unix_sockets, (char*) fn);
213 /* We don't know, so assume yes */
217 static int dir_is_mount_point(DIR *d, const char *subdir) {
218 struct file_handle *h;
219 int mount_id_parent, mount_id;
222 h = alloca(MAX_HANDLE_SZ);
224 h->handle_bytes = MAX_HANDLE_SZ;
225 r_p = name_to_handle_at(dirfd(d), ".", h, &mount_id_parent, 0);
229 h->handle_bytes = MAX_HANDLE_SZ;
230 r = name_to_handle_at(dirfd(d), subdir, h, &mount_id, 0);
234 /* got no handle; make no assumptions, return error */
235 if (r_p < 0 && r < 0)
238 /* got both handles; if they differ, it is a mount point */
239 if (r_p >= 0 && r >= 0)
240 return mount_id_parent != mount_id;
242 /* got only one handle; assume different mount points if one
243 * of both queries was not supported by the filesystem */
244 if (r_p == -ENOSYS || r_p == -ENOTSUP || r == -ENOSYS || r == -ENOTSUP)
253 static int dir_cleanup(
257 const struct stat *ds,
262 bool keep_this_level)
265 struct timespec times[2];
266 bool deleted = false;
269 while ((dent = readdir(d))) {
272 char _cleanup_free_ *sub_path = NULL;
274 if (streq(dent->d_name, ".") ||
275 streq(dent->d_name, ".."))
278 if (fstatat(dirfd(d), dent->d_name, &s, AT_SYMLINK_NOFOLLOW) < 0) {
280 if (errno != ENOENT) {
281 log_error("stat(%s/%s) failed: %m", p, dent->d_name);
288 /* Stay on the same filesystem */
289 if (s.st_dev != rootdev)
292 /* Try to detect bind mounts of the same filesystem instance; they
293 * do not differ in device major/minors. This type of query is not
294 * supported on all kernels or filesystem types though. */
295 if (S_ISDIR(s.st_mode) && dir_is_mount_point(d, dent->d_name) > 0)
298 /* Do not delete read-only files owned by root */
299 if (s.st_uid == 0 && !(s.st_mode & S_IWUSR))
302 if (asprintf(&sub_path, "%s/%s", p, dent->d_name) < 0) {
307 /* Is there an item configured for this path? */
308 if (hashmap_get(items, sub_path))
311 if (find_glob(globs, sub_path))
314 if (S_ISDIR(s.st_mode)) {
317 streq(dent->d_name, "lost+found") &&
322 log_warning("Reached max depth on %s.", sub_path);
324 DIR _cleanup_closedir_ *sub_dir;
327 sub_dir = xopendirat(dirfd(d), dent->d_name, O_NOFOLLOW|O_NOATIME);
328 if (sub_dir == NULL) {
329 if (errno != ENOENT) {
330 log_error("opendir(%s/%s) failed: %m", p, dent->d_name);
337 q = dir_cleanup(i, sub_path, sub_dir, &s, cutoff, rootdev, false, maxdepth-1, false);
343 /* Note: if you are wondering why we don't
344 * support the sticky bit for excluding
345 * directories from cleaning like we do it for
346 * other file system objects: well, the sticky
347 * bit already has a meaning for directories,
348 * so we don't want to overload that. */
353 /* Ignore ctime, we change it when deleting */
354 age = MAX(timespec_load(&s.st_mtim),
355 timespec_load(&s.st_atim));
359 if (i->type != IGNORE_DIRECTORY_PATH || !streq(dent->d_name, p)) {
360 log_debug("rmdir '%s'\n", sub_path);
362 if (unlinkat(dirfd(d), dent->d_name, AT_REMOVEDIR) < 0) {
363 if (errno != ENOENT && errno != ENOTEMPTY) {
364 log_error("rmdir(%s): %m", sub_path);
371 /* Skip files for which the sticky bit is
372 * set. These are semantics we define, and are
373 * unknown elsewhere. See XDG_RUNTIME_DIR
374 * specification for details. */
375 if (s.st_mode & S_ISVTX)
378 if (mountpoint && S_ISREG(s.st_mode)) {
379 if (streq(dent->d_name, ".journal") &&
383 if (streq(dent->d_name, "aquota.user") ||
384 streq(dent->d_name, "aquota.group"))
388 /* Ignore sockets that are listed in /proc/net/unix */
389 if (S_ISSOCK(s.st_mode) && unix_socket_alive(sub_path))
392 /* Ignore device nodes */
393 if (S_ISCHR(s.st_mode) || S_ISBLK(s.st_mode))
396 /* Keep files on this level around if this is
401 age = MAX3(timespec_load(&s.st_mtim),
402 timespec_load(&s.st_atim),
403 timespec_load(&s.st_ctim));
408 log_debug("unlink '%s'\n", sub_path);
410 if (unlinkat(dirfd(d), dent->d_name, 0) < 0) {
411 if (errno != ENOENT) {
412 log_error("unlink(%s): %m", sub_path);
423 /* Restore original directory timestamps */
424 times[0] = ds->st_atim;
425 times[1] = ds->st_mtim;
427 if (futimens(dirfd(d), times) < 0)
428 log_error("utimensat(%s): %m", p);
434 static int item_set_perms(Item *i, const char *path) {
435 /* not using i->path directly because it may be a glob */
437 if (chmod(path, i->mode) < 0) {
438 log_error("chmod(%s) failed: %m", path);
442 if (i->uid_set || i->gid_set)
444 i->uid_set ? i->uid : (uid_t) -1,
445 i->gid_set ? i->gid : (gid_t) -1) < 0) {
447 log_error("chown(%s) failed: %m", path);
451 return label_fix(path, false, false);
454 static int write_one_file(Item *i, const char *path) {
458 flags = i->type == CREATE_FILE ? O_CREAT|O_APPEND :
459 i->type == TRUNCATE_FILE ? O_CREAT|O_TRUNC : 0;
462 label_context_set(path, S_IFREG);
463 fd = open(path, flags|O_NDELAY|O_CLOEXEC|O_WRONLY|O_NOCTTY|O_NOFOLLOW, i->mode);
465 label_context_clear();
470 if (i->type == WRITE_FILE && errno == ENOENT)
473 log_error("Failed to create file %s: %m", path);
480 _cleanup_free_ char *unescaped;
482 unescaped = cunescape(i->argument);
483 if (unescaped == NULL) {
484 close_nointr_nofail(fd);
488 l = strlen(unescaped);
489 n = write(fd, unescaped, l);
491 if (n < 0 || (size_t) n < l) {
492 log_error("Failed to write file %s: %s", path, n < 0 ? strerror(-n) : "Short write");
493 close_nointr_nofail(fd);
494 return n < 0 ? n : -EIO;
498 close_nointr_nofail(fd);
500 if (stat(path, &st) < 0) {
501 log_error("stat(%s) failed: %m", path);
505 if (!S_ISREG(st.st_mode)) {
506 log_error("%s is not a file.", path);
510 r = item_set_perms(i, path);
517 static int recursive_relabel_children(Item *i, const char *path) {
518 DIR _cleanup_closedir_ *d;
521 /* This returns the first error we run into, but nevertheless
526 return errno == ENOENT ? 0 : -errno;
530 union dirent_storage buf;
533 char _cleanup_free_ *entry_path = NULL;
535 r = readdir_r(d, &buf.de, &de);
545 if (streq(de->d_name, ".") || streq(de->d_name, ".."))
548 if (asprintf(&entry_path, "%s/%s", path, de->d_name) < 0) {
554 if (de->d_type == DT_UNKNOWN) {
557 if (lstat(entry_path, &st) < 0) {
558 if (ret == 0 && errno != ENOENT)
563 is_dir = S_ISDIR(st.st_mode);
566 is_dir = de->d_type == DT_DIR;
568 r = item_set_perms(i, entry_path);
570 if (ret == 0 && r != -ENOENT)
576 r = recursive_relabel_children(i, entry_path);
577 if (r < 0 && ret == 0)
585 static int recursive_relabel(Item *i, const char *path) {
589 r = item_set_perms(i, path);
593 if (lstat(path, &st) < 0)
596 if (S_ISDIR(st.st_mode))
597 r = recursive_relabel_children(i, path);
602 static int glob_item(Item *i, int (*action)(Item *, const char *)) {
610 if ((k = glob(i->path, GLOB_NOSORT|GLOB_BRACE, NULL, &g)) != 0) {
612 if (k != GLOB_NOMATCH) {
616 log_error("glob(%s) failed: %m", i->path);
621 STRV_FOREACH(fn, g.gl_pathv)
622 if ((k = action(i, *fn)) < 0)
629 static int create_item(Item *i) {
638 case IGNORE_DIRECTORY_PATH:
640 case RECURSIVE_REMOVE_PATH:
645 r = write_one_file(i, i->path);
650 r = glob_item(i, write_one_file);
656 case TRUNCATE_DIRECTORY:
657 case CREATE_DIRECTORY:
659 RUN_WITH_UMASK(0000) {
660 mkdir_parents_label(i->path, 0755);
661 r = mkdir(i->path, i->mode);
664 if (r < 0 && errno != EEXIST) {
665 log_error("Failed to create directory %s: %m", i->path);
669 if (stat(i->path, &st) < 0) {
670 log_error("stat(%s) failed: %m", i->path);
674 if (!S_ISDIR(st.st_mode)) {
675 log_error("%s is not a directory.", i->path);
679 r = item_set_perms(i, i->path);
687 RUN_WITH_UMASK(0000) {
688 r = mkfifo(i->path, i->mode);
691 if (r < 0 && errno != EEXIST) {
692 log_error("Failed to create fifo %s: %m", i->path);
696 if (stat(i->path, &st) < 0) {
697 log_error("stat(%s) failed: %m", i->path);
701 if (!S_ISFIFO(st.st_mode)) {
702 log_error("%s is not a fifo.", i->path);
706 r = item_set_perms(i, i->path);
712 case CREATE_SYMLINK: {
715 label_context_set(i->path, S_IFLNK);
716 r = symlink(i->argument, i->path);
718 label_context_clear();
721 if (r < 0 && errno != EEXIST) {
722 log_error("symlink(%s, %s) failed: %m", i->argument, i->path);
726 r = readlink_malloc(i->path, &x);
728 log_error("readlink(%s) failed: %s", i->path, strerror(-r));
732 if (!streq(i->argument, x)) {
734 log_error("%s is not the right symlinks.", i->path);
742 case CREATE_BLOCK_DEVICE:
743 case CREATE_CHAR_DEVICE: {
746 if (have_effective_cap(CAP_MKNOD) == 0) {
747 /* In a container we lack CAP_MKNOD. We
748 shouldnt attempt to create the device node in
749 that case to avoid noise, and we don't support
750 virtualized devices in containers anyway. */
752 log_debug("We lack CAP_MKNOD, skipping creation of device node %s.", i->path);
756 file_type = (i->type == CREATE_BLOCK_DEVICE ? S_IFBLK : S_IFCHR);
758 RUN_WITH_UMASK(0000) {
759 label_context_set(i->path, file_type);
760 r = mknod(i->path, i->mode | file_type, i->major_minor);
762 label_context_clear();
766 if (r < 0 && errno != EEXIST) {
767 log_error("Failed to create device node %s: %m", i->path);
771 if (stat(i->path, &st) < 0) {
772 log_error("stat(%s) failed: %m", i->path);
776 if ((st.st_mode & S_IFMT) != file_type) {
777 log_error("%s is not a device node.", i->path);
781 r = item_set_perms(i, i->path);
790 r = glob_item(i, item_set_perms);
795 case RECURSIVE_RELABEL_PATH:
797 r = glob_item(i, recursive_relabel);
802 log_debug("%s created successfully.", i->path);
807 static int remove_item_instance(Item *i, const char *instance) {
816 case CREATE_DIRECTORY:
819 case CREATE_BLOCK_DEVICE:
820 case CREATE_CHAR_DEVICE:
822 case IGNORE_DIRECTORY_PATH:
824 case RECURSIVE_RELABEL_PATH:
829 if (remove(instance) < 0 && errno != ENOENT) {
830 log_error("remove(%s): %m", instance);
836 case TRUNCATE_DIRECTORY:
837 case RECURSIVE_REMOVE_PATH:
838 /* FIXME: we probably should use dir_cleanup() here
839 * instead of rm_rf() so that 'x' is honoured. */
840 r = rm_rf_dangerous(instance, false, i->type == RECURSIVE_REMOVE_PATH, false);
841 if (r < 0 && r != -ENOENT) {
842 log_error("rm_rf(%s): %s", instance, strerror(-r));
852 static int remove_item(Item *i) {
861 case CREATE_DIRECTORY:
864 case CREATE_CHAR_DEVICE:
865 case CREATE_BLOCK_DEVICE:
867 case IGNORE_DIRECTORY_PATH:
869 case RECURSIVE_RELABEL_PATH:
874 case TRUNCATE_DIRECTORY:
875 case RECURSIVE_REMOVE_PATH:
876 r = glob_item(i, remove_item_instance);
883 static int clean_item_instance(Item *i, const char* instance) {
884 DIR _cleanup_closedir_ *d = NULL;
895 n = now(CLOCK_REALTIME);
901 d = opendir(instance);
903 if (errno == ENOENT || errno == ENOTDIR)
906 log_error("Failed to open directory %s: %m", i->path);
910 if (fstat(dirfd(d), &s) < 0) {
911 log_error("stat(%s) failed: %m", i->path);
915 if (!S_ISDIR(s.st_mode)) {
916 log_error("%s is not a directory.", i->path);
920 if (fstatat(dirfd(d), "..", &ps, AT_SYMLINK_NOFOLLOW) != 0) {
921 log_error("stat(%s/..) failed: %m", i->path);
925 mountpoint = s.st_dev != ps.st_dev ||
926 (s.st_dev == ps.st_dev && s.st_ino == ps.st_ino);
928 r = dir_cleanup(i, instance, d, &s, cutoff, s.st_dev, mountpoint,
929 MAX_DEPTH, i->keep_first_level);
933 static int clean_item(Item *i) {
939 case CREATE_DIRECTORY:
940 case TRUNCATE_DIRECTORY:
942 clean_item_instance(i, i->path);
944 case IGNORE_DIRECTORY_PATH:
945 r = glob_item(i, clean_item_instance);
954 static int process_item(Item *i) {
959 r = arg_create ? create_item(i) : 0;
960 q = arg_remove ? remove_item(i) : 0;
961 p = arg_clean ? clean_item(i) : 0;
972 static void item_free(Item *i) {
980 static bool item_equal(Item *a, Item *b) {
984 if (!streq_ptr(a->path, b->path))
987 if (a->type != b->type)
990 if (a->uid_set != b->uid_set ||
991 (a->uid_set && a->uid != b->uid))
994 if (a->gid_set != b->gid_set ||
995 (a->gid_set && a->gid != b->gid))
998 if (a->mode_set != b->mode_set ||
999 (a->mode_set && a->mode != b->mode))
1002 if (a->age_set != b->age_set ||
1003 (a->age_set && a->age != b->age))
1006 if ((a->type == CREATE_FILE ||
1007 a->type == TRUNCATE_FILE ||
1008 a->type == WRITE_FILE ||
1009 a->type == CREATE_SYMLINK) &&
1010 !streq_ptr(a->argument, b->argument))
1013 if ((a->type == CREATE_CHAR_DEVICE ||
1014 a->type == CREATE_BLOCK_DEVICE) &&
1015 a->major_minor != b->major_minor)
1021 static int parse_line(const char *fname, unsigned line, const char *buffer) {
1022 Item _cleanup_free_ *i = NULL;
1025 *mode = NULL, *user = NULL, *group = NULL, *age = NULL;
1039 "%c %ms %ms %ms %ms %ms %n",
1048 log_error("[%s:%u] Syntax error.", fname, line);
1053 n += strspn(buffer+n, WHITESPACE);
1054 if (buffer[n] != 0 && (buffer[n] != '-' || buffer[n+1] != 0)) {
1055 i->argument = unquote(buffer+n, "\"");
1065 case CREATE_DIRECTORY:
1066 case TRUNCATE_DIRECTORY:
1069 case IGNORE_DIRECTORY_PATH:
1071 case RECURSIVE_REMOVE_PATH:
1073 case RECURSIVE_RELABEL_PATH:
1076 case CREATE_SYMLINK:
1078 log_error("[%s:%u] Symlink file requires argument.", fname, line);
1085 log_error("[%s:%u] Write file requires argument.", fname, line);
1090 case CREATE_CHAR_DEVICE:
1091 case CREATE_BLOCK_DEVICE: {
1092 unsigned major, minor;
1095 log_error("[%s:%u] Device file requires argument.", fname, line);
1099 if (sscanf(i->argument, "%u:%u", &major, &minor) != 2) {
1100 log_error("[%s:%u] Can't parse device file major/minor '%s'.", fname, line, i->argument);
1104 i->major_minor = makedev(major, minor);
1109 log_error("[%s:%u] Unknown file type '%c'.", fname, line, type);
1115 if (!path_is_absolute(i->path)) {
1116 log_error("[%s:%u] Path '%s' not absolute.", fname, line, i->path);
1120 path_kill_slashes(i->path);
1122 if (arg_prefix && !path_startswith(i->path, arg_prefix))
1125 if (user && !streq(user, "-")) {
1126 const char *u = user;
1128 r = get_user_creds(&u, &i->uid, NULL, NULL, NULL);
1130 log_error("[%s:%u] Unknown user '%s'.", fname, line, user);
1137 if (group && !streq(group, "-")) {
1138 const char *g = group;
1140 r = get_group_creds(&g, &i->gid);
1142 log_error("[%s:%u] Unknown group '%s'.", fname, line, group);
1149 if (mode && !streq(mode, "-")) {
1152 if (sscanf(mode, "%o", &m) != 1) {
1153 log_error("[%s:%u] Invalid mode '%s'.", fname, line, mode);
1161 i->type == CREATE_DIRECTORY ||
1162 i->type == TRUNCATE_DIRECTORY ? 0755 : 0644;
1164 if (age && !streq(age, "-")) {
1165 const char *a = age;
1168 i->keep_first_level = true;
1172 if (parse_sec(a, &i->age) < 0) {
1173 log_error("[%s:%u] Invalid age '%s'.", fname, line, age);
1180 h = needs_glob(i->type) ? globs : items;
1182 existing = hashmap_get(h, i->path);
1185 /* Two identical items are fine */
1186 if (!item_equal(existing, i))
1187 log_warning("Two or more conflicting lines for %s configured, ignoring.", i->path);
1192 r = hashmap_put(h, i->path, i);
1194 log_error("Failed to insert item %s: %s", i->path, strerror(-r));
1198 i = NULL; /* avoid cleanup */
1203 static int help(void) {
1205 printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
1206 "Creates, deletes and cleans up volatile and temporary files and directories.\n\n"
1207 " -h --help Show this help\n"
1208 " --create Create marked files/directories\n"
1209 " --clean Clean up marked directories\n"
1210 " --remove Remove marked files/directories\n"
1211 " --prefix=PATH Only apply rules that apply to paths with the specified prefix\n",
1212 program_invocation_short_name);
1217 static int parse_argv(int argc, char *argv[]) {
1226 static const struct option options[] = {
1227 { "help", no_argument, NULL, 'h' },
1228 { "create", no_argument, NULL, ARG_CREATE },
1229 { "clean", no_argument, NULL, ARG_CLEAN },
1230 { "remove", no_argument, NULL, ARG_REMOVE },
1231 { "prefix", required_argument, NULL, ARG_PREFIX },
1232 { NULL, 0, NULL, 0 }
1240 while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
1261 arg_prefix = optarg;
1268 log_error("Unknown option code %c", c);
1273 if (!arg_clean && !arg_create && !arg_remove) {
1274 log_error("You need to specify at least one of --clean, --create or --remove.");
1281 static int read_config_file(const char *fn, bool ignore_enoent) {
1290 r = search_and_fopen_nulstr(fn, "re", conf_file_dirs, &f);
1292 if (ignore_enoent && r == -ENOENT)
1295 log_error("Failed to open '%s', ignoring: %s", fn, strerror(-r));
1299 log_debug("apply: %s\n", fn);
1301 char line[LINE_MAX], *l;
1304 if (!(fgets(line, sizeof(line), f)))
1310 if (*l == '#' || *l == 0)
1313 if ((k = parse_line(fn, v, l)) < 0)
1318 /* we have to determine age parameter for each entry of type X */
1319 HASHMAP_FOREACH(i, globs, iterator) {
1321 Item *j, *candidate_item = NULL;
1323 if (i->type != IGNORE_DIRECTORY_PATH)
1326 HASHMAP_FOREACH(j, items, iter) {
1327 if (j->type != CREATE_DIRECTORY && j->type != TRUNCATE_DIRECTORY)
1330 if (path_equal(j->path, i->path)) {
1335 if ((!candidate_item && path_startswith(i->path, j->path)) ||
1336 (candidate_item && path_startswith(j->path, candidate_item->path) && (fnmatch(i->path, j->path, FNM_PATHNAME | FNM_PERIOD) == 0)))
1340 if (candidate_item) {
1341 i->age = candidate_item->age;
1347 log_error("Failed to read from file %s: %m", fn);
1357 int main(int argc, char *argv[]) {
1362 r = parse_argv(argc, argv);
1364 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
1366 log_set_target(LOG_TARGET_AUTO);
1367 log_parse_environment();
1374 items = hashmap_new(string_hash_func, string_compare_func);
1375 globs = hashmap_new(string_hash_func, string_compare_func);
1377 if (!items || !globs) {
1384 if (optind < argc) {
1387 for (j = optind; j < argc; j++) {
1388 k = read_config_file(argv[j], false);
1389 if (k < 0 && r == 0)
1394 _cleanup_strv_free_ char **files = NULL;
1397 r = conf_files_list_nulstr(&files, ".conf", NULL, conf_file_dirs);
1399 log_error("Failed to enumerate tmpfiles.d files: %s", strerror(-r));
1403 STRV_FOREACH(f, files) {
1404 k = read_config_file(*f, true);
1405 if (k < 0 && r == 0)
1410 HASHMAP_FOREACH(i, globs, iterator)
1413 HASHMAP_FOREACH(i, items, iterator)
1417 while ((i = hashmap_steal_first(items)))
1420 while ((i = hashmap_steal_first(globs)))
1423 hashmap_free(items);
1424 hashmap_free(globs);
1426 set_free_free(unix_sockets);
1430 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;