Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/newsyslog Address PR 16291 by Markus W Kilbinger: ne...



details:   https://anonhg.NetBSD.org/src/rev/717ca98fc9d7
branches:  trunk
changeset: 533040:717ca98fc9d7
user:      ad <ad%NetBSD.org@localhost>
date:      Wed Jun 19 16:30:31 2002 +0000

description:
Address PR 16291 by Markus W Kilbinger: newsyslog always compresses archived
log files.

diffstat:

 usr.bin/newsyslog/newsyslog.c |  68 ++++++++++++++++++++++--------------------
 1 files changed, 35 insertions(+), 33 deletions(-)

diffs (191 lines):

diff -r de14d9a286a8 -r 717ca98fc9d7 usr.bin/newsyslog/newsyslog.c
--- a/usr.bin/newsyslog/newsyslog.c     Wed Jun 19 16:10:48 2002 +0000
+++ b/usr.bin/newsyslog/newsyslog.c     Wed Jun 19 16:30:31 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: newsyslog.c,v 1.43 2002/02/11 10:57:58 wiz Exp $       */
+/*     $NetBSD: newsyslog.c,v 1.44 2002/06/19 16:30:31 ad Exp $        */
 
 /*
  * Copyright (c) 1999, 2000 Andrew Doran <ad%NetBSD.org@localhost>
@@ -55,7 +55,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: newsyslog.c,v 1.43 2002/02/11 10:57:58 wiz Exp $");
+__RCSID("$NetBSD: newsyslog.c,v 1.44 2002/06/19 16:30:31 ad Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -143,8 +143,8 @@
        needroot = 1;
        cfile = _PATH_NEWSYSLOGCONF;
 
-       gethostname(hostname, sizeof (hostname));
-       hostname[sizeof (hostname) - 1] = '\0';
+       gethostname(hostname, sizeof(hostname));
+       hostname[sizeof(hostname) - 1] = '\0';
 
        /* Truncate domain. */
        if ((p = strchr(hostname, '.')) != NULL)
