chiark / gitweb /
tmpfiles: create leading directories for d/D instructions
[elogind.git] / src / tmpfiles.c
index 01668da87e142c8a3711424e1c05e47c55080425..70a9ebd83111e609252c8c410a4cd4535d31f006 100644 (file)
@@ -47,7 +47,7 @@
 
 /* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
  * them in the file system. This is intended to be used to create
- * properly owned directories beneath /tmp, /var/tmp, /var/run and
+ * properly owned directories beneath /tmp, /var/tmp, /run and
  * /var/lock which are volatile and hence need to be recreated on
  * bootup. */
 
@@ -147,6 +147,8 @@ static void load_unix_sockets(void) {
                 if (!(s = strdup(p)))
                         goto fail;
 
+                path_kill_slashes(s);
+
                 if ((k = set_put(unix_sockets, s)) < 0) {
                         free(s);
 
@@ -301,6 +303,10 @@ static int dir_cleanup(
                         if (S_ISSOCK(s.st_mode) && unix_socket_alive(sub_path))
                                 continue;
 
+                        /* Ignore device nodes */
+                        if (S_ISCHR(s.st_mode) || S_ISBLK(s.st_mode))
+                                continue;
+
                         age = MAX3(timespec_load(&s.st_mtim),
                                    timespec_load(&s.st_atim),
                                    timespec_load(&s.st_ctim));
@@ -460,6 +466,7 @@ static int create_item(Item *i) {
         case CREATE_DIRECTORY:
 
                 u = umask(0);
+                mkdir_parents(i->path, 0755);
                 r = mkdir(i->path, i->mode);
                 umask(u);
 
@@ -501,7 +508,7 @@ static int create_item(Item *i) {
                 break;
         }
 
-        if ((r = label_fix(i->path)) < 0)
+        if ((r = label_fix(i->path, false)) < 0)
                 goto finish;
 
         log_debug("%s created successfully.", i->path);
@@ -769,7 +776,8 @@ static int scandir_filter(const struct dirent *d) {
                 return 0;
 
         if (d->d_type != DT_REG &&
-            d->d_type != DT_LNK)
+            d->d_type != DT_LNK &&
+            d->d_type != DT_UNKNOWN)
                 return 0;
 
         return endswith(d->d_name, ".conf");
@@ -846,7 +854,7 @@ static int parse_argv(int argc, char *argv[]) {
         }
 
         if (!arg_clean && !arg_create && !arg_remove) {
-                log_error("You need to specify at leat one of --clean, --create or --remove.");
+                log_error("You need to specify at least one of --clean, --create or --remove.");
                 return -EINVAL;
         }