chiark / gitweb /
tmpfiles: get rid of "m" lines, make them redundant by "z"
authorLennart Poettering <lennart@poettering.net>
Tue, 10 Jun 2014 21:42:16 +0000 (23:42 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 10 Jun 2014 21:42:16 +0000 (23:42 +0200)
"m" so far has been a non-globbing version of "z". Since this makes it
quite redundant, let's get rid of it. Remove "m" from the man pages,
beef up "z" docs instead, and make "m" nothing more than a compatibility
alias for "z".

man/tmpfiles.d.xml
src/journal/journal-remote.c
src/shared/mkdir.c
src/shared/mkdir.h
src/tmpfiles/tmpfiles.c
tmpfiles.d/systemd.conf

index 20ed803a527653565f0c15dfdc02641d4f76c5df..76cae39aae4345583ccbd3aef69e529eab603a81 100644 (file)
@@ -188,17 +188,6 @@ L    /tmp/foobar -    -    -    -   /dev/null</programlisting>
                                         <listitem><para>Recursively copy a file or directory, if the destination files or directories don't exist yet.</para></listitem>
                                 </varlistentry>
 
                                         <listitem><para>Recursively copy a file or directory, if the destination files or directories don't exist yet.</para></listitem>
                                 </varlistentry>
 
-                                <varlistentry>
-                                        <term><varname>m</varname></term>
-                                        <listitem><para>If the
-                                        specified file path exists,
-                                        adjust its access mode, group
-                                        and user to the specified
-                                        values and reset the SELinux
-                                        security context. If it does not exist, do
-                                        nothing.</para></listitem>
-                                </varlistentry>
-
                                 <varlistentry>
                                         <term><varname>x</varname></term>
                                         <listitem><para>Ignore a path
                                 <varlistentry>
                                         <term><varname>x</varname></term>
                                         <listitem><para>Ignore a path
@@ -262,27 +251,29 @@ L    /tmp/foobar -    -    -    -   /dev/null</programlisting>
 
                                 <varlistentry>
                                         <term><varname>z</varname></term>
 
                                 <varlistentry>
                                         <term><varname>z</varname></term>
-                                        <listitem><para>Restore
-                                        SELinux security context
-                                        and set ownership and access
-                                        mode of a file or directory if
-                                        it exists.  Lines of this type
-                                        accept shell-style globs in
-                                        place of normal path names.
+                                        <listitem><para>Adjust the
+                                        access mode, group and user,
+                                        and restore the SELinux security
+                                        context of a file or directory,
+                                        if it exists. Lines of this
+                                        type accept shell-style globs
+                                        in place of normal path names.
                                         </para></listitem>
                                 </varlistentry>
 
                                 <varlistentry>
                                         <term><varname>Z</varname></term>
                                         <listitem><para>Recursively
                                         </para></listitem>
                                 </varlistentry>
 
                                 <varlistentry>
                                         <term><varname>Z</varname></term>
                                         <listitem><para>Recursively
-                                        restore SELinux security
-                                        context and set
-                                        ownership and access mode of a
-                                        path and all its
-                                        subdirectories (if it is a
-                                        directory). Lines of this type
-                                        accept shell-style globs in
-                                        place of normal path
+                                        set the access mode, group and
+                                        user, and restore the SELinux
+                                        security context of a file or
+                                        directory if it exists, as
+                                        well as of its subdirectories
+                                        and the files contained
+                                        therein (if applicable). Lines
+                                        of this type accept
+                                        shell-style globs in place of
+                                        normal path
                                         names.</para></listitem>
                                 </varlistentry>
                         </variablelist>
                                         names.</para></listitem>
                                 </varlistentry>
                         </variablelist>
index 9adad7aabc579d5fc1e283e2537d717e5b4103d8..915f234ab2d110394d0646124c54ff0af799578e 100644 (file)
@@ -185,7 +185,7 @@ static int open_output(Writer *s, const char* url) {
                 if (r < 0)
                         return log_oom();
         } else {
                 if (r < 0)
                         return log_oom();
         } else {
-                r = is_dir(arg_output);
+                r = is_dir(arg_output, true);
                 if (r > 0) {
                         r = asprintf(&output,
                                      "%s/remote-%s.journal", arg_output, name);
                 if (r > 0) {
                         r = asprintf(&output,
                                      "%s/remote-%s.journal", arg_output, name);
index ba083d6d673a58e2b1cb422651026bd6735f176f..f941efb401809333240dbef8e0eeefdbc3919cee 100644 (file)
@@ -58,11 +58,16 @@ int mkdir_safe(const char *path, mode_t mode, uid_t uid, gid_t gid) {
         return mkdir_safe_internal(path, mode, uid, gid, mkdir);
 }
 
         return mkdir_safe_internal(path, mode, uid, gid, mkdir);
 }
 
-int is_dir(const char* path) {
+int is_dir(const char* path, bool follow) {
         struct stat st;
 
         struct stat st;
 
-        if (stat(path, &st) < 0)
-                return -errno;
+        if (follow) {
+                if (stat(path, &st) < 0)
+                        return -errno;
+        } else {
+                if (lstat(path, &st) < 0)
+                        return -errno;
+        }
 
         return S_ISDIR(st.st_mode);
 }
 
         return S_ISDIR(st.st_mode);
 }
@@ -85,7 +90,7 @@ int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, mk
                 return 0;
 
         p = strndupa(path, e - path);
                 return 0;
 
         p = strndupa(path, e - path);
-        r = is_dir(p);
+        r = is_dir(p, true);
         if (r > 0)
                 return 0;
         if (r == 0)
         if (r > 0)
                 return 0;
         if (r == 0)
@@ -130,7 +135,7 @@ int mkdir_p_internal(const char *prefix, const char *path, mode_t mode, mkdir_fu
                 return r;
 
         r = _mkdir(path, mode);
                 return r;
 
         r = _mkdir(path, mode);
-        if (r < 0 && (errno != EEXIST || is_dir(path) <= 0))
+        if (r < 0 && (errno != EEXIST || is_dir(path, true) <= 0))
                 return -errno;
 
         return 0;
                 return -errno;
 
         return 0;
index f1bf4c0a68a837ee4684bb956f2c890e12378558..d15ede60646b6269988d3431a5ec0efd4c333fed 100644 (file)
@@ -41,4 +41,4 @@ typedef int (*mkdir_func_t)(const char *pathname, mode_t mode);
 int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkdir_func_t _mkdir);
 int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, mkdir_func_t _mkdir);
 int mkdir_p_internal(const char *prefix, const char *path, mode_t mode, mkdir_func_t _mkdir);
 int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkdir_func_t _mkdir);
 int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, mkdir_func_t _mkdir);
 int mkdir_p_internal(const char *prefix, const char *path, mode_t mode, mkdir_func_t _mkdir);