@@ -236,7 +236,7 @@
 
                for (ap = argv, nf = 0; (*ap = strsep(&line, " \t")) != NULL;)
                        if (**ap != '\0') {
-                               if (++nf == sizeof (argv) / sizeof (argv[0])) {
+                               if (++nf == sizeof(argv) / sizeof(argv[0])) {
                                        warnx("config line %d: "
                                            "too many fields", lineno);
                                        goto bad;
@@ -248,11 +248,11 @@
        if (nf < 6)
                errx(EXIT_FAILURE, "config line %d: too few fields", lineno);
        
-       memset(log, 0, sizeof (*log));
+       memset(log, 0, sizeof(*log));
        
        /* logfile_name */
        ap = argv;
-       strlcpy(log->logfile, *ap++, sizeof (log->logfile));
+       strlcpy(log->logfile, *ap++, sizeof(log->logfile));
        if (log->logfile[0] != '/')
                errx(EXIT_FAILURE, 
                    "config line %d: logfile must have a full path", lineno);
@@ -372,7 +372,7 @@
 
        /* path_to_pidfile */
        if (*ap != NULL && **ap == '/')
-               strlcpy(log->pidfile, *ap++, sizeof (log->pidfile));
+               strlcpy(log->pidfile, *ap++, sizeof(log->pidfile));
        else
                log->pidfile[0] = '\0';
 
@@ -441,10 +441,10 @@
         * Get the age (expressed in hours) of the current log file with
         * respect to the newest historical log file.
         */
-       strlcpy(tmp, log->logfile, sizeof (tmp));
-       strlcat(tmp, ".0", sizeof (tmp));
+       strlcpy(tmp, log->logfile, sizeof(tmp));
+       strlcat(tmp, ".0", sizeof(tmp));
        if (stat(tmp, &sb) < 0) {
-               strlcat(tmp, ".gz", sizeof (tmp));
+               strlcat(tmp, ".gz", sizeof(tmp));
                if (stat(tmp, &sb) < 0)
                        age = -1;
                else
@@ -498,25 +498,25 @@
        pid_t pid;
 
        /* Remove oldest historical log. */
-       snprintf(file1, sizeof (file1), "%s.%d", log->logfile,
+       snprintf(file1, sizeof(file1), "%s.%d", log->logfile,
            log->numhist - 1);
 
        PRINFO(("rm -f %s\n", file1));
        if (!noaction)
                unlink(file1);
-       strlcat(file1, ".gz", sizeof (file1));
+       strlcat(file1, ".gz", sizeof(file1));
        PRINFO(("rm -f %s\n", file1));
        if (!noaction)
                unlink(file1);
 
        /* Move down log files. */
        for (i = log->numhist - 1; i != 0; i--) {
-               snprintf(file1, sizeof (file1), "%s.%d", log->logfile, i - 1);
-               snprintf(file2, sizeof (file2), "%s.%d", log->logfile, i);
+               snprintf(file1, sizeof(file1), "%s.%d", log->logfile, i - 1);
+               snprintf(file2, sizeof(file2), "%s.%d", log->logfile, i);
 
                if (lstat(file1, &st) != 0) {
-                       strlcat(file1, ".gz", sizeof (file1));
-                       strlcat(file2, ".gz", sizeof (file2));
+                       strlcat(file1, ".gz", sizeof(file1));
+                       strlcat(file2, ".gz", sizeof(file2));
                        if (lstat(file1, &st) != 0)
                                continue;
                }
@@ -542,14 +542,16 @@
         * if 'p' has been specified.)  It should be noted that gzip(1)
         * preserves file ownership and file mode.
         */
-       for (i = (log->flags & CE_PLAIN0) != 0; i < log->numhist; i++) {
-               snprintf(file1, sizeof (file1), "%s.%d", log->logfile, i);
-               if (lstat(file1, &st) != 0)
-                       continue;
-               snprintf(file2, sizeof (file2), "%s.gz", file1);
-               if (lstat(file2, &st) == 0)
-                       continue;
-               log_compress(log, file1);
+       if ((log->flags & CE_COMPRESS) != 0) {
+               for (i = (log->flags & CE_PLAIN0) != 0; i < log->numhist; i++) {
+                       snprintf(file1, sizeof(file1), "%s.%d", log->logfile, i);
+                       if (lstat(file1, &st) != 0)
+                               continue;
+                       snprintf(file2, sizeof(file2), "%s.gz", file1);
+                       if (lstat(file2, &st) == 0)
+                               continue;
+                       log_compress(log, file1);
+               }
        }
 
        log_trimmed(log);
@@ -561,7 +563,7 @@
                        if (unlink(log->logfile))
                                err(EXIT_FAILURE, "%s", log->logfile);
        } else {
-               snprintf(file1, sizeof (file1), "%s.0", log->logfile);
+               snprintf(file1, sizeof(file1), "%s.0", log->logfile);
                PRINFO(("mv %s %s\n", log->logfile, file1));
                if (!noaction)
                        if (rename(log->logfile, file1))
@@ -596,7 +598,7 @@
 
        /* If the newest historical log is to be compressed, do it here. */
        if ((log->flags & (CE_PLAIN0 | CE_COMPRESS)) == CE_COMPRESS) {
-               snprintf(file1, sizeof (file1), "%s.0", log->logfile);
+               snprintf(file1, sizeof(file1), "%s.0", log->logfile);
                if ((log->flags & CE_NOSIGNAL) == 0) {
                        PRINFO(("sleep for 10 seconds before compressing...\n"));
                        sleep(10);
@@ -678,7 +680,7 @@
                        errx(EXIT_FAILURE, "gzip failed");
        }
 
-       snprintf(tmp, sizeof (tmp), "%s.gz", fn);
+       snprintf(tmp, sizeof(tmp), "%s.gz", fn);
        PRINFO(("chown %d:%d %s\n", log->uid, log->gid, tmp));
        if (!noaction)
                if (chown(tmp, log->uid, log->gid))
@@ -746,9 +748,9 @@
 
 #ifdef notyet
        if (file[0] != '/')
-               snprintf(tmp, sizeof (tmp), "%s%s", _PATH_VARRUN, file);
+               snprintf(tmp, sizeof(tmp), "%s%s", _PATH_VARRUN, file);
        else
-               strlcpy(tmp, file, sizeof (tmp));
+               strlcpy(tmp, file, sizeof(tmp));
 #endif
 
        if ((fd = fopen(file, "rt")) == NULL) {
@@ -756,8 +758,8 @@
                return (-1);
        }
        
-       if (fgets(line, sizeof (line) - 1, fd) != NULL) {
-               line[sizeof (line) - 1] = '\0';
+       if (fgets(line, sizeof(line) - 1, fd) != NULL) {
+               line[sizeof(line) - 1] = '\0';
                pid = (pid_t)strtol(line, NULL, 0);
        } else {
                warnx("unable to read %s", file);
@@ -778,7 +780,7 @@
 {
        char buf[MAXLOGNAME * 2 + 2], *group;
 
-       strlcpy(buf, name, sizeof (buf));
+       strlcpy(buf, name, sizeof(buf));
        *gr = NULL;
 
        /* 



Home | Main Index | Thread Index | Old Index