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 _cleanup_fclose_ FILE *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_consume(unix_sockets, s);
190 if (k < 0 && k != -EEXIST)
197 set_free_free(unix_sockets);
201 static bool unix_socket_alive(const char *fn) {
207 return !!set_get(unix_sockets, (char*) fn);
209 /* We don't know, so assume yes */
213 static int dir_is_mount_point(DIR *d, const char *subdir) {
214 struct file_handle *h;
215 int mount_id_parent, mount_id;
218 h = alloca(MAX_HANDLE_SZ);
220 h->handle_bytes = MAX_HANDLE_SZ;
221 r_p = name_to_handle_at(dirfd(d), ".", h, &mount_id_parent, 0);
225 h->handle_bytes = MAX_HANDLE_SZ;
226 r = name_to_handle_at(dirfd(d), subdir, h, &mount_id, 0);
230 /* got no handle; make no assumptions, return error */
231 if (r_p < 0 && r < 0)
234 /* got both handles; if they differ, it is a mount point */
235 if (r_p >= 0 && r >= 0)
236 return mount_id_parent != mount_id;
238 /* got only one handle; assume different mount points if one
239 * of both queries was not supported by the filesystem */
240 if (r_p == -ENOSYS || r_p == -ENOTSUP || r == -ENOSYS || r == -ENOTSUP)
249 static int dir_cleanup(
253 const struct stat *ds,
258 bool keep_this_level)
261 struct timespec times[2];
262 bool deleted = false;
265 while ((dent = readdir(d))) {
268 _cleanup_free_ char *sub_path = NULL;
270 if (streq(dent->d_name, ".") ||
271 streq(dent->d_name, ".."))
274 if (fstatat(dirfd(d), dent->d_name, &s, AT_SYMLINK_NOFOLLOW) < 0) {
276 if (errno != ENOENT) {
277 log_error("stat(%s/%s) failed: %m", p, dent->d_name);
284 /* Stay on the same filesystem */
285 if (s.st_dev != rootdev)
288 /* Try to detect bind mounts of the same filesystem instance; they
289 * do not differ in device major/minors. This type of query is not
290 * supported on all kernels or filesystem types though. */
291 if (S_ISDIR(s.st_mode) && dir_is_mount_point(d, dent->d_name) > 0)
294 /* Do not delete read-only files owned by root */
295 if (s.st_uid == 0 && !(s.st_mode & S_IWUSR))
298 if (asprintf(&sub_path, "%s/%s", p, dent->d_name) < 0) {
303 /* Is there an item configured for this path? */
304 if (hashmap_get(items, sub_path))
307 if (find_glob(globs, sub_path))
310 if (S_ISDIR(s.st_mode)) {
313 streq(dent->d_name, "lost+found") &&
318 log_warning("Reached max depth on %s.", sub_path);
320 _cleanup_closedir_ DIR *sub_dir;
323 sub_dir = xopendirat(dirfd(d), dent->d_name, O_NOFOLLOW|O_NOATIME);
324 if (sub_dir == NULL) {
325 if (errno != ENOENT) {
326 log_error("opendir(%s/%s) failed: %m", p, dent->d_name);
333 q = dir_cleanup(i, sub_path, sub_dir, &s, cutoff, rootdev, false, maxdepth-1, false);
339 /* Note: if you are wondering why we don't
340 * support the sticky bit for excluding
341 * directories from cleaning like we do it for
342 * other file system objects: well, the sticky
343 * bit already has a meaning for directories,
344 * so we don't want to overload that. */
349 /* Ignore ctime, we change it when deleting */
350 age = MAX(timespec_load(&s.st_mtim),
351 timespec_load(&s.st_atim));
355 if (i->type != IGNORE_DIRECTORY_PATH || !streq(dent->d_name, p)) {
356 log_debug("rmdir '%s'\n", sub_path);
358 if (unlinkat(dirfd(d), dent->d_name, AT_REMOVEDIR) < 0) {
359 if (errno != ENOENT && errno != ENOTEMPTY) {
360 log_error("rmdir(%s): %m", sub_path);
367 /* Skip files for which the sticky bit is
368 * set. These are semantics we define, and are
369 * unknown elsewhere. See XDG_RUNTIME_DIR
370 * specification for details. */
371 if (s.st_mode & S_ISVTX)
374 if (mountpoint && S_ISREG(s.st_mode)) {
375 if (streq(dent->d_name, ".journal") &&
379 if (streq(dent->d_name, "aquota.user") ||
380 streq(dent->d_name, "aquota.group"))
384 /* Ignore sockets that are listed in /proc/net/unix */
385 if (S_ISSOCK(s.st_mode) && unix_socket_alive(sub_path))
388 /* Ignore device nodes */
389 if (S_ISCHR(s.st_mode) || S_ISBLK(s.st_mode))
392 /* Keep files on this level around if this is
397 age = MAX3(timespec_load(&s.st_mtim),
398 timespec_load(&s.st_atim),
399 timespec_load(&s.st_ctim));
404 log_debug("unlink '%s'\n", sub_path);
406 if (unlinkat(dirfd(d), dent->d_name, 0) < 0) {
407 if (errno != ENOENT) {
408 log_error("unlink(%s): %m", sub_path);
419 /* Restore original directory timestamps */
420 times[0] = ds->st_atim;
421 times[1] = ds->st_mtim;
423 if (futimens(dirfd(d), times) < 0)
424 log_error("utimensat(%s): %m", p);
430 static int item_set_perms(Item *i, const char *path) {
431 /* not using i->path directly because it may be a glob */
433 if (chmod(path, i->mode) < 0) {
434 log_error("chmod(%s) failed: %m", path);
438 if (i->uid_set || i->gid_set)
440 i->uid_set ? i->uid : (uid_t) -1,
441 i->gid_set ? i->gid : (gid_t) -1) < 0) {
443 log_error("chown(%s) failed: %m", path);
447 return label_fix(path, false, false);
450 static int write_one_file(Item *i, const char *path) {
454 flags = i->type == CREATE_FILE ? O_CREAT|O_APPEND :
455 i->type == TRUNCATE_FILE ? O_CREAT|O_TRUNC : 0;
458 label_context_set(path, S_IFREG);
459 fd = open(path, flags|O_NDELAY|O_CLOEXEC|O_WRONLY|O_NOCTTY|O_NOFOLLOW, i->mode);
461 label_context_clear();
466 if (i->type == WRITE_FILE && errno == ENOENT)
469 log_error("Failed to create file %s: %m", path);
476 _cleanup_free_ char *unescaped;
478 unescaped = cunescape(i->argument);
479 if (unescaped == NULL) {
480 close_nointr_nofail(fd);
484 l = strlen(unescaped);
485 n = write(fd, unescaped, l);
487 if (n < 0 || (size_t) n < l) {
488 log_error("Failed to write file %s: %s", path, n < 0 ? strerror(-n) : "Short write");
489 close_nointr_nofail(fd);
490 return n < 0 ? n : -EIO;
494 close_nointr_nofail(fd);
496 if (stat(path, &st) < 0) {
497 log_error("stat(%s) failed: %m", path);
501 if (!S_ISREG(st.st_mode)) {
502 log_error("%s is not a file.", path);
506 r = item_set_perms(i, path);
513 static int recursive_relabel_children(Item *i, const char *path) {
514 _cleanup_closedir_ DIR *d;
517 /* This returns the first error we run into, but nevertheless
522 return errno == ENOENT ? 0 : -errno;
526 union dirent_storage buf;
529 _cleanup_free_ char *entry_path = NULL;
531 r = readdir_r(d, &buf.de, &de);
541 if (streq(de->d_name, ".") || streq(de->d_name, ".."))
544 if (asprintf(&entry_path, "%s/%s", path, de->d_name) < 0) {
550 if (de->d_type == DT_UNKNOWN) {
553 if (lstat(entry_path, &st) < 0) {
554 if (ret == 0 && errno != ENOENT)
559 is_dir = S_ISDIR(st.st_mode);
562 is_dir = de->d_type == DT_DIR;
564 r = item_set_perms(i, entry_path);
566 if (ret == 0 && r != -ENOENT)
572 r = recursive_relabel_children(i, entry_path);
573 if (r < 0 && ret == 0)
581 static int recursive_relabel(Item *i, const char *path) {
585 r = item_set_perms(i, path);
589 if (lstat(path, &st) < 0)
592 if (S_ISDIR(st.st_mode))
593 r = recursive_relabel_children(i, path);
598 static int glob_item(Item *i, int (*action)(Item *, const char *)) {
600 _cleanup_globfree_ glob_t g = {};
604 k = glob(i->path, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
606 if (k != GLOB_NOMATCH) {
610 log_error("glob(%s) failed: %m", i->path);
614 STRV_FOREACH(fn, g.gl_pathv) {
623 static int create_item(Item *i) {
632 case IGNORE_DIRECTORY_PATH:
634 case RECURSIVE_REMOVE_PATH:
639 r = write_one_file(i, i->path);
644 r = glob_item(i, write_one_file);
650 case TRUNCATE_DIRECTORY:
651 case CREATE_DIRECTORY:
653 RUN_WITH_UMASK(0000) {
654 mkdir_parents_label(i->path, 0755);
655 r = mkdir(i->path, i->mode);
658 if (r < 0 && errno != EEXIST) {
659 log_error("Failed to create directory %s: %m", i->path);
663 if (stat(i->path, &st) < 0) {
664 log_error("stat(%s) failed: %m", i->path);
668 if (!S_ISDIR(st.st_mode)) {
669 log_error("%s is not a directory.", i->path);
673 r = item_set_perms(i, i->path);
681 RUN_WITH_UMASK(0000) {
682 r = mkfifo(i->path, i->mode);
685 if (r < 0 && errno != EEXIST) {
686 log_error("Failed to create fifo %s: %m", i->path);
690 if (stat(i->path, &st) < 0) {
691 log_error("stat(%s) failed: %m", i->path);
695 if (!S_ISFIFO(st.st_mode)) {
696 log_error("%s is not a fifo.", i->path);
700 r = item_set_perms(i, i->path);
706 case CREATE_SYMLINK: {
709 label_context_set(i->path, S_IFLNK);
710 r = symlink(i->argument, i->path);
712 label_context_clear();
715 if (r < 0 && errno != EEXIST) {
716 log_error("symlink(%s, %s) failed: %m", i->argument, i->path);
720 r = readlink_malloc(i->path, &x);
722 log_error("readlink(%s) failed: %s", i->path, strerror(-r));
726 if (!streq(i->argument, x)) {
728 log_error("%s is not the right symlinks.", i->path);
736 case CREATE_BLOCK_DEVICE:
737 case CREATE_CHAR_DEVICE: {
740 if (have_effective_cap(CAP_MKNOD) == 0) {
741 /* In a container we lack CAP_MKNOD. We
742 shouldn't attempt to create the device node in
743 that case to avoid noise, and we don't support
744 virtualized devices in containers anyway. */
746 log_debug("We lack CAP_MKNOD, skipping creation of device node %s.", i->path);
750 file_type = (i->type == CREATE_BLOCK_DEVICE ? S_IFBLK : S_IFCHR);
752 RUN_WITH_UMASK(0000) {
753 label_context_set(i->path, file_type);
754 r = mknod(i->path, i->mode | file_type, i->major_minor);
756 label_context_clear();
760 if (r < 0 && errno != EEXIST) {
761 log_error("Failed to create device node %s: %m", i->path);
765 if (stat(i->path, &st) < 0) {
766 log_error("stat(%s) failed: %m", i->path);
770 if ((st.st_mode & S_IFMT) != file_type) {
771 log_error("%s is not a device node.", i->path);
775 r = item_set_perms(i, i->path);
784 r = glob_item(i, item_set_perms);
789 case RECURSIVE_RELABEL_PATH:
791 r = glob_item(i, recursive_relabel);
796 log_debug("%s created successfully.", i->path);
801 static int remove_item_instance(Item *i, const char *instance) {
810 case CREATE_DIRECTORY:
813 case CREATE_BLOCK_DEVICE:
814 case CREATE_CHAR_DEVICE:
816 case IGNORE_DIRECTORY_PATH:
818 case RECURSIVE_RELABEL_PATH:
823 if (remove(instance) < 0 && errno != ENOENT) {
824 log_error("remove(%s): %m", instance);
830 case TRUNCATE_DIRECTORY:
831 case RECURSIVE_REMOVE_PATH:
832 /* FIXME: we probably should use dir_cleanup() here
833 * instead of rm_rf() so that 'x' is honoured. */
834 r = rm_rf_dangerous(instance, false, i->type == RECURSIVE_REMOVE_PATH, false);
835 if (r < 0 && r != -ENOENT) {
836 log_error("rm_rf(%s): %s", instance, strerror(-r));
846 static int remove_item(Item *i) {
855 case CREATE_DIRECTORY:
858 case CREATE_CHAR_DEVICE:
859 case CREATE_BLOCK_DEVICE:
861 case IGNORE_DIRECTORY_PATH:
863 case RECURSIVE_RELABEL_PATH:
868 case TRUNCATE_DIRECTORY:
869 case RECURSIVE_REMOVE_PATH:
870 r = glob_item(i, remove_item_instance);
877 static int clean_item_instance(Item *i, const char* instance) {
878 _cleanup_closedir_ DIR *d = NULL;
889 n = now(CLOCK_REALTIME);
895 d = opendir(instance);
897 if (errno == ENOENT || errno == ENOTDIR)
900 log_error("Failed to open directory %s: %m", i->path);
904 if (fstat(dirfd(d), &s) < 0) {
905 log_error("stat(%s) failed: %m", i->path);
909 if (!S_ISDIR(s.st_mode)) {
910 log_error("%s is not a directory.", i->path);
914 if (fstatat(dirfd(d), "..", &ps, AT_SYMLINK_NOFOLLOW) != 0) {
915 log_error("stat(%s/..) failed: %m", i->path);
919 mountpoint = s.st_dev != ps.st_dev ||
920 (s.st_dev == ps.st_dev && s.st_ino == ps.st_ino);
922 r = dir_cleanup(i, instance, d, &s, cutoff, s.st_dev, mountpoint,
923 MAX_DEPTH, i->keep_first_level);
927 static int clean_item(Item *i) {
933 case CREATE_DIRECTORY:
934 case TRUNCATE_DIRECTORY:
936 clean_item_instance(i, i->path);
938 case IGNORE_DIRECTORY_PATH:
939 r = glob_item(i, clean_item_instance);
948 static int process_item(Item *i) {
953 r = arg_create ? create_item(i) : 0;
954 q = arg_remove ? remove_item(i) : 0;
955 p = arg_clean ? clean_item(i) : 0;
966 static void item_free(Item *i) {
974 static bool item_equal(Item *a, Item *b) {
978 if (!streq_ptr(a->path, b->path))
981 if (a->type != b->type)
984 if (a->uid_set != b->uid_set ||
985 (a->uid_set && a->uid != b->uid))
988 if (a->gid_set != b->gid_set ||
989 (a->gid_set && a->gid != b->gid))
992 if (a->mode_set != b->mode_set ||
993 (a->mode_set && a->mode != b->mode))
996 if (a->age_set != b->age_set ||
997 (a->age_set && a->age != b->age))
1000 if ((a->type == CREATE_FILE ||
1001 a->type == TRUNCATE_FILE ||
1002 a->type == WRITE_FILE ||
1003 a->type == CREATE_SYMLINK) &&
1004 !streq_ptr(a->argument, b->argument))
1007 if ((a->type == CREATE_CHAR_DEVICE ||
1008 a->type == CREATE_BLOCK_DEVICE) &&
1009 a->major_minor != b->major_minor)
1015 static int parse_line(const char *fname, unsigned line, const char *buffer) {
1016 _cleanup_free_ Item *i = NULL;
1019 *mode = NULL, *user = NULL, *group = NULL, *age = NULL;
1033 "%c %ms %ms %ms %ms %ms %n",
1042 log_error("[%s:%u] Syntax error.", fname, line);
1047 n += strspn(buffer+n, WHITESPACE);
1048 if (buffer[n] != 0 && (buffer[n] != '-' || buffer[n+1] != 0)) {
1049 i->argument = unquote(buffer+n, "\"");
1059 case CREATE_DIRECTORY:
1060 case TRUNCATE_DIRECTORY:
1063 case IGNORE_DIRECTORY_PATH:
1065 case RECURSIVE_REMOVE_PATH:
1067 case RECURSIVE_RELABEL_PATH:
1070 case CREATE_SYMLINK:
1072 log_error("[%s:%u] Symlink file requires argument.", fname, line);
1079 log_error("[%s:%u] Write file requires argument.", fname, line);
1084 case CREATE_CHAR_DEVICE:
1085 case CREATE_BLOCK_DEVICE: {
1086 unsigned major, minor;
1089 log_error("[%s:%u] Device file requires argument.", fname, line);
1093 if (sscanf(i->argument, "%u:%u", &major, &minor) != 2) {
1094 log_error("[%s:%u] Can't parse device file major/minor '%s'.", fname, line, i->argument);
1098 i->major_minor = makedev(major, minor);
1103 log_error("[%s:%u] Unknown file type '%c'.", fname, line, type);
1109 if (!path_is_absolute(i->path)) {
1110 log_error("[%s:%u] Path '%s' not absolute.", fname, line, i->path);
1114 path_kill_slashes(i->path);
1116 if (arg_prefix && !path_startswith(i->path, arg_prefix))
1119 if (user && !streq(user, "-")) {
1120 const char *u = user;
1122 r = get_user_creds(&u, &i->uid, NULL, NULL, NULL);
1124 log_error("[%s:%u] Unknown user '%s'.", fname, line, user);
1131 if (group && !streq(group, "-")) {
1132 const char *g = group;
1134 r = get_group_creds(&g, &i->gid);
1136 log_error("[%s:%u] Unknown group '%s'.", fname, line, group);
1143 if (mode && !streq(mode, "-")) {
1146 if (sscanf(mode, "%o", &m) != 1) {
1147 log_error("[%s:%u] Invalid mode '%s'.", fname, line, mode);
1155 i->type == CREATE_DIRECTORY ||
1156 i->type == TRUNCATE_DIRECTORY ? 0755 : 0644;
1158 if (age && !streq(age, "-")) {
1159 const char *a = age;
1162 i->keep_first_level = true;
1166 if (parse_sec(a, &i->age) < 0) {
1167 log_error("[%s:%u] Invalid age '%s'.", fname, line, age);
1174 h = needs_glob(i->type) ? globs : items;
1176 existing = hashmap_get(h, i->path);
1179 /* Two identical items are fine */
1180 if (!item_equal(existing, i))
1181 log_warning("Two or more conflicting lines for %s configured, ignoring.", i->path);
1186 r = hashmap_put(h, i->path, i);
1188 log_error("Failed to insert item %s: %s", i->path, strerror(-r));
1192 i = NULL; /* avoid cleanup */
1197 static int help(void) {
1199 printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
1200 "Creates, deletes and cleans up volatile and temporary files and directories.\n\n"
1201 " -h --help Show this help\n"
1202 " --create Create marked files/directories\n"
1203 " --clean Clean up marked directories\n"
1204 " --remove Remove marked files/directories\n"
1205 " --prefix=PATH Only apply rules that apply to paths with the specified prefix\n",
1206 program_invocation_short_name);
1211 static int parse_argv(int argc, char *argv[]) {
1220 static const struct option options[] = {
1221 { "help", no_argument, NULL, 'h' },
1222 { "create", no_argument, NULL, ARG_CREATE },
1223 { "clean", no_argument, NULL, ARG_CLEAN },
1224 { "remove", no_argument, NULL, ARG_REMOVE },
1225 { "prefix", required_argument, NULL, ARG_PREFIX },
1226 { NULL, 0, NULL, 0 }
1234 while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
1255 arg_prefix = optarg;
1262 log_error("Unknown option code %c", c);
1267 if (!arg_clean && !arg_create && !arg_remove) {
1268 log_error("You need to specify at least one of --clean, --create or --remove.");
1275 static int read_config_file(const char *fn, bool ignore_enoent) {
1284 r = search_and_fopen_nulstr(fn, "re", conf_file_dirs, &f);
1286 if (ignore_enoent && r == -ENOENT)
1289 log_error("Failed to open '%s', ignoring: %s", fn, strerror(-r));
1293 log_debug("apply: %s\n", fn);
1295 char line[LINE_MAX], *l;
1298 if (!(fgets(line, sizeof(line), f)))
1304 if (*l == '#' || *l == 0)
1307 if ((k = parse_line(fn, v, l)) < 0)
1312 /* we have to determine age parameter for each entry of type X */
1313 HASHMAP_FOREACH(i, globs, iterator) {
1315 Item *j, *candidate_item = NULL;
1317 if (i->type != IGNORE_DIRECTORY_PATH)
1320 HASHMAP_FOREACH(j, items, iter) {
1321 if (j->type != CREATE_DIRECTORY && j->type != TRUNCATE_DIRECTORY)
1324 if (path_equal(j->path, i->path)) {
1329 if ((!candidate_item && path_startswith(i->path, j->path)) ||
1330 (candidate_item && path_startswith(j->path, candidate_item->path) && (fnmatch(i->path, j->path, FNM_PATHNAME | FNM_PERIOD) == 0)))
1334 if (candidate_item) {
1335 i->age = candidate_item->age;
1341 log_error("Failed to read from file %s: %m", fn);
1351 int main(int argc, char *argv[]) {
1356 r = parse_argv(argc, argv);
1358 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
1360 log_set_target(LOG_TARGET_AUTO);
1361 log_parse_environment();
1368 items = hashmap_new(string_hash_func, string_compare_func);
1369 globs = hashmap_new(string_hash_func, string_compare_func);
1371 if (!items || !globs) {
1378 if (optind < argc) {
1381 for (j = optind; j < argc; j++) {
1382 k = read_config_file(argv[j], false);
1383 if (k < 0 && r == 0)
1388 _cleanup_strv_free_ char **files = NULL;
1391 r = conf_files_list_nulstr(&files, ".conf", NULL, conf_file_dirs);
1393 log_error("Failed to enumerate tmpfiles.d files: %s", strerror(-r));
1397 STRV_FOREACH(f, files) {
1398 k = read_config_file(*f, true);
1399 if (k < 0 && r == 0)
1404 HASHMAP_FOREACH(i, globs, iterator)
1407 HASHMAP_FOREACH(i, items, iterator)
1411 while ((i = hashmap_steal_first(items)))
1414 while ((i = hashmap_steal_first(globs)))
1417 hashmap_free(items);
1418 hashmap_free(globs);
1420 set_free_free(unix_sockets);
1424 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;