-int is_dir(const char *path);
+int is_dir(const char *path, bool is_dir);
index 6745c23a1527ae0b0e3947c012bd919741605288..89f6c6bd15696037e3004d2f2a6a886a93b45002 100644 (file)
@@ -71,7 +71,6 @@ typedef enum ItemType {
         CREATE_CHAR_DEVICE = 'c',
         CREATE_BLOCK_DEVICE = 'b',
         COPY_FILES = 'C',
         CREATE_CHAR_DEVICE = 'c',
         CREATE_BLOCK_DEVICE = 'b',
         COPY_FILES = 'C',
-        ADJUST_MODE = 'm',
 
         /* These ones take globs */
         WRITE_FILE = 'w',
 
         /* These ones take globs */
         WRITE_FILE = 'w',
@@ -79,8 +78,9 @@ typedef enum ItemType {
         IGNORE_DIRECTORY_PATH = 'X',
         REMOVE_PATH = 'r',
         RECURSIVE_REMOVE_PATH = 'R',
         IGNORE_DIRECTORY_PATH = 'X',
         REMOVE_PATH = 'r',
         RECURSIVE_REMOVE_PATH = 'R',
+        ADJUST_MODE = 'm', /* legacy, 'z' is identical to this */
         RELABEL_PATH = 'z',
         RELABEL_PATH = 'z',
-        RECURSIVE_RELABEL_PATH = 'Z'
+        RECURSIVE_RELABEL_PATH = 'Z',
 } ItemType;
 
 typedef struct Item {
 } ItemType;
 
 typedef struct Item {
@@ -134,6 +134,7 @@ static bool needs_glob(ItemType t) {
                       IGNORE_DIRECTORY_PATH,
                       REMOVE_PATH,
                       RECURSIVE_REMOVE_PATH,
                       IGNORE_DIRECTORY_PATH,
                       REMOVE_PATH,
                       RECURSIVE_REMOVE_PATH,
+                      ADJUST_MODE,
                       RELABEL_PATH,
                       RECURSIVE_RELABEL_PATH);
 }
                       RELABEL_PATH,
                       RECURSIVE_RELABEL_PATH);
 }
@@ -543,109 +544,90 @@ static int write_one_file(Item *i, const char *path) {
         return 0;
 }
 
         return 0;
 }
 
