[systemd-commits] 2 commits - man/systemd-tmpfiles.xml src/tmpfiles

Kay Sievers kay at kemper.freedesktop.org
Sun Jun 10 10:23:14 PDT 2012


 man/systemd-tmpfiles.xml |   10 ++++++--
 src/tmpfiles/tmpfiles.c  |   54 ++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 53 insertions(+), 11 deletions(-)

New commits:
commit ca2e894bdbd06b43800b57074be0e499a3539b0d
Author: Kay Sievers <kay at vrfy.org>
Date:   Sun Jun 10 19:21:50 2012 +0200

    tmpfiles: print error if basename lookup fails; document it in manpage

diff --git a/man/systemd-tmpfiles.xml b/man/systemd-tmpfiles.xml
index 4ac7224..623b420 100644
--- a/man/systemd-tmpfiles.xml
+++ b/man/systemd-tmpfiles.xml
@@ -67,9 +67,13 @@
 
                 <para>If invoked with no arguments, it applies all
                 directives from all configuration files. If one or
-                more absolute file names are passed on the command
-                line only the directives in these files are
-                applied.</para>
+                more file names are passed on the command line, only
+                the directives in these files are applied. If only
+                the basename of a configuration file is specified,
+                all configuration directories as specified in <citerefentry>
+                        <refentrytitle>tmpfiles.d</refentrytitle>
+                        <manvolnum>5</manvolnum>
+                </citerefentry> are searched for a matching file.</para>
         </refsect1>
 
         <refsect1>
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index bec73ff..12ec0b2 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -1281,6 +1281,7 @@ static char *resolve_fragment(const char *fragment, const char **search_paths) {
                 free(resolved_path);
         }
 
+        errno = ENOENT;
         return NULL;
 }
 
@@ -1316,7 +1317,14 @@ int main(int argc, char *argv[]) {
                 int j;
 
                 for (j = optind; j < argc; j++) {
-                        char *fragment = resolve_fragment(argv[j], conf_file_dirs);
+                        char *fragment;
+
+                        fragment = resolve_fragment(argv[j], conf_file_dirs);
+                        if (!fragment) {
+                                log_error("Failed to find any: %s file: %m", argv[j]);
+                                r = EXIT_FAILURE;
+                                goto finish;
+                        }
                         if (read_config_file(fragment, false) < 0)
                                 r = EXIT_FAILURE;
                         free(fragment);

commit 9125670f9a3dc34adf16b87635b460b2e4099b78
Author: Dave Reisner <dreisner at archlinux.org>
Date:   Fri Jun 8 22:31:19 2012 -0400

    tmpfiles: allow to specify basename only: systemd-tmpfiles <program.conf>
    
    Allow passing of basename only, instead of the absolute path; letting
    systemd-tmpfiles perform a path lookup for the proper fragment path in
    the config directories.
    
    This allows distributions to call: systemd-tmpfiles <program.conf> on
    upgrade of a package, with respecting the possibly overriden (or even
    masked) tmpfile.

diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index aebc4bb..bec73ff 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -100,6 +100,14 @@ static bool arg_remove = false;
 
 static const char *arg_prefix = NULL;
 
+static const char *conf_file_dirs[] = {
+        "/etc/tmpfiles.d",
+        "/run/tmpfiles.d",
+        "/usr/local/lib/tmpfiles.d",
+        "/usr/lib/tmpfiles.d",
+        NULL
+};
+
 #define MAX_DEPTH 256
 
 static bool needs_glob(ItemType t) {
@@ -1253,6 +1261,29 @@ static int read_config_file(const char *fn, bool ignore_enoent) {
         return r;
 }
 
+static char *resolve_fragment(const char *fragment, const char **search_paths) {
+        const char **p;
+        char *resolved_path;
+
+        if (is_path(fragment))
+                return strdup(fragment);
+
+        STRV_FOREACH(p, search_paths) {
+                resolved_path = join(*p, "/", fragment, NULL);
+                if (resolved_path == NULL) {
+                        log_error("Out of memory");
+                        return NULL;
+                }
+
+                if (access(resolved_path, F_OK) == 0)
+                        return resolved_path;
+
+                free(resolved_path);
+        }
+
+        return NULL;
+}
+
 int main(int argc, char *argv[]) {
         int r;
         Item *i;
@@ -1284,19 +1315,18 @@ int main(int argc, char *argv[]) {
         if (optind < argc) {
                 int j;
 
-                for (j = optind; j < argc; j++)
-                        if (read_config_file(argv[j], false) < 0)
+                for (j = optind; j < argc; j++) {
+                        char *fragment = resolve_fragment(argv[j], conf_file_dirs);
+                        if (read_config_file(fragment, false) < 0)
                                 r = EXIT_FAILURE;
+                        free(fragment);
+                }
 
         } else {
                 char **files, **f;
 
-                r = conf_files_list(&files, ".conf",
-                                    "/etc/tmpfiles.d",
-                                    "/run/tmpfiles.d",
-                                    "/usr/local/lib/tmpfiles.d",
-                                    "/usr/lib/tmpfiles.d",
-                                    NULL);
+                r = conf_files_list_strv(&files, ".conf",
+                                    (const char **)conf_file_dirs);
                 if (r < 0) {
                         log_error("Failed to enumerate tmpfiles.d files: %s", strerror(-r));
                         r = EXIT_FAILURE;



More information about the systemd-commits mailing list