[hackers] [sbase] Audit logger(1) || FRIGN

From: <git_AT_suckless.org>
Date: Sat, 7 Mar 2015 00:25:45 +0100 (CET)

commit 5342ed279f23abbadcfad07663d240dfd6632958
Author: FRIGN <dev_AT_frign.de>
Date: Sat Mar 7 00:08:43 2015 +0100

    Audit logger(1)
    
    1) Update manpage to current style
    2) Line spacing
    3) Local variable grouping
    4) check for getline >= 0 instead of != -1
    5) error message cleanup

diff --git a/README b/README
index 4e9f925..d9d488e 100644
--- a/README
+++ b/README
_AT_@ -40,7 +40,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
 =* kill yes none
 =*| link yes none
 =*| ln yes none
-=* logger yes none
+=*| logger yes none
 =* logname yes none
 = ls no (-C), -S, -f, -m, -s, -x
 =*| md5sum non-posix none
diff --git a/logger.1 b/logger.1
index ec0f2f0..22cadc1 100644
--- a/logger.1
+++ b/logger.1
_AT_@ -1,4 +1,4 @@
-.Dd December 4, 2014
+.Dd March 7, 2015
 .Dt LOGGER 1
 .Os sbase
 .Sh NAME
_AT_@ -14,24 +14,31 @@
 .Nm
 provides a shell command interface to the
 .Xr syslog 3
-system log module.
+system log module and writes each
+.Ar message
+to the log.
+If no
+.Ar message
+is given,
+.Nm
+logs stdin.
 .Sh OPTIONS
 .Bl -tag -width xxxxxxxxxxxx
 .It Fl i
-Log the process ID of the logger process with each line.
+Add the logger process ID to each line in the log.
 .It Fl p Ar priority
-Enter the message with the specified priority. They priority has to be
-specified symbolically as
+Set the message
+.Ar priority
+given symbolically as a
 .Dq facility.level
 pair. The default is
 .Dq user.notice .
 .It Fl s
-Log the message to standard error, as well as the system log.
+Also log to stderr.
 .It Fl t Ar tag
-Mark every line in the log with the specified
-.Ar tag .
-.It Ar message
-Write the message to the log; if not specified, standard input is logged.
+Add
+.Ar tag
+to each line in the log.
 .El
 .Sh SEE ALSO
 .Xr syslogd 1 ,
_AT_@ -43,6 +50,6 @@ utility is compliant with the
 .St -p1003.1-2008
 specification.
 .Pp
-The flags
+The
 .Op Fl ipst
-are extensions to that specification.
+flags are an extensions to that specification.
diff --git a/logger.c b/logger.c
index 36d3a3a..0f8a763 100644
--- a/logger.c
+++ b/logger.c
_AT_@ -18,8 +18,8 @@ decodetable(CODE *table, char *name)
                 if (!strcasecmp(name, c->c_name))
                         return c->c_val;
         eprintf("invalid priority name: %s\n", name);
- /* NOTREACHED */
- return -1;
+
+ return -1; /* not reached */
 }
 
 static int
_AT_@ -32,6 +32,7 @@ decodepri(char *pri)
         *lev++ = '\0';
         if (!*lev)
                 eprintf("invalid priority name: %s\n", pri);
+
         return (decodetable(facilitynames, fac) & LOG_FACMASK) |
                (decodetable(prioritynames, lev) & LOG_PRIMASK);
 }
_AT_@ -45,10 +46,9 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
+ size_t sz;
+ int logflags = 0, priority = LOG_NOTICE, i;
         char *buf = NULL, *tag = NULL;
- size_t sz = 0;
- int logflags = 0, priority = LOG_NOTICE;
- int i;
 
         ARGBEGIN {
         case 'i':
_AT_@ -69,13 +69,13 @@ main(int argc, char *argv[])
 
         openlog(tag ? tag : getlogin(), logflags, 0);
 
- if (argc == 0) {
- while (getline(&buf, &sz, stdin) != -1)
+ if (!argc) {
+ while (getline(&buf, &sz, stdin) >= 0)
                         syslog(priority, "%s", buf);
                 if (ferror(stdin))
- eprintf("%s: read error:", "<stdin>");
+ eprintf("getline %s:", "<stdin>");
         } else {
- for (i = 0; i < argc; i++)
+ for (i = 0, sz = 0; i < argc; i++)
                         sz += strlen(argv[i]);
                 sz += argc;
                 buf = ecalloc(1, sz);
_AT_@ -86,6 +86,8 @@ main(int argc, char *argv[])
                 }
                 syslog(priority, "%s", buf);
         }
+
         closelog();
+
         return 0;
 }
Received on Sat Mar 07 2015 - 00:25:45 CET

This archive was generated by hypermail 2.3.0 : Sat Mar 07 2015 - 00:36:10 CET