-static int recursive_relabel_children(Item *i, const char *path) {
+static int item_set_perms_children(Item *i, const char *path) {
         _cleanup_closedir_ DIR *d;
         _cleanup_closedir_ DIR *d;
-        int ret = 0;
+        int r = 0;
+
+        assert(i);
+        assert(path);
 
         /* This returns the first error we run into, but nevertheless
          * tries to go on */
 
         d = opendir(path);
         if (!d)
 
         /* This returns the first error we run into, but nevertheless
          * tries to go on */
 
         d = opendir(path);
         if (!d)
-                return errno == ENOENT ? 0 : -errno;
+                return errno == ENOENT || errno == ENOTDIR ? 0 : -errno;
 
         for (;;) {
 
         for (;;) {
+                _cleanup_free_ char *p = NULL;
                 struct dirent *de;
                 struct dirent *de;
-                bool dir;
-                int r;
-                _cleanup_free_ char *entry_path = NULL;
+                int q;
 
                 errno = 0;
                 de = readdir(d);
 
                 errno = 0;
                 de = readdir(d);
-                if (!de && errno != 0) {
-                        if (ret == 0)
-                                ret = -errno;
-                        break;
-                }
+                if (!de) {
+                        if (errno != 0 && r == 0)
+                                r = -errno;
 
 
-                if (!de)
                         break;
                         break;
+                }
 
                 if (streq(de->d_name, ".") || streq(de->d_name, ".."))
                         continue;
 
 
                 if (streq(de->d_name, ".") || streq(de->d_name, ".."))
                         continue;
 
-                if (asprintf(&entry_path, "%s/%s", path, de->d_name) < 0) {
-                        if (ret == 0)
-                                ret = -ENOMEM;
-                        continue;
-                }
-
-                if (de->d_type == DT_UNKNOWN) {
-                        r = is_dir(entry_path);
-                        if (r < 0) {
-                                if (ret == 0 && errno != ENOENT)
-                                        ret = -errno;
-                                continue;
-                        }
-
-                        dir = r;
-
-                } else
-                        dir = de->d_type == DT_DIR;
+                p = strjoin(path, "/", de->d_name, NULL);
+                if (!p)
+                        return -ENOMEM;
 
 
-                r = item_set_perms(i, entry_path);
-                if (r < 0) {
-                        if (ret == 0 && r != -ENOENT)
-                                ret = r;
-                        continue;
-                }
+                q = item_set_perms(i, p);
+                if (q < 0 && q != -ENOENT && r == 0)
+                        r = q;
 
 
-                if (dir) {
-                        r = recursive_relabel_children(i, entry_path);
-                        if (r < 0 && ret == 0)
-                                ret = r;
+                if (IN_SET(de->d_type, DT_UNKNOWN, DT_DIR)) {
+                        q = item_set_perms_children(i, p);
+                        if (q < 0 && r == 0)
+                                r = q;
                 }
         }
 
                 }
         }
 
-        return ret;
+        return r;
 }
 
 }
 
