\fB\-h\fR, \fB\-\-help\fR
Display help text and exit.
.TP
-\fB\-i\fR, \fB\-\-id\fR=[\fBppid\fR|\fBpid\fR]
+\fB\-i\fR, \fB\-\-id\fR[=\fBid\fR]
Log the PID of the logger process with each line. When optional
argument
-.B ppid
-is specified PPID is used instead of logger command PID. Use of
-.B ppid
-is recommended in scripts that send several messages.
+.B id
+is specified then it is used instead of logger command PID. Use of
+.B --id=$$
+(PPID) is recommended in scripts that send several messages.
.TP
\fB\-n\fR, \fB\-\-server\fR \fIserver\fR
Write to the specified remote syslog
struct logger_ctl {
int fd;
int pri;
+ pid_t pid; /* zero when unwanted */
char *tag;
char *unix_socket;
char *server;
void (*syslogfp)(const struct logger_ctl *ctl, const char *msg);
unsigned int
prio_prefix:1, /* read priority from intput */
- pid:1, /* print PID, or PPID if it is enabled as well*/
- ppid:1, /* include PPID instead of PID */
stderr_printout:1, /* output message to stderr */
rfc5424_time:1, /* include time stamp */
rfc5424_tq:1, /* include time quality markup */
return cp;
}
-static pid_t get_process_id(const struct logger_ctl *ctl)
-{
- pid_t id = 0;
-
- if (ctl->pid)
- id = ctl->ppid ? getppid() : getpid();
- return id;
-}
-
static void syslog_rfc3164(const struct logger_ctl *ctl, const char *msg)
{
char *buf, pid[30], *cp, *tp, *hostname, *dot;
time_t now;
- pid_t process;
int len;
*pid = '\0';
if (ctl->fd < 0)
return;
- if ((process = get_process_id(ctl)))
- snprintf(pid, sizeof(pid), "[%d]", process);
+ if (ctl->pid)
+ snprintf(pid, sizeof(pid), "[%d]", ctl->pid);
cp = ctl->tag ? ctl->tag : xgetlogin();
struct ntptimeval ntptv;
struct timeval tv;
struct tm *tm;
- pid_t process;
int len;
*pid = *time = *timeq = '\0';
if (48 < strlen(tag))
errx(EXIT_FAILURE, _("tag '%s' is too long"), tag);
- if ((process = get_process_id(ctl)))
- snprintf(pid, sizeof(pid), " %d", process);
+ if (ctl->pid)
+ snprintf(pid, sizeof(pid), " %d", ctl->pid);
if (ctl->rfc5424_tq) {
if (ntp_gettime(&ntptv) == TIME_OK)
char time[32], pid[32];
struct timeval tv;
struct tm *tm;
- pid_t process;
int len;
gettimeofday(&tv, NULL);
tag = ctl->tag ? ctl->tag : program_invocation_short_name;
- if ((process = get_process_id(ctl)))
- snprintf(pid, sizeof(pid), "[%d]", process);
+ if (ctl->pid)
+ snprintf(pid, sizeof(pid), "[%d]", ctl->pid);
else
pid[0] = '\0';
fprintf(out, _(" %s [options] [<message>]\n"), program_invocation_short_name);
fputs(USAGE_OPTIONS, out);
- fputs(_(" -i, --id[=pid|ppid] log PID or PPID (default is PID)\n"), out);
+ fputs(_(" -i, --id[=<id>] log <id> (default is 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);
{
struct logger_ctl ctl = {
.fd = -1,
- .ppid = 0,
+ .pid = 0,
.pri = LOG_NOTICE,
.prio_prefix = 0,
.tag = NULL,
stdout_reopened = 1;
break;
case 'i': /* log process id also */
- ctl.pid = 1;
if (optarg) {
const char *p = optarg;
if (*p == '=')
p++;
- if (!strcmp(p, "ppid"))
- ctl.ppid = 1;
- else if (!strcmp(p, "pid"))
- ctl.ppid = 0;
- else
- warnx(_("ignoring unknown option argument: %s"), optarg);
- }
+ ctl.pid = strtoul_or_err(optarg, _("failed to parse id"));
+ } else
+ ctl.pid = getpid();
break;
case 'p': /* priority */
ctl.pri = pencode(optarg);