* [PATCH 00/10] pull: logger changes
@ 2014-07-22 22:00 Sami Kerola
2014-07-22 22:00 ` [PATCH 01/10] logger: ensure program writes everything to syslog file descriptor Sami Kerola
` (10 more replies)
0 siblings, 11 replies; 21+ messages in thread
From: Sami Kerola @ 2014-07-22 22:00 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa, Kodiak Firesmith
Hello,
Couple weeks I wrote few logger(1) changes that has been lying in my git
repo waiting release to happen. Now when the v2.25 is out it's time to
consider these changes.
Some of the changes are inspired by request from Kodiak, who is CC'd with
them. He approached me after rc1 release that could I add fully
qualified hostname to logger's remote server logging. When I looked
syslog related RFC's I realized the old BSD syslog protocol (rfc 3164)
does not seem to cover the fqdn case. So supporting more recent protocol
(rfc 5424) felt like a good idea. Here is a example of rfc 5424 logger
line after syslog-ng received it.
Jun 28 14:41:02 127.0.0.1 1 2014-06-28T14:41:02.762100+0100 kerolasa.example.com tag - [timeQuality tzKnown="1" isSynced="1" syncAccuracy="506435"] message
The additional ISO-8601 style time stamp and time quality markups are
enabled by default. Plus I am proposing to use the new format as default
when logging to remote server, with an option --rfc3164 to revert to old
format when needed. Maybe that is a step too far, or maybe not. Either
way comments, opinions, request for further changes, and such would be
nice to hear.
Sami Kerola (10):
logger: ensure program writes everything to syslog file descriptor
logger: fix indentation issues
logger: do not rely only getlogin(3) telling who ran the command
logger: refactor long if clause
docs: make logger.1 facilities and levels easier to read
logger: add function pointer to choose how logging is done
logger: add rfc5424 support
docs: add logger protocol notes to manual page
logger: add process --id=parent optional argument
logger: make --stderr print remote server messages
audit_getloginuid | 0
bash-completion/logger | 2 +-
misc-utils/logger.1 | 98 ++++++++++++----
misc-utils/logger.c | 300 ++++++++++++++++++++++++++++++++++++-------------
4 files changed, 295 insertions(+), 105 deletions(-)
create mode 100644 audit_getloginuid
The following changes since commit a3c74d88e126552b457e964bfa288f39df8dd81a:
swapon: don't print errors as data in smartcols table (2014-07-22 12:29:38 +0200)
are available in the git repository at:
git://github.com/kerolasa/lelux-utiliteetit.git
for you to fetch changes up to c1f7a32499b162a33433160cb5778a3b59840757:
logger: make --stderr print remote server messages (2014-07-22 22:29:04 +0100)
--
2.0.2
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 01/10] logger: ensure program writes everything to syslog file descriptor
2014-07-22 22:00 [PATCH 00/10] pull: logger changes Sami Kerola
@ 2014-07-22 22:00 ` Sami Kerola
2014-07-29 7:52 ` Karel Zak
2014-07-22 22:00 ` [PATCH 02/10] logger: fix indentation issues Sami Kerola
` (9 subsequent siblings)
10 siblings, 1 reply; 21+ messages in thread
From: Sami Kerola @ 2014-07-22 22:00 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
It is fair assumption messages an user is asking to be wrote will be
attempted to be wrote as hard as possible.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/logger.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index a862e55..6604d1a 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -51,6 +51,7 @@
#include <netdb.h>
#include <getopt.h>
+#include "all-io.h"
#include "c.h"
#include "closestream.h"
#include "nls.h"
@@ -281,8 +282,8 @@ static void mysyslog(int fd, int logflags, int pri, char *tag, char *msg)
snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s",
pri, tp, cp, pid, msg);
- if (write(fd, buf, strlen(buf)+1) < 0)
- return; /* error */
+ if (write_all(fd, buf, strlen(buf)+1) < 0)
+ warn(_("write failed"));
}
}
--
2.0.2
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 02/10] logger: fix indentation issues
2014-07-22 22:00 [PATCH 00/10] pull: logger changes Sami Kerola
2014-07-22 22:00 ` [PATCH 01/10] logger: ensure program writes everything to syslog file descriptor Sami Kerola
@ 2014-07-22 22:00 ` Sami Kerola
2014-07-22 22:00 ` [PATCH 03/10] logger: do not rely only getlogin(3) telling who ran the command Sami Kerola
` (8 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2014-07-22 22:00 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/logger.c | 98 ++++++++++++++++++++++++++---------------------------
1 file changed, 49 insertions(+), 49 deletions(-)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 6604d1a..204511d 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -76,8 +76,7 @@ enum {
OPT_JOURNALD
};
-
-static char* get_prio_prefix(char *msg, int *prio)
+static char *get_prio_prefix(char *msg, int *prio)
{
int p;
char *end = NULL;
@@ -133,8 +132,7 @@ static int pencode(char *s)
if (fac < 0)
errx(EXIT_FAILURE, _("unknown facility name: %s."), save);
*s++ = '.';
- }
- else {
+ } else {
fac = LOG_USER;
s = save;
}
@@ -261,30 +259,30 @@ static int journald_entry(FILE *fp)
static void mysyslog(int fd, int logflags, int pri, char *tag, char *msg)
{
- char buf[1000], pid[30], *cp, *tp;
- time_t now;
-
- if (fd > -1) {
- if (logflags & LOG_PID)
- snprintf (pid, sizeof(pid), "[%d]", getpid());
- else
- pid[0] = 0;
- if (tag)
- cp = tag;
- else {
- cp = getlogin();
- if (!cp)
- cp = "<someone>";
- }
- time(&now);
- tp = ctime(&now)+4;
-
- snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s",
- pri, tp, cp, pid, msg);
-
- if (write_all(fd, buf, strlen(buf)+1) < 0)
- warn(_("write failed"));
- }
+ char buf[1000], pid[30], *cp, *tp;
+ time_t now;
+
+ if (fd > -1) {
+ if (logflags & LOG_PID)
+ snprintf(pid, sizeof(pid), "[%d]", getpid());
+ else
+ pid[0] = 0;
+ if (tag)
+ cp = tag;
+ else {
+ cp = getlogin();
+ if (!cp)
+ cp = "<someone>";
+ }
+ time(&now);
+ tp = ctime(&now) + 4;
+
+ snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s",
+ pri, tp, cp, pid, msg);
+
+ if (write_all(fd, buf, strlen(buf) + 1) < 0)
+ warn(_("write failed"));
+ }
}
static void __attribute__ ((__noreturn__)) usage(FILE *out)
@@ -450,17 +448,19 @@ int main(int argc, char **argv)
for (p = buf, endp = buf + sizeof(buf) - 2; *argv;) {
len = strlen(*argv);
if (p + len > endp && p > buf) {
- if (!usock && !server)
- syslog(pri, "%s", buf);
- else
- mysyslog(LogSock, logflags, pri, tag, buf);
+ if (!usock && !server)
+ syslog(pri, "%s", buf);
+ else
+ mysyslog(LogSock, logflags, pri, tag,
+ buf);
p = buf;
}
if (len > sizeof(buf) - 1) {
- if (!usock && !server)
- syslog(pri, "%s", *argv++);
- else
- mysyslog(LogSock, logflags, pri, tag, *argv++);
+ if (!usock && !server)
+ syslog(pri, "%s", *argv++);
+ else
+ mysyslog(LogSock, logflags, pri, tag,
+ *argv++);
} else {
if (p != buf)
*p++ = ' ';
@@ -469,31 +469,31 @@ int main(int argc, char **argv)
}
}
if (p != buf) {
- if (!usock && !server)
- syslog(pri, "%s", buf);
- else
- mysyslog(LogSock, logflags, pri, tag, buf);
+ if (!usock && !server)
+ syslog(pri, "%s", buf);
+ else
+ mysyslog(LogSock, logflags, pri, tag, buf);
}
} else {
char *msg;
int default_priority = pri;
while (fgets(buf, sizeof(buf), stdin) != NULL) {
- /* glibc is buggy and adds an additional newline,
- so we have to remove it here until glibc is fixed */
- int len = strlen(buf);
+ /* glibc is buggy and adds an additional newline,
+ so we have to remove it here until glibc is fixed */
+ int len = strlen(buf);
- if (len > 0 && buf[len - 1] == '\n')
- buf[len - 1] = '\0';
+ if (len > 0 && buf[len - 1] == '\n')
+ buf[len - 1] = '\0';
msg = buf;
pri = default_priority;
if (prio_prefix && msg[0] == '<')
msg = get_prio_prefix(msg, &pri);
- if (!usock && !server)
- syslog(pri, "%s", msg);
- else
- mysyslog(LogSock, logflags, pri, tag, msg);
+ if (!usock && !server)
+ syslog(pri, "%s", msg);
+ else
+ mysyslog(LogSock, logflags, pri, tag, msg);
}
}
if (!usock && !server)
--
2.0.2
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 03/10] logger: do not rely only getlogin(3) telling who ran the command
2014-07-22 22:00 [PATCH 00/10] pull: logger changes Sami Kerola
2014-07-22 22:00 ` [PATCH 01/10] logger: ensure program writes everything to syslog file descriptor Sami Kerola
2014-07-22 22:00 ` [PATCH 02/10] logger: fix indentation issues Sami Kerola
@ 2014-07-22 22:00 ` Sami Kerola
2014-07-22 22:00 ` [PATCH 04/10] logger: refactor long if clause Sami Kerola
` (7 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2014-07-22 22:00 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The getlogin(3) is known not to always work, and when that happens it is
reasonable to try determine user of name by looking process owner and
passwd information.
Reference: http://man7.org/linux/man-pages/man3/getlogin.3.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/logger.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 204511d..65e468c 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -50,6 +50,7 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <getopt.h>
+#include <pwd.h>
#include "all-io.h"
#include "c.h"
@@ -257,6 +258,16 @@ static int journald_entry(FILE *fp)
}
#endif
+static char *xgetlogin()
+{
+ char *cp;
+ struct passwd *pw;
+
+ if (!(cp = getlogin()) || !*cp)
+ cp = (pw = getpwuid(geteuid()))? pw->pw_name : "<someone>";
+ return cp;
+}
+
static void mysyslog(int fd, int logflags, int pri, char *tag, char *msg)
{
char buf[1000], pid[30], *cp, *tp;
@@ -269,11 +280,8 @@ static void mysyslog(int fd, int logflags, int pri, char *tag, char *msg)
pid[0] = 0;
if (tag)
cp = tag;
- else {
- cp = getlogin();
- if (!cp)
- cp = "<someone>";
- }
+ else
+ cp = xgetlogin();
time(&now);
tp = ctime(&now) + 4;
@@ -438,7 +446,7 @@ int main(int argc, char **argv)
else if (usock)
LogSock = unix_socket(usock, socket_type);
else
- openlog(tag ? tag : getlogin(), logflags, 0);
+ openlog(tag ? tag : xgetlogin(), logflags, 0);
/* log input line if appropriate */
if (argc > 0) {
--
2.0.2
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 04/10] logger: refactor long if clause
2014-07-22 22:00 [PATCH 00/10] pull: logger changes Sami Kerola
` (2 preceding siblings ...)
2014-07-22 22:00 ` [PATCH 03/10] logger: do not rely only getlogin(3) telling who ran the command Sami Kerola
@ 2014-07-22 22:00 ` Sami Kerola
2014-07-22 22:00 ` [PATCH 05/10] docs: make logger.1 facilities and levels easier to read Sami Kerola
` (6 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2014-07-22 22:00 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
When if clause that continues throughout whole function it usually can be
shorten to immediate action, e.g., in this case return on the spot not at
end of the function.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/logger.c | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 65e468c..5506022 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -273,24 +273,22 @@ static void mysyslog(int fd, int logflags, int pri, char *tag, char *msg)
char buf[1000], pid[30], *cp, *tp;
time_t now;
- if (fd > -1) {
- if (logflags & LOG_PID)
- snprintf(pid, sizeof(pid), "[%d]", getpid());
- else
- pid[0] = 0;
- if (tag)
- cp = tag;
- else
- cp = xgetlogin();
- time(&now);
- tp = ctime(&now) + 4;
-
- snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s",
- pri, tp, cp, pid, msg);
-
- if (write_all(fd, buf, strlen(buf) + 1) < 0)
- warn(_("write failed"));
- }
+ if (fd < 0)
+ return;
+ if (logflags & LOG_PID)
+ snprintf(pid, sizeof(pid), "[%d]", getpid());
+ else
+ pid[0] = 0;
+ if (tag)
+ cp = tag;
+ else
+ cp = xgetlogin();
+ time(&now);
+ tp = ctime(&now) + 4;
+ snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s",
+ pri, tp, cp, pid, msg);
+ if (write_all(fd, buf, strlen(buf) + 1) < 0)
+ warn(_("write failed"));
}
static void __attribute__ ((__noreturn__)) usage(FILE *out)
--
2.0.2
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 05/10] docs: make logger.1 facilities and levels easier to read
2014-07-22 22:00 [PATCH 00/10] pull: logger changes Sami Kerola
` (3 preceding siblings ...)
2014-07-22 22:00 ` [PATCH 04/10] logger: refactor long if clause Sami Kerola
@ 2014-07-22 22:00 ` Sami Kerola
2014-07-22 22:00 ` [PATCH 06/10] logger: add function pointer to choose how logging is done Sami Kerola
` (5 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2014-07-22 22:00 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Most people read vertical list lot quicker than horizontal.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/logger.1 | 59 +++++++++++++++++++++++++++++++++++------------------
1 file changed, 39 insertions(+), 20 deletions(-)
diff --git a/misc-utils/logger.1 b/misc-utils/logger.1
index ea1e97d..3228196 100644
--- a/misc-utils/logger.1
+++ b/misc-utils/logger.1
@@ -160,32 +160,51 @@ to start with a hyphen (\-).
Write this \fImessage\fR to the log; if not specified, and the
.B \-f
flag is not provided, standard input is logged.
-.PP
+.SH RETURN VALUE
The
.B logger
utility exits 0 on success, and >0 if an error occurs.
-.PP
+.SH FACILITIES AND LEVELS
Valid facility names are:
-.IR auth , \ authpriv
-(for security information of a sensitive nature),
-.IR cron , \ daemon , \ ftp , \ kern
-(can't be generated from user process),
-.IR lpr , \ mail , \ news , \ security
-(deprecated synonym for
-.IR auth ), \ syslog , \ user , \ uucp ,
-and
-.IR local0 \ to \ local7 ,
-inclusive.
+.TS
+tab(:);
+left l l.
+\fIauth\fR
+\fIauthpriv\fR:for security information of a sensitive nature
+\fIcron\fR
+\fIdaemon\fR
+\fIftp\fR
+\fIkern\fR:cannot be generated from user process
+\fIlpr\fR
+\fImail\fR
+\fInews\fR
+\fIsyslog\fR
+\fIuser\fR
+\fIuucp\fR
+\fIlocal0\fR
+to
+\fIlocal7\fR
+\fIsecurity\fR:deprecated synonym for \fIauth\fR
+.TE
.PP
Valid level names are:
-.IR alert , \ crit , \ debug , \ emerg , \ err , \ error
-(deprecated synonym for
-.IR err ), \ info , \ notice , \ panic
-(deprecated synonym for
-.IR emerg ), \ warning , \ warn
-(deprecated synonym for
-.IR warning ).
-For the priority order and intended purposes of these levels, see
+.TS
+tab(:);
+left l l.
+\fIemerg\fR
+\fIalert\fR
+\fIcrit\fR
+\fIerr\fR
+\fIwarning\fR
+\fInotice\fR
+\fIinfo\fR
+\fIdebug\fR
+\fIpanic\fR:deprecated synonym for \fIemerg\fR
+\fIerror\fR:deprecated synonym for \fIerr\fR
+\fIwarn\fR:deprecated synonym for \fIwarning\fR
+.TE
+.PP
+For the priority order and intended purposes of these facilities and levels, see
.BR syslog (3).
.SH EXAMPLES
logger System rebooted
--
2.0.2
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 06/10] logger: add function pointer to choose how logging is done
2014-07-22 22:00 [PATCH 00/10] pull: logger changes Sami Kerola
` (4 preceding siblings ...)
2014-07-22 22:00 ` [PATCH 05/10] docs: make logger.1 facilities and levels easier to read Sami Kerola
@ 2014-07-22 22:00 ` Sami Kerola
2014-07-24 9:44 ` Karel Zak
2014-07-22 22:00 ` [PATCH 07/10] logger: add rfc5424 support Sami Kerola
` (4 subsequent siblings)
10 siblings, 1 reply; 21+ messages in thread
From: Sami Kerola @ 2014-07-22 22:00 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa, Kodiak Firesmith
This change paves way to adding support for both RFC 3164 and RFC 5424
syslog protocols.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/logger.c | 102 +++++++++++++++++++++++++++-------------------------
1 file changed, 53 insertions(+), 49 deletions(-)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 5506022..d49bb19 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -77,6 +77,13 @@ enum {
OPT_JOURNALD
};
+struct logger_ctl {
+ int fd;
+ int logflags;
+ int pri;
+ char *tag;
+};
+
static char *get_prio_prefix(char *msg, int *prio)
{
int p;
@@ -268,29 +275,34 @@ static char *xgetlogin()
return cp;
}
-static void mysyslog(int fd, int logflags, int pri, char *tag, char *msg)
+static void syslog_rfc3164(struct logger_ctl *ctl, char *msg)
{
char buf[1000], pid[30], *cp, *tp;
time_t now;
- if (fd < 0)
+ if (ctl->fd < 0)
return;
- if (logflags & LOG_PID)
+ if (ctl->logflags & LOG_PID)
snprintf(pid, sizeof(pid), "[%d]", getpid());
else
pid[0] = 0;
- if (tag)
- cp = tag;
+ if (ctl->tag)
+ cp = ctl->tag;
else
cp = xgetlogin();
time(&now);
tp = ctime(&now) + 4;
snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s",
- pri, tp, cp, pid, msg);
- if (write_all(fd, buf, strlen(buf) + 1) < 0)
+ ctl->pri, tp, cp, pid, msg);
+ if (write_all(ctl->fd, buf, strlen(buf) + 1) < 0)
warn(_("write failed"));
}
+static void syslog_local(struct logger_ctl *ctl, char *msg)
+{
+ syslog(ctl->pri, "%s", msg);
+}
+
static void __attribute__ ((__noreturn__)) usage(FILE *out)
{
fputs(USAGE_HEADER, out);
@@ -328,12 +340,18 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
*/
int main(int argc, char **argv)
{
- int ch, logflags, pri, prio_prefix;
- char *tag, buf[1024];
+ struct logger_ctl ctl = {
+ .fd = -1,
+ .logflags = 0,
+ .pri = LOG_NOTICE,
+ .tag = NULL,
+ };
+ int ch, prio_prefix;
+ char buf[1024];
char *usock = NULL;
char *server = NULL;
char *port = NULL;
- int LogSock = -1, socket_type = ALL_TYPES;
+ int socket_type = ALL_TYPES;
#ifdef HAVE_LIBSYSTEMD
FILE *jfd = NULL;
#endif
@@ -356,16 +374,13 @@ int main(int argc, char **argv)
#endif
{ NULL, 0, 0, 0 }
};
+ void (*syslogfp)(struct logger_ctl *ctl, char *msg);
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
atexit(close_stdout);
- tag = NULL;
- pri = LOG_NOTICE;
- logflags = 0;
- prio_prefix = 0;
while ((ch = getopt_long(argc, argv, "f:ip:st:u:dTn:P:Vh",
longopts, NULL)) != -1) {
switch (ch) {
@@ -375,16 +390,16 @@ int main(int argc, char **argv)
optarg);
break;
case 'i': /* log process id also */
- logflags |= LOG_PID;
+ ctl.logflags |= LOG_PID;
break;
case 'p': /* priority */
- pri = pencode(optarg);
+ ctl.pri = pencode(optarg);
break;
case 's': /* log to standard error */
- logflags |= LOG_PERROR;
+ ctl.logflags |= LOG_PERROR;
break;
case 't': /* tag */
- tag = optarg;
+ ctl.tag = optarg;
break;
case 'u': /* unix socket */
usock = optarg;
@@ -439,12 +454,16 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;
}
#endif
- if (server)
- LogSock = inet_socket(server, port, socket_type);
- else if (usock)
- LogSock = unix_socket(usock, socket_type);
- else
- openlog(tag ? tag : xgetlogin(), logflags, 0);
+ if (server) {
+ ctl.fd = inet_socket(server, port, socket_type);
+ syslogfp = syslog_rfc3164;
+ } else if (usock) {
+ ctl.fd = unix_socket(usock, socket_type);
+ syslogfp = syslog_rfc3164;
+ } else {
+ openlog(ctl.tag ? ctl.tag : xgetlogin(), ctl.logflags, 0);
+ syslogfp = syslog_local;
+ }
/* log input line if appropriate */
if (argc > 0) {
@@ -454,20 +473,12 @@ int main(int argc, char **argv)
for (p = buf, endp = buf + sizeof(buf) - 2; *argv;) {
len = strlen(*argv);
if (p + len > endp && p > buf) {
- if (!usock && !server)
- syslog(pri, "%s", buf);
- else
- mysyslog(LogSock, logflags, pri, tag,
- buf);
+ syslogfp(&ctl, buf);
p = buf;
}
- if (len > sizeof(buf) - 1) {
- if (!usock && !server)
- syslog(pri, "%s", *argv++);
- else
- mysyslog(LogSock, logflags, pri, tag,
- *argv++);
- } else {
+ if (len > sizeof(buf) - 1)
+ syslogfp(&ctl, *argv++);
+ else {
if (p != buf)
*p++ = ' ';
memmove(p, *argv++, len);
@@ -475,14 +486,11 @@ int main(int argc, char **argv)
}
}
if (p != buf) {
- if (!usock && !server)
- syslog(pri, "%s", buf);
- else
- mysyslog(LogSock, logflags, pri, tag, buf);
+ syslogfp(&ctl, buf);
}
} else {
char *msg;
- int default_priority = pri;
+ int default_priority = ctl.pri;
while (fgets(buf, sizeof(buf), stdin) != NULL) {
/* glibc is buggy and adds an additional newline,
so we have to remove it here until glibc is fixed */
@@ -492,20 +500,16 @@ int main(int argc, char **argv)
buf[len - 1] = '\0';
msg = buf;
- pri = default_priority;
+ ctl.pri = default_priority;
if (prio_prefix && msg[0] == '<')
- msg = get_prio_prefix(msg, &pri);
-
- if (!usock && !server)
- syslog(pri, "%s", msg);
- else
- mysyslog(LogSock, logflags, pri, tag, msg);
+ msg = get_prio_prefix(msg, &ctl.pri);
+ syslogfp(&ctl, msg);
}
}
if (!usock && !server)
closelog();
else
- close(LogSock);
+ close(ctl.fd);
return EXIT_SUCCESS;
}
--
2.0.2
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 07/10] logger: add rfc5424 support
2014-07-22 22:00 [PATCH 00/10] pull: logger changes Sami Kerola
` (5 preceding siblings ...)
2014-07-22 22:00 ` [PATCH 06/10] logger: add function pointer to choose how logging is done Sami Kerola
@ 2014-07-22 22:00 ` Sami Kerola
2014-07-24 9:55 ` Karel Zak
2014-07-22 22:00 ` [PATCH 08/10] docs: add logger protocol notes to manual page Sami Kerola
` (3 subsequent siblings)
10 siblings, 1 reply; 21+ messages in thread
From: Sami Kerola @ 2014-07-22 22:00 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa, Kodiak Firesmith
Add support the more recent syslog protocol and make it default. The
older BSD syslog protocol can still be used with option --rfc3164.
Protocols are meaningful only when messages are sent to remote syslog
server.
Requested-by: Kodiak Firesmith <ksf@sei.cmu.edu>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
audit_getloginuid | 0
misc-utils/logger.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 108 insertions(+), 8 deletions(-)
create mode 100644 audit_getloginuid
diff --git a/audit_getloginuid b/audit_getloginuid
new file mode 100644
index 0000000..e69de29
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index d49bb19..3974f11 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -44,6 +44,7 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#include <sys/timex.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -74,7 +75,9 @@ enum {
enum {
OPT_PRIO_PREFIX = CHAR_MAX + 1,
- OPT_JOURNALD
+ OPT_JOURNALD,
+ OPT_RFC3164,
+ OPT_RFC5424
};
struct logger_ctl {
@@ -82,6 +85,9 @@ struct logger_ctl {
int logflags;
int pri;
char *tag;
+ unsigned int rfc5424_time:1,
+ rfc5424_tq:1,
+ rfc5424_host:1;
};
static char *get_prio_prefix(char *msg, int *prio)
@@ -298,6 +304,82 @@ static void syslog_rfc3164(struct logger_ctl *ctl, char *msg)
warn(_("write failed"));
}
+static void syslog_rfc5424(struct logger_ctl *ctl, char *msg)
+{
+ char *buf, pid[32], *tag;
+ struct ntptimeval ntptv;
+ char fmt[64], time[64], timeq[80], *hostname;
+ struct timeval tv;
+ struct tm *tm;
+
+ if (ctl->fd < 0)
+ return;
+ if (ctl->rfc5424_time) {
+ gettimeofday(&tv, NULL);
+ if ((tm = localtime(&tv.tv_sec)) != NULL) {
+ strftime(fmt, sizeof(fmt), " %Y-%m-%dT%H:%M:%S.%%06u%z",
+ tm);
+ snprintf(time, sizeof(time), fmt, tv.tv_usec);
+ } else
+ err(EXIT_FAILURE, _("localtime() failed"));
+ } else
+ time[0] = 0;
+ if (ctl->rfc5424_host) {
+ hostname = xgethostname();
+ /* Arbitrary looking 'if (var < strlen()) checks originate from
+ * RFC 5424 - 6 Syslog Message Format definition. */
+ if (255 < strlen(hostname))
+ errx(EXIT_FAILURE, _("hostname '%s' is too long"),
+ hostname);
+ } else
+ hostname = xcalloc(1, sizeof(char));
+ if (ctl->tag)
+ tag = ctl->tag;
+ else
+ tag = xgetlogin();
+ if (48 < strlen(tag))
+ errx(EXIT_FAILURE, _("tag '%s' is too long"), tag);
+ if (ctl->logflags & LOG_PID)
+ snprintf(pid, sizeof(pid), " %d", getpid());
+ else
+ pid[0] = 0;
+ if (ctl->rfc5424_tq) {
+ if (ntp_gettime(&ntptv) == TIME_OK)
+ snprintf(timeq, sizeof(timeq),
+ " [timeQuality tzKnown=\"1\" isSynced=\"1\" syncAccuracy=\"%ld\"]",
+ ntptv.maxerror);
+ else
+ snprintf(timeq, sizeof(timeq),
+ " [timeQuality tzKnown=\"1\" isSynced=\"0\"]");
+ } else
+ timeq[0] = 0;
+ xasprintf(&buf, "<%d>1%s%s%s %s -%s%s %s", ctl->pri, time,
+ hostname[0] ? " " : "", hostname, tag, pid, timeq, msg);
+ if (write_all(ctl->fd, buf, strlen(buf) + 1) < 0)
+ warn(_("write failed"));
+ free(hostname);
+ free(buf);
+}
+
+static void parse_rfc5424(struct logger_ctl *ctl, char *optarg)
+{
+ char *in, *tok;
+
+ in = optarg;
+ while ((tok = strtok(in, ","))) {
+ in = NULL;
+ if (!strcmp(tok, "notime")) {
+ ctl->rfc5424_time = 0;
+ ctl->rfc5424_tq = 0;
+ } else if (!strcmp(tok, "notq"))
+ ctl->rfc5424_tq = 0;
+ else if (!strcmp(tok, "nohost"))
+ ctl->rfc5424_host = 0;
+ else
+ warnx(_("ignoring unknown option argument: %s"), tok);
+ }
+}
+
static void syslog_local(struct logger_ctl *ctl, char *msg)
{
syslog(ctl->pri, "%s", msg);
@@ -309,16 +391,19 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
fprintf(out, _(" %s [options] [<message>]\n"), program_invocation_short_name);
fputs(USAGE_OPTIONS, out);
- fputs(_(" -T, --tcp use TCP only\n"), out);
- fputs(_(" -d, --udp use UDP only\n"), out);
fputs(_(" -i, --id log the process ID too\n"), out);
fputs(_(" -f, --file <file> log the contents of this file\n"), out);
- fputs(_(" -n, --server <name> write to this remote syslog server\n"), out);
- fputs(_(" -P, --port <number> use this UDP port\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);
fputs(_(" -s, --stderr output message to standard error as well\n"), out);
fputs(_(" -t, --tag <tag> mark every line with this tag\n"), out);
+ fputs(_(" -n, --server <name> write to this remote syslog server\n"), out);
+ fputs(_(" -P, --port <number> use this UDP port\n"), out);
+ fputs(_(" -T, --tcp use TCP only\n"), out);
+ fputs(_(" -d, --udp use UDP only\n"), out);
+ fputs(_(" --rfc3164 use the BSD syslog protocol\n"), out);
+ fputs(_(" --rfc5424[=<notime,notq,nohost>]\n"), out);
+ fputs(_(" use the syslog protocol (default)\n"), out);
fputs(_(" -u, --socket <socket> write to this Unix socket\n"), out);
#ifdef HAVE_LIBSYSTEMD
fputs(_(" --journald[=<file>] write journald entry\n"), out);
@@ -345,6 +430,9 @@ int main(int argc, char **argv)
.logflags = 0,
.pri = LOG_NOTICE,
.tag = NULL,
+ .rfc5424_time = 1,
+ .rfc5424_tq = 1,
+ .rfc5424_host = 1,
};
int ch, prio_prefix;
char buf[1024];
@@ -369,12 +457,14 @@ int main(int argc, char **argv)
{ "version", no_argument, 0, 'V' },
{ "help", no_argument, 0, 'h' },
{ "prio-prefix", no_argument, 0, OPT_PRIO_PREFIX },
+ { "rfc3164", no_argument, 0, OPT_RFC3164 },
+ { "rfc5424", optional_argument, 0, OPT_RFC5424 },
#ifdef HAVE_LIBSYSTEMD
{ "journald", optional_argument, 0, OPT_JOURNALD },
#endif
{ NULL, 0, 0, 0 }
};
- void (*syslogfp)(struct logger_ctl *ctl, char *msg);
+ void (*syslogfp)(struct logger_ctl *ctl, char *msg) = NULL;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@@ -424,6 +514,14 @@ int main(int argc, char **argv)
case OPT_PRIO_PREFIX:
prio_prefix = 1;
break;
+ case OPT_RFC3164:
+ syslogfp = syslog_rfc3164;
+ break;
+ case OPT_RFC5424:
+ syslogfp = syslog_rfc5424;
+ if (optarg)
+ parse_rfc5424(&ctl, optarg);
+ break;
#ifdef HAVE_LIBSYSTEMD
case OPT_JOURNALD:
if (optarg) {
@@ -456,10 +554,12 @@ int main(int argc, char **argv)
#endif
if (server) {
ctl.fd = inet_socket(server, port, socket_type);
- syslogfp = syslog_rfc3164;
+ if (!syslogfp)
+ syslogfp = syslog_rfc5424;
} else if (usock) {
ctl.fd = unix_socket(usock, socket_type);
- syslogfp = syslog_rfc3164;
+ if (!syslogfp)
+ syslogfp = syslog_rfc5424;
} else {
openlog(ctl.tag ? ctl.tag : xgetlogin(), ctl.logflags, 0);
syslogfp = syslog_local;
--
2.0.2
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 08/10] docs: add logger protocol notes to manual page
2014-07-22 22:00 [PATCH 00/10] pull: logger changes Sami Kerola
` (6 preceding siblings ...)
2014-07-22 22:00 ` [PATCH 07/10] logger: add rfc5424 support Sami Kerola
@ 2014-07-22 22:00 ` Sami Kerola
2014-07-22 22:00 ` [PATCH 09/10] logger: add process --id=parent optional argument Sami Kerola
` (2 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2014-07-22 22:00 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa, Kodiak Firesmith
Inform about rfc5424 support, how to control what it includes to
submission, and that it is the new default when sending syslog messages
to remote server without specifying protocol.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
bash-completion/logger | 2 +-
misc-utils/logger.1 | 28 +++++++++++++++++++++++++++-
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/bash-completion/logger b/bash-completion/logger
index 6b4c7df..0a66af3 100644
--- a/bash-completion/logger
+++ b/bash-completion/logger
@@ -37,7 +37,7 @@ _logger_module()
esac
case $cur in
-*)
- OPTS="--journald --udp --id --file --help --server --port --priority --stderr --tag --socket --version"
+ OPTS="--journald --udp --id --file --help --server --port --priority --rfc3164 --rfc5424 --stderr --tag --socket --version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
diff --git a/misc-utils/logger.1 b/misc-utils/logger.1
index 3228196..214e870 100644
--- a/misc-utils/logger.1
+++ b/misc-utils/logger.1
@@ -33,7 +33,7 @@
.\"
.\" Section on valid facility and level strings added by
.\" and1000@debian.org, 26 Oct 1997.
-.TH LOGGER "1" "April 2013" "util-linux" "User Commands"
+.TH LOGGER "1" "June 2014" "util-linux" "User Commands"
.SH NAME
logger \- a shell command interface to the syslog(3) system log module
.SH SYNOPSIS
@@ -104,6 +104,32 @@ specified by the \fB\-p\fR option. Similarly, if no prefix is provided,
the line is logged using the \fB\-p\fR \fIpriority\fR.
This option doesn't affect a command-line message.
+
+.TP
+\fB\-\-rfc3164\fR
+Use RFC 3164 BSD syslog protocol to submit messages to remote server.
+.TP
+\fB\-\-rfc5424\fR [\fInotime\fR,\fInotq\fR,\fInohost\fR]
+Use RFC 5424 syslog protocol to submit messages to remote server.
+Optional argument
+.I notime
+will supress submission of sender time stamp that is in ISO-8601 format,
+including microseconds and timezone. When
+.I notime
+is specified the time quality structured data, that can be suppressed
+separately with
+.IR notq ,
+is excluded from output. The time quality information tells if local
+clock was syncronized, and maximum number of microseconds the time stamp
+could be off. Option argument
+.I nohost
+will suppress
+.IR gethostname (2)
+information from message header.
+.IP
+The rfc5424 protocol has been default for
+.B logger
+since version 2.26.
.TP
\fB\-s\fR, \fB\-\-stderr\fR
Output the message to standard error as well as to the system log.
--
2.0.2
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 09/10] logger: add process --id=parent optional argument
2014-07-22 22:00 [PATCH 00/10] pull: logger changes Sami Kerola
` (7 preceding siblings ...)
2014-07-22 22:00 ` [PATCH 08/10] docs: add logger protocol notes to manual page Sami Kerola
@ 2014-07-22 22:00 ` Sami Kerola
2014-07-24 10:11 ` Karel Zak
2014-07-22 22:00 ` [PATCH 10/10] logger: make --stderr print remote server messages Sami Kerola
2014-07-29 9:55 ` [PATCH 00/10] pull: logger changes Karel Zak
10 siblings, 1 reply; 21+ messages in thread
From: Sami Kerola @ 2014-07-22 22:00 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
When scripts send several messages they will be easier to group together
when parent process id is printed rather than id of the each logger
process.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/logger.1 | 11 +++++++++--
misc-utils/logger.c | 39 +++++++++++++++++++++++++++++++--------
2 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/misc-utils/logger.1 b/misc-utils/logger.1
index 214e870..f8446b4 100644
--- a/misc-utils/logger.1
+++ b/misc-utils/logger.1
@@ -56,8 +56,15 @@ port defined in /etc/services, which is often
\fB\-h\fR, \fB\-\-help\fR
Display help text and exit.
.TP
-\fB\-i\fR, \fB\-\-id\fR
-Log the process ID of the logger process with each line.
+\fB\-i\fR, \fB\-\-id\fR [\fIparent\fR]
+Log the process ID of the logger process with each line. When optional
+argument
+.I parent
+is specified parent process id is used. Grouping of messages is expected
+to be easier when
+.I parent
+is in use in scripts that send several logger messages and run in
+parallel user sessions.
.TP
.TP
\fB\-n\fR, \fB\-\-server\fR \fIserver\fR
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 3974f11..5c75d71 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -85,7 +85,8 @@ struct logger_ctl {
int logflags;
int pri;
char *tag;
- unsigned int rfc5424_time:1,
+ unsigned int parent:1,
+ rfc5424_time:1,
rfc5424_tq:1,
rfc5424_host:1;
};
@@ -281,15 +282,29 @@ static char *xgetlogin()
return cp;
}
+static pid_t get_process_id(struct logger_ctl *ctl)
+{
+ pid_t id = 0;
+
+ if (ctl->logflags & LOG_PID) {
+ if (ctl->parent)
+ id = getppid();
+ else
+ id = getpid();
+ }
+ return id;
+}
+
static void syslog_rfc3164(struct logger_ctl *ctl, char *msg)
{
char buf[1000], pid[30], *cp, *tp;
time_t now;
+ pid_t process;
if (ctl->fd < 0)
return;
- if (ctl->logflags & LOG_PID)
- snprintf(pid, sizeof(pid), "[%d]", getpid());
+ if ((process = get_process_id(ctl)))
+ snprintf(pid, sizeof(pid), "[%d]", process);
else
pid[0] = 0;
if (ctl->tag)
@@ -311,6 +326,7 @@ static void syslog_rfc5424(struct logger_ctl *ctl, char *msg)
char fmt[64], time[64], timeq[80], *hostname;
struct timeval tv;
struct tm *tm;
+ pid_t process;
if (ctl->fd < 0)
return;
@@ -339,8 +355,8 @@ static void syslog_rfc5424(struct logger_ctl *ctl, char *msg)
tag = xgetlogin();
if (48 < strlen(tag))
errx(EXIT_FAILURE, _("tag '%s' is too long"), tag);
- if (ctl->logflags & LOG_PID)
- snprintf(pid, sizeof(pid), " %d", getpid());
+ if ((process = get_process_id(ctl)))
+ snprintf(pid, sizeof(pid), " %d", process);
else
pid[0] = 0;
if (ctl->rfc5424_tq) {
@@ -391,7 +407,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
fprintf(out, _(" %s [options] [<message>]\n"), program_invocation_short_name);
fputs(USAGE_OPTIONS, out);
- fputs(_(" -i, --id log the process ID too\n"), out);
+ fputs(_(" -i, --id[=parent] log the [parent] process ID too\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);
@@ -428,6 +444,7 @@ int main(int argc, char **argv)
struct logger_ctl ctl = {
.fd = -1,
.logflags = 0,
+ .parent = 0,
.pri = LOG_NOTICE,
.tag = NULL,
.rfc5424_time = 1,
@@ -444,7 +461,7 @@ int main(int argc, char **argv)
FILE *jfd = NULL;
#endif
static const struct option longopts[] = {
- { "id", no_argument, 0, 'i' },
+ { "id", optional_argument, 0, 'i' },
{ "stderr", no_argument, 0, 's' },
{ "file", required_argument, 0, 'f' },
{ "priority", required_argument, 0, 'p' },
@@ -471,7 +488,7 @@ int main(int argc, char **argv)
textdomain(PACKAGE);
atexit(close_stdout);
- while ((ch = getopt_long(argc, argv, "f:ip:st:u:dTn:P:Vh",
+ while ((ch = getopt_long(argc, argv, "f:i::p:st:u:dTn:P:Vh",
longopts, NULL)) != -1) {
switch (ch) {
case 'f': /* file to log */
@@ -481,6 +498,12 @@ int main(int argc, char **argv)
break;
case 'i': /* log process id also */
ctl.logflags |= LOG_PID;
+ if (optarg) {
+ if (!strcmp(optarg, "parent"))
+ ctl.parent = 1;
+ else
+ warnx(_("ignoring unknown option argument: %s"));
+ }
break;
case 'p': /* priority */
ctl.pri = pencode(optarg);
--
2.0.2
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 10/10] logger: make --stderr print remote server messages
2014-07-22 22:00 [PATCH 00/10] pull: logger changes Sami Kerola
` (8 preceding siblings ...)
2014-07-22 22:00 ` [PATCH 09/10] logger: add process --id=parent optional argument Sami Kerola
@ 2014-07-22 22:00 ` Sami Kerola
2014-07-29 9:55 ` [PATCH 00/10] pull: logger changes Karel Zak
10 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2014-07-22 22:00 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Users wish to see the message should include also remote messages, not
only the one sent to locally via libc function.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/logger.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 5c75d71..55c7cef 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -317,6 +317,8 @@ static void syslog_rfc3164(struct logger_ctl *ctl, char *msg)
ctl->pri, tp, cp, pid, msg);
if (write_all(ctl->fd, buf, strlen(buf) + 1) < 0)
warn(_("write failed"));
+ if (ctl->logflags & LOG_PERROR)
+ fprintf(stderr, "%s\n", buf);
}
static void syslog_rfc5424(struct logger_ctl *ctl, char *msg)
@@ -374,6 +376,8 @@ static void syslog_rfc5424(struct logger_ctl *ctl, char *msg)
if (write_all(ctl->fd, buf, strlen(buf) + 1) < 0)
warn(_("write failed"));
free(hostname);
+ if (ctl->logflags & LOG_PERROR)
+ fprintf(stderr, "%s\n", buf);
free(buf);
}
--
2.0.2
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH 06/10] logger: add function pointer to choose how logging is done
2014-07-22 22:00 ` [PATCH 06/10] logger: add function pointer to choose how logging is done Sami Kerola
@ 2014-07-24 9:44 ` Karel Zak
2014-07-26 14:54 ` Sami Kerola
0 siblings, 1 reply; 21+ messages in thread
From: Karel Zak @ 2014-07-24 9:44 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux, Kodiak Firesmith
On Tue, Jul 22, 2014 at 11:00:55PM +0100, Sami Kerola wrote:
> + void (*syslogfp)(struct logger_ctl *ctl, char *msg);
What about to move it to the control struct too?
> + if (server) {
> + ctl.fd = inet_socket(server, port, socket_type);
> + syslogfp = syslog_rfc3164;
> + } else if (usock) {
> + ctl.fd = unix_socket(usock, socket_type);
> + syslogfp = syslog_rfc3164;
> + } else {
> + openlog(ctl.tag ? ctl.tag : xgetlogin(), ctl.logflags, 0);
> + syslogfp = syslog_local;
> + }
Maybe it would be better to create small functions
logger_open()
logger_log()
logger_close()
to keep main() simple and readable and without all the details like
"if (usock) ...".
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 07/10] logger: add rfc5424 support
2014-07-22 22:00 ` [PATCH 07/10] logger: add rfc5424 support Sami Kerola
@ 2014-07-24 9:55 ` Karel Zak
2014-07-24 10:31 ` Sami Kerola
2014-07-26 14:57 ` Sami Kerola
0 siblings, 2 replies; 21+ messages in thread
From: Karel Zak @ 2014-07-24 9:55 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux, Kodiak Firesmith
On Tue, Jul 22, 2014 at 11:00:56PM +0100, Sami Kerola wrote:
> struct logger_ctl {
> @@ -82,6 +85,9 @@ struct logger_ctl {
> int logflags;
> int pri;
> char *tag;
> + unsigned int rfc5424_time:1,
> + rfc5424_tq:1,
what does it mean "_tq"? It's always good idea use comments for flags
and struct members :-)
> + fputs(_(" --rfc3164 use the BSD syslog protocol\n"), out);
"use obsolete BSD syslog protocol"
^^^^^^^
> + parse_rfc5424(&ctl, optarg);
parse_rfc5424_flags()
or so...
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 09/10] logger: add process --id=parent optional argument
2014-07-22 22:00 ` [PATCH 09/10] logger: add process --id=parent optional argument Sami Kerola
@ 2014-07-24 10:11 ` Karel Zak
2014-07-26 15:08 ` Sami Kerola
0 siblings, 1 reply; 21+ messages in thread
From: Karel Zak @ 2014-07-24 10:11 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Tue, Jul 22, 2014 at 11:00:58PM +0100, Sami Kerola wrote:
> + unsigned int parent:1,
ppid : 1
> + rfc5424_time:1,
> rfc5424_tq:1,
> rfc5424_host:1;
> };
> @@ -281,15 +282,29 @@ static char *xgetlogin()
> return cp;
> }
>
> +static pid_t get_process_id(struct logger_ctl *ctl)
> +{
> + pid_t id = 0;
> +
> + if (ctl->logflags & LOG_PID) {
> + if (ctl->parent)
> + id = getppid();
> + else
> + id = getpid();
id = ctl->ppid ? getppid() : getpid();
:-)
> - fputs(_(" -i, --id log the process ID too\n"), out);
> + fputs(_(" -i, --id[=parent] log the [parent] process ID too\n"), out);
what about:
-i, --id[=pid|ppid] log PID or PPID (default is PID)
I think it's more robust and readable when you can specify also
default setting in scripts.
And please, don't use "parent" in code and in the man page. It's
confusing. It's PID and PPID.
(I personally don't like "process ID" too, "PID" is the term.)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 07/10] logger: add rfc5424 support
2014-07-24 9:55 ` Karel Zak
@ 2014-07-24 10:31 ` Sami Kerola
2014-07-26 14:57 ` Sami Kerola
1 sibling, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2014-07-24 10:31 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux, Kodiak Firesmith
On 24 July 2014 10:55, Karel Zak <kzak@redhat.com> wrote:
> On Tue, Jul 22, 2014 at 11:00:56PM +0100, Sami Kerola wrote:
>> struct logger_ctl {
>> @@ -82,6 +85,9 @@ struct logger_ctl {
>> int logflags;
>> int pri;
>> char *tag;
>> + unsigned int rfc5424_time:1,
>> + rfc5424_tq:1,
>
> what does it mean "_tq"? It's always good idea use comments for flags
> and struct members :-)
Thanks for review. Adding comments would indeed make the code more
understandable, I'll do that.
One of my major doubts has been is it too verbose to have the time
quality markups in messages by default? It is possible various
auditors would prefer to see time quality messages, but they are
minority. For most the time quality markups are probably strange
unnecessary looking noise. I feel it is better to be more explicit
about data by default, and allow messaging to be less verbose than
other way around. Does anyone have strong opinions, or good argument,
in behalf or against time quality markup?
>> + fputs(_(" --rfc3164 use the BSD syslog protocol\n"), out);
>
> "use obsolete BSD syslog protocol"
> ^^^^^^^
Request to add 'obsolete' sounds like approval to change the default
from rfc 3164 to rfc 5424.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 06/10] logger: add function pointer to choose how logging is done
2014-07-24 9:44 ` Karel Zak
@ 2014-07-26 14:54 ` Sami Kerola
0 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2014-07-26 14:54 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux, Kodiak Firesmith
On 24 July 2014 10:44, Karel Zak <kzak@redhat.com> wrote:
> On Tue, Jul 22, 2014 at 11:00:55PM +0100, Sami Kerola wrote:
>> + void (*syslogfp)(struct logger_ctl *ctl, char *msg);
>
> What about to move it to the control struct too?
Oh, I see. Done, and that allows the later main() clean up.
https://github.com/kerolasa/lelux-utiliteetit/commit/4d0dc65a487f7bc24899e622158b604fe95d1c4b
>> + if (server) {
>> + ctl.fd = inet_socket(server, port, socket_type);
>> + syslogfp = syslog_rfc3164;
>> + } else if (usock) {
>> + ctl.fd = unix_socket(usock, socket_type);
>> + syslogfp = syslog_rfc3164;
>> + } else {
>> + openlog(ctl.tag ? ctl.tag : xgetlogin(), ctl.logflags, 0);
>> + syslogfp = syslog_local;
>> + }
>
> Maybe it would be better to create small functions
>
> logger_open()
> logger_log()
> logger_close()
>
> to keep main() simple and readable and without all the details like
> "if (usock) ...".
Done in new main() clean up commit.
https://github.com/kerolasa/lelux-utiliteetit/commit/bb840ac3eb832f404f470f8933070f228a104b8e
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 07/10] logger: add rfc5424 support
2014-07-24 9:55 ` Karel Zak
2014-07-24 10:31 ` Sami Kerola
@ 2014-07-26 14:57 ` Sami Kerola
1 sibling, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2014-07-26 14:57 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux, Kodiak Firesmith
On 24 July 2014 10:55, Karel Zak <kzak@redhat.com> wrote:
> On Tue, Jul 22, 2014 at 11:00:56PM +0100, Sami Kerola wrote:
>> struct logger_ctl {
>> @@ -82,6 +85,9 @@ struct logger_ctl {
>> int logflags;
>> int pri;
>> char *tag;
>> + unsigned int rfc5424_time:1,
>> + rfc5424_tq:1,
>
> what does it mean "_tq"? It's always good idea use comments for flags
> and struct members :-)
Comments added.
https://github.com/kerolasa/lelux-utiliteetit/commit/499505cbc97e9047afb982bc66129a94b181b16e#diff-f68064e0e43fa893a5676182f1572882R92
>> + fputs(_(" --rfc3164 use the BSD syslog protocol\n"), out);
>
> "use obsolete BSD syslog protocol"
> ^^^^^^^
The BSD protocol is marked obsolete.
>> + parse_rfc5424(&ctl, optarg);
>
> parse_rfc5424_flags()
The '_flags' is added to function name.
https://github.com/kerolasa/lelux-utiliteetit/commit/499505cbc97e9047afb982bc66129a94b181b16e#diff-f68064e0e43fa893a5676182f1572882R370
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 09/10] logger: add process --id=parent optional argument
2014-07-24 10:11 ` Karel Zak
@ 2014-07-26 15:08 ` Sami Kerola
0 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2014-07-26 15:08 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 24 July 2014 11:11, Karel Zak <kzak@redhat.com> wrote:
> On Tue, Jul 22, 2014 at 11:00:58PM +0100, Sami Kerola wrote:
>
>> + unsigned int parent:1,
>
> ppid : 1
>
>> + rfc5424_time:1,
>> rfc5424_tq:1,
>> rfc5424_host:1;
>> };
>> @@ -281,15 +282,29 @@ static char *xgetlogin()
>> return cp;
>> }
>>
>> +static pid_t get_process_id(struct logger_ctl *ctl)
>> +{
>> + pid_t id = 0;
>> +
>> + if (ctl->logflags & LOG_PID) {
>> + if (ctl->parent)
>> + id = getppid();
>> + else
>> + id = getpid();
>
> id = ctl->ppid ? getppid() : getpid();
>
> :-)
Yep, that is happier code.
https://github.com/kerolasa/lelux-utiliteetit/commit/375223774131ea07d1cb26aa3832c082c1add57b#diff-f68064e0e43fa893a5676182f1572882R291
>> - fputs(_(" -i, --id log the process ID too\n"), out);
>> + fputs(_(" -i, --id[=parent] log the [parent] process ID too\n"), out);
>
> what about:
>
> -i, --id[=pid|ppid] log PID or PPID (default is PID)
>
>
> I think it's more robust and readable when you can specify also
> default setting in scripts.
Support to --id=pid is added.
> And please, don't use "parent" in code and in the man page. It's
> confusing. It's PID and PPID.
>
>
> (I personally don't like "process ID" too, "PID" is the term.)
Various 'process ID' and 'parent' notations are changed to pid and/or
ppid strings. See the github link above.
I will shortly send two logger patches that are previously not seen in
mail list so that they can be publicly reviewed. What comes to
possible merge the maillist versions of the changes are obsolete, and
up to date revisions are available from:
git://github.com/kerolasa/lelux-utiliteetit.git logger
Here are the changes so far.
logger: ensure program writes everything to syslog file descriptor
logger: fix indentation issues
logger: do not rely only getlogin(3) telling who ran the command
logger: refactor long if clause
docs: make logger.1 facilities and levels easier to read
logger: add function pointer to choose how logging is done
logger: tidy up main() by adding small functions and ctl data
logger: add rfc5424 support
docs: add logger protocol notes to manual page
logger: add process --id=parent optional argument
logger: make --stderr print remote server messages
logger: improve readablity of pencode() function
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 01/10] logger: ensure program writes everything to syslog file descriptor
2014-07-22 22:00 ` [PATCH 01/10] logger: ensure program writes everything to syslog file descriptor Sami Kerola
@ 2014-07-29 7:52 ` Karel Zak
2014-07-29 8:23 ` Karel Zak
0 siblings, 1 reply; 21+ messages in thread
From: Karel Zak @ 2014-07-29 7:52 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Tue, Jul 22, 2014 at 11:00:50PM +0100, Sami Kerola wrote:
> @@ -281,8 +282,8 @@ static void mysyslog(int fd, int logflags, int pri, char *tag, char *msg)
> snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s",
^^^^^^^^^^
> pri, tp, cp, pid, msg);
>
> + if (write_all(fd, buf, strlen(buf)+1) < 0)
^^^^^^^^^^
> + warn(_("write failed"));
Do we really need strlen() if there is snprintf(buf, ....)?
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 01/10] logger: ensure program writes everything to syslog file descriptor
2014-07-29 7:52 ` Karel Zak
@ 2014-07-29 8:23 ` Karel Zak
0 siblings, 0 replies; 21+ messages in thread
From: Karel Zak @ 2014-07-29 8:23 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Tue, Jul 29, 2014 at 09:52:50AM +0200, Karel Zak wrote:
> On Tue, Jul 22, 2014 at 11:00:50PM +0100, Sami Kerola wrote:
> > @@ -281,8 +282,8 @@ static void mysyslog(int fd, int logflags, int pri, char *tag, char *msg)
> > snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s",
> ^^^^^^^^^^
> > pri, tp, cp, pid, msg);
> >
> > + if (write_all(fd, buf, strlen(buf)+1) < 0)
> ^^^^^^^^^^
> > + warn(_("write failed"));
>
> Do we really need strlen() if there is snprintf(buf, ....)?
I'm going to improve this, you don't have send a new version.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 00/10] pull: logger changes
2014-07-22 22:00 [PATCH 00/10] pull: logger changes Sami Kerola
` (9 preceding siblings ...)
2014-07-22 22:00 ` [PATCH 10/10] logger: make --stderr print remote server messages Sami Kerola
@ 2014-07-29 9:55 ` Karel Zak
10 siblings, 0 replies; 21+ messages in thread
From: Karel Zak @ 2014-07-29 9:55 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux, Kodiak Firesmith
On Tue, Jul 22, 2014 at 11:00:49PM +0100, Sami Kerola wrote:
> audit_getloginuid | 0
> bash-completion/logger | 2 +-
> misc-utils/logger.1 | 98 ++++++++++++----
> misc-utils/logger.c | 300 ++++++++++++++++++++++++++++++++++++-------------
> 4 files changed, 295 insertions(+), 105 deletions(-)
> create mode 100644 audit_getloginuid
Merged & modified. Thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2014-07-29 9:56 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-22 22:00 [PATCH 00/10] pull: logger changes Sami Kerola
2014-07-22 22:00 ` [PATCH 01/10] logger: ensure program writes everything to syslog file descriptor Sami Kerola
2014-07-29 7:52 ` Karel Zak
2014-07-29 8:23 ` Karel Zak
2014-07-22 22:00 ` [PATCH 02/10] logger: fix indentation issues Sami Kerola
2014-07-22 22:00 ` [PATCH 03/10] logger: do not rely only getlogin(3) telling who ran the command Sami Kerola
2014-07-22 22:00 ` [PATCH 04/10] logger: refactor long if clause Sami Kerola
2014-07-22 22:00 ` [PATCH 05/10] docs: make logger.1 facilities and levels easier to read Sami Kerola
2014-07-22 22:00 ` [PATCH 06/10] logger: add function pointer to choose how logging is done Sami Kerola
2014-07-24 9:44 ` Karel Zak
2014-07-26 14:54 ` Sami Kerola
2014-07-22 22:00 ` [PATCH 07/10] logger: add rfc5424 support Sami Kerola
2014-07-24 9:55 ` Karel Zak
2014-07-24 10:31 ` Sami Kerola
2014-07-26 14:57 ` Sami Kerola
2014-07-22 22:00 ` [PATCH 08/10] docs: add logger protocol notes to manual page Sami Kerola
2014-07-22 22:00 ` [PATCH 09/10] logger: add process --id=parent optional argument Sami Kerola
2014-07-24 10:11 ` Karel Zak
2014-07-26 15:08 ` Sami Kerola
2014-07-22 22:00 ` [PATCH 10/10] logger: make --stderr print remote server messages Sami Kerola
2014-07-29 9:55 ` [PATCH 00/10] pull: logger changes Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).