-static int recursive_relabel(Item *i, const char *path) {
-        int r;
-        struct stat st;
+static int item_set_perms_recursive(Item *i, const char *path) {
+        int r, q;
+
+        assert(i);
+        assert(path);
 
         r = item_set_perms(i, path);
         if (r < 0)
                 return r;
 
 
         r = item_set_perms(i, path);
         if (r < 0)
                 return r;
 
-        if (lstat(path, &st) < 0)
-                return -errno;
-
-        if (S_ISDIR(st.st_mode))
-                r = recursive_relabel_children(i, path);
+        q = item_set_perms_children(i, path);
+        if (q < 0 && r == 0)
+                r = q;
 
         return r;
 }
 
 static int glob_item(Item *i, int (*action)(Item *, const char *)) {
 
         return r;
 }
 
 static int glob_item(Item *i, int (*action)(Item *, const char *)) {
-        int r = 0, k;
         _cleanup_globfree_ glob_t g = {};
         _cleanup_globfree_ glob_t g = {};
+        int r = 0, k;
         char **fn;
 
         errno = 0;
         k = glob(i->path, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
         char **fn;
 
         errno = 0;
         k = glob(i->path, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
-        if (k != 0)
-                if (k != GLOB_NOMATCH) {
-                        if (errno > 0)
-                                errno = EIO;
+        if (k != 0 && k != GLOB_NOMATCH) {
+                if (errno == 0)
+                        errno = EIO;
 
 
-                        log_error("glob(%s) failed: %m", i->path);
-                        return -errno;
-                }
+                log_error("glob(%s) failed: %m", i->path);
+                return -errno;
+        }
 
         STRV_FOREACH(fn, g.gl_pathv) {
                 k = action(i, *fn);
 
         STRV_FOREACH(fn, g.gl_pathv) {
                 k = action(i, *fn);
-                if (k < 0)
+                if (k < 0 && r == 0)
                         r = k;
         }
 
                         r = k;
         }
 
@@ -693,13 +675,6 @@ static int create_item(Item *i) {
 
                 break;
 
 
                 break;
 
-        case ADJUST_MODE:
-                r = item_set_perms_full(i, i->path, true);
-                if (r < 0)
-                        return r;
-
-                break;
-
         case TRUNCATE_DIRECTORY:
         case CREATE_DIRECTORY:
 
         case TRUNCATE_DIRECTORY:
         case CREATE_DIRECTORY:
 
@@ -826,6 +801,7 @@ static int create_item(Item *i) {
                 break;
         }
 
                 break;
         }
 
+        case ADJUST_MODE:
         case RELABEL_PATH:
 
                 r = glob_item(i, item_set_perms);
         case RELABEL_PATH:
 
                 r = glob_item(i, item_set_perms);
@@ -835,9 +811,11 @@ static int create_item(Item *i) {
 
         case RECURSIVE_RELABEL_PATH:
 
 
         case RECURSIVE_RELABEL_PATH:
 
-                r = glob_item(i, recursive_relabel);
+                r = glob_item(i, item_set_perms_recursive);
                 if (r < 0)
                         return r;
                 if (r < 0)
                         return r;
+
+                break;
         }
 
         log_debug("%s created successfully.", i->path);
         }
 
         log_debug("%s created successfully.", i->path);
@@ -861,11 +839,11 @@ static int remove_item_instance(Item *i, const char *instance) {
         case CREATE_CHAR_DEVICE:
         case IGNORE_PATH:
         case IGNORE_DIRECTORY_PATH:
         case CREATE_CHAR_DEVICE:
         case IGNORE_PATH:
         case IGNORE_DIRECTORY_PATH:
+        case ADJUST_MODE:
         case RELABEL_PATH:
         case RECURSIVE_RELABEL_PATH:
         case WRITE_FILE:
         case COPY_FILES:
         case RELABEL_PATH:
         case RECURSIVE_RELABEL_PATH:
         case WRITE_FILE:
         case COPY_FILES:
-        case ADJUST_MODE:
                 break;
 
         case REMOVE_PATH:
                 break;
 
         case REMOVE_PATH:
@@ -908,11 +886,11 @@ static int remove_item(Item *i) {
         case CREATE_BLOCK_DEVICE:
         case IGNORE_PATH:
         case IGNORE_DIRECTORY_PATH:
         case CREATE_BLOCK_DEVICE:
         case IGNORE_PATH:
         case IGNORE_DIRECTORY_PATH:
+        case ADJUST_MODE:
         case RELABEL_PATH:
         case RECURSIVE_RELABEL_PATH:
         case WRITE_FILE:
         case COPY_FILES:
         case RELABEL_PATH:
         case RECURSIVE_RELABEL_PATH:
         case WRITE_FILE:
         case COPY_FILES:
-        case ADJUST_MODE:
                 break;
 
         case REMOVE_PATH:
                 break;
 
         case REMOVE_PATH:
@@ -1158,9 +1136,9 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
         case IGNORE_DIRECTORY_PATH:
         case REMOVE_PATH:
         case RECURSIVE_REMOVE_PATH:
         case IGNORE_DIRECTORY_PATH:
         case REMOVE_PATH:
         case RECURSIVE_REMOVE_PATH:
+        case ADJUST_MODE:
         case RELABEL_PATH:
         case RECURSIVE_RELABEL_PATH:
         case RELABEL_PATH:
         case RECURSIVE_RELABEL_PATH:
-        case ADJUST_MODE:
                 break;
 
         case CREATE_SYMLINK:
                 break;
 
         case CREATE_SYMLINK:
index c5910f8cfe2a271669d9a001a1f1a03a496186d6..85dc35699da57305bba119fceeae71b654a7b9a2 100644 (file)
@@ -25,7 +25,7 @@ d /run/systemd/netif 0755 systemd-network systemd-network -
 d /run/systemd/netif/links 0755 systemd-network systemd-network -
 d /run/systemd/netif/leases 0755 systemd-network systemd-network -
 
 d /run/systemd/netif/links 0755 systemd-network systemd-network -
 d /run/systemd/netif/leases 0755 systemd-network systemd-network -
 
-m /var/log/journal 2755 root systemd-journal - -
+z /var/log/journal 2755 root systemd-journal - -
 Z /var/log/journal/%m 2755 root systemd-journal - -
 Z /var/log/journal/%m 2755 root systemd-journal - -
-m /run/log/journal 2755 root systemd-journal - -
+z /run/log/journal 2755 root systemd-journal - -
 Z /run/log/journal/%m 2755 root systemd-journal - -
 Z /run/log/journal/%m 2755 root systemd-journal - -