]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tmpfiles: interpret "-" as stdin
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 20 Apr 2016 02:34:04 +0000 (22:34 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 20 Apr 2016 13:00:39 +0000 (09:00 -0400)
man/systemd-tmpfiles.xml
src/tmpfiles/tmpfiles.c

index 447a7eaa17746b765abc1802b31ac62cca623b8f..c1aab5155178ab81d8e1b29122c2893d0086c6c9 100644 (file)
     <citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
     </para>
 
-    <para>If invoked with no arguments, it applies all directives from
-    all configuration files. If one or more absolute filenames 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
+    <para>If invoked with no arguments, it applies all directives from all configuration
+    files. If one or more absolute filenames are passed on the command line, only the
+    directives in these files are applied.  If <literal>-</literal> is specified instead
+    of a filename, directives are read from standard input.  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>
index efd264b34dbc26307f0cbed95bf7edeb4a5e9ce2..85b876d11ba80c9148d1345dc16e0562b91d3c61 100644 (file)
@@ -2198,7 +2198,8 @@ static int parse_argv(int argc, char *argv[]) {
 }
 
 static int read_config_file(const char *fn, bool ignore_enoent) {
-        _cleanup_fclose_ FILE *f = NULL;
+        _cleanup_fclose_ FILE *_f = NULL;
+        FILE *f;
         char line[LINE_MAX];
         Iterator iterator;
         unsigned v = 0;
@@ -2207,16 +2208,23 @@ static int read_config_file(const char *fn, bool ignore_enoent) {
 
         assert(fn);
 
-        r = search_and_fopen_nulstr(fn, "re", arg_root, conf_file_dirs, &f);
-        if (r < 0) {
-                if (ignore_enoent && r == -ENOENT) {
-                        log_debug_errno(r, "Failed to open \"%s\": %m", fn);
-                        return 0;
-                }
+        if (streq(fn, "-")) {
+                log_debug("Reading config from stdin.");
+                fn = "<stdin>";
+                f = stdin;
+        } else {
+                r = search_and_fopen_nulstr(fn, "re", arg_root, conf_file_dirs, &_f);
+                if (r < 0) {
+                        if (ignore_enoent && r == -ENOENT) {
+                                log_debug_errno(r, "Failed to open \"%s\", ignoring: %m", fn);
+                                return 0;
+                        }
 
-                return log_error_errno(r, "Failed to open '%s', ignoring: %m", fn);
+                        return log_error_errno(r, "Failed to open '%s': %m", fn);
+                }
+                log_debug("Reading config file \"%s\".", fn);
+                f = _f;
         }
-        log_debug("Reading config file \"%s\".", fn);
 
         FOREACH_LINE(line, f, break) {
                 char *l;