]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: warn when --file and command line message are combined
authorSami Kerola <kerolasa@iki.fi>
Sun, 27 Jul 2014 17:01:09 +0000 (18:01 +0100)
committerSami Kerola <kerolasa@iki.fi>
Mon, 28 Jul 2014 20:15:18 +0000 (21:15 +0100)
When --file is combined with command line arguments the later has
silently been ignored.  This commit makes user to be aware the logger
will not use command line arguments when --file is specified.

Reported-by: "Daniel 'DaB.' Baur" <debian@daniel.baur4.info>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=467244
CC: Andreas Henriksson <andreas@fatal.se>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/logger.c

index afd93712a29d7875633b4a2c0aea04b3547d15f7..ac583fd1044a5b8a7af4f6d27b44135b9e34605f 100644 (file)
@@ -535,6 +535,7 @@ int main(int argc, char **argv)
                .rfc5424_host = 1,
        };
        int ch;
+       int stdout_reopened = 0;
 #ifdef HAVE_LIBSYSTEMD
        FILE *jfd = NULL;
 #endif
@@ -570,8 +571,8 @@ int main(int argc, char **argv)
                switch (ch) {
                case 'f':               /* file to log */
                        if (freopen(optarg, "r", stdin) == NULL)
-                               err(EXIT_FAILURE, _("file %s"),
-                                   optarg);
+                               err(EXIT_FAILURE, _("file %s"), optarg);
+                       stdout_reopened = 1;
                        break;
                case 'i':               /* log process id also */
                        ctl.logflags |= LOG_PID;
@@ -642,6 +643,8 @@ int main(int argc, char **argv)
        }
        argc -= optind;
        argv += optind;
+       if (stdout_reopened && argc)
+               warnx(_("--file <file> and <message> are mutually exclusive, message is ignored"));
 #ifdef HAVE_LIBSYSTEMD
        if (jfd) {
                int ret = journald_entry(jfd);