summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Kerola <kerolasa@iki.fi>2015-02-20 19:42:34 +0000
committerKarel Zak <kzak@redhat.com>2015-03-12 10:15:25 +0100
commit32881ca22daba4bff0520d150ef64b8b55036e73 (patch)
treeb1dbacfb881c442aac3a29644bf805af270ece07
parent9efc3268cef117afdfc5b7cab03e4f91b384c3a3 (diff)
downloadutil-linux-32881ca22daba4bff0520d150ef64b8b55036e73.tar.gz
logger: fix -i argument parsing regression
With earlier logger it's possible to combine the option -i with other options, such as -s. But currently: $:~> logger -is logger: failed to parse id: 's' The changed behaviour breaks existing scripts like dhcpcd-run-hooks from dhcpcd. Broken-since: aab5b44405b9a6ada92e419e5a84cc0d1d4afee9 Reference: http://comments.gmane.org/gmane.linux.utilities.util-linux-ng/9683 Reported-by: Juergen Daubert <jue@jue.li> Reviewed-by: Benno Schulenberg <bensberg@justemail.net> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rw-r--r--misc-utils/logger.15
-rw-r--r--misc-utils/logger.c13
2 files changed, 13 insertions, 5 deletions
diff --git a/misc-utils/logger.1 b/misc-utils/logger.1
index a855cdf1d..994616e61 100644
--- a/misc-utils/logger.1
+++ b/misc-utils/logger.1
@@ -58,7 +58,10 @@ syslog port defined in /etc/services, which is often 514 .
Log the contents of the specified \fIfile\fR.
This option cannot be combined with a command-line message.
.TP
-.BR \-i , " \-\-id" [ = \fIid ]
+.B \-i
+Log the PID of the logger process with each line.
+.TP
+.BR "\-\-id" [ =\fIid ]
Log the PID of the logger process with each line. When the optional
argument \fIid\fR is specified, then it is used instead of the logger
command's PID. The use of \fB\-\-id=$$\fR
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 7abfcf122..1e7e2dc10 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -89,7 +89,8 @@ enum {
OPT_JOURNALD,
OPT_RFC3164,
OPT_RFC5424,
- OPT_SOCKET_ERRORS
+ OPT_SOCKET_ERRORS,
+ OPT_ID
};
struct logger_ctl {
@@ -552,7 +553,8 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
fputs(_("Enter messages into the system log.\n"), out);
fputs(USAGE_OPTIONS, out);
- fputs(_(" -i, --id[=<id>] log <id> (default is PID)\n"), out);
+ fputs(_(" -i log the logger command's PID\n"), out);
+ fputs(_(" --id[=<id>] log the given <id>, or otherwise the PID\n"), out);
fputs(_(" -f, --file <file> log the contents of this file\n"), out);
fputs(_(" -p, --priority <prio> mark given message with this priority\n"), out);
fputs(_(" --prio-prefix look for a prefix on every line read from stdin\n"), out);
@@ -610,7 +612,7 @@ int main(int argc, char **argv)
FILE *jfd = NULL;
#endif
static const struct option longopts[] = {
- { "id", optional_argument, 0, 'i' },
+ { "id", optional_argument, 0, OPT_ID },
{ "stderr", no_argument, 0, 's' },
{ "file", required_argument, 0, 'f' },
{ "priority", required_argument, 0, 'p' },
@@ -637,7 +639,7 @@ int main(int argc, char **argv)
textdomain(PACKAGE);
atexit(close_stdout);
- while ((ch = getopt_long(argc, argv, "f:i::p:st:u:dTn:P:Vh",
+ while ((ch = getopt_long(argc, argv, "f:ip:st:u:dTn:P:Vh",
longopts, NULL)) != -1) {
switch (ch) {
case 'f': /* file to log */
@@ -646,6 +648,9 @@ int main(int argc, char **argv)
stdout_reopened = 1;
break;
case 'i': /* log process id also */
+ ctl.pid = getpid();
+ break;
+ case OPT_ID:
if (optarg) {
const char *p = optarg;