Source-Changes-HG archive

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

[src/netbsd-1-5]: src/usr.bin/newsyslog Pull up revisions 1.22-1.43 (via patc...



details:   https://anonhg.NetBSD.org/src/rev/355052fdc3f0
branches:  netbsd-1-5
changeset: 492932:355052fdc3f0
user:      he <he%NetBSD.org@localhost>
date:      Wed Mar 06 23:34:45 2002 +0000

description:
Pull up revisions 1.22-1.43 (via patch, requested by martti):
  Synchronize to current development version.  This includes among
  other things the ``specific time for periodic trimming'' feature.

diffstat:

 usr.bin/newsyslog/newsyslog.c |  1515 +++++++++++++++++++++++++---------------
 1 files changed, 926 insertions(+), 589 deletions(-)

diffs (truncated from 1609 to 300 lines):

diff -r 70aa9024da09 -r 355052fdc3f0 usr.bin/newsyslog/newsyslog.c
--- a/usr.bin/newsyslog/newsyslog.c     Wed Mar 06 23:34:24 2002 +0000
+++ b/usr.bin/newsyslog/newsyslog.c     Wed Mar 06 23:34:45 2002 +0000
@@ -1,50 +1,63 @@
-/*     $NetBSD: newsyslog.c,v 1.21.4.1 2000/10/09 11:08:29 ad Exp $    */
+/*     $NetBSD: newsyslog.c,v 1.21.4.2 2002/03/06 23:34:45 he Exp $    */
+
+/*
+ * Copyright (c) 1999, 2000 Andrew Doran <ad%NetBSD.org@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
 
 /*
  * This file contains changes from the Open Software Foundation.
  */
 
 /*
-
-Copyright 1988, 1989 by the Massachusetts Institute of Technology
-
-Permission to use, copy, modify, and distribute this software
-and its documentation for any purpose and without fee is
-hereby granted, provided that the above copyright notice
-appear in all copies and that both that copyright notice and
-this permission notice appear in supporting documentation,
-and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
-used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-M.I.T. and the M.I.T. S.I.P.B. make no representations about
-the suitability of this software for any purpose.  It is
-provided "as is" without express or implied warranty.
-
-*/
+ * Copyright 1988, 1989 by the Massachusetts Institute of Technology
+ * 
+ * Permission to use, copy, modify, and distribute this software
+ * and its documentation for any purpose and without fee is
+ * hereby granted, provided that the above copyright notice
+ * appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation,
+ * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
+ * used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission.
+ * M.I.T. and the M.I.T. S.I.P.B. make no representations about
+ * the suitability of this software for any purpose.  It is
+ * provided "as is" without express or implied warranty.
+ * 
+ */
 
 /*
- *      newsyslog - roll over selected logs at the appropriate time,
- *              keeping the a specified number of backup files around.
+ * newsyslog(8) - a program to roll over log files provided that specified
+ * critera are met, optionally preserving a number of historical log files.
  */
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: newsyslog.c,v 1.21.4.1 2000/10/09 11:08:29 ad Exp $");
+__RCSID("$NetBSD: newsyslog.c,v 1.21.4.2 2002/03/06 23:34:45 he Exp $");
 #endif /* not lint */
 
-#ifndef CONF
-#define CONF "/etc/athena/newsyslog.conf" /* Configuration file */
-#endif
-#ifndef PIDFILE
-#define PIDFILE "/etc/syslog.pid"
-#endif
-#ifndef COMPRESS
-#define COMPRESS "/usr/ucb/compress" /* File compression program */
-#endif
-#ifndef COMPRESS_POSTFIX
-#define COMPRESS_POSTFIX ".Z"
-#endif
-
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/stat.h>
@@ -58,628 +71,952 @@
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdarg.h>
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <errno.h>
+#include <err.h>
+#include <util.h>
+#include <paths.h>
 
-#define kbytes(size)  (((size) + 1023) >> 10)
-#ifdef _IBMR2
-/* Calculates (db * DEV_BSIZE) */
-#define dbtob(db)  ((unsigned)(db) << UBSHIFT) 
-#endif
+#include "pathnames.h"
+
+#define        PRHDRINFO(x)    ((void)(verbose ? printf x : 0))
+#define        PRINFO(x)       ((void)(verbose ? printf("  ") + printf x : 0))
 
-#define CE_COMPACT 1            /* Compact the achived log files */
-#define CE_BINARY 2             /* Logfile is in binary, don't add */
-                                /* status messages */
-#define CE_NOSIGNAL 4           /* Don't send a signal when trimmed */
-#define NONE -1
-        
+#define        CE_COMPRESS     0x01    /* Compress the archived log files */
+#define        CE_BINARY       0x02    /* Logfile is a binary file/non-syslog */
+#define        CE_NOSIGNAL     0x04    /* Don't send a signal when trimmed */
+#define        CE_CREATE       0x08    /* Create log file if none exists */
+#define        CE_PLAIN0       0x10    /* Do not compress zero'th history file */
+
 struct conf_entry {
-        char    *log;           /* Name of the log */
-        int     uid;            /* Owner of log */
-        int     gid;            /* Group of log */
-        int     numlogs;        /* Number of logs to keep */
-        int     size;           /* Size cutoff to trigger trimming the log */
-        int     hours;          /* Hours between log trimming */
-        int     permissions;    /* File permissions on the log */
-        int     flags;          /* Flags (CE_*) */
-        char   *pidfile;       /* Name of file containing PID to signal */
-        int    signum;         /* Signal to send */
-        struct conf_entry       *next; /* Linked list pointer */
+       uid_t   uid;                    /* Owner of log */
+       gid_t   gid;                    /* Group of log */
+       mode_t  mode;                   /* File permissions */
+       int     numhist;                /* Number of historical logs to keep */
+       size_t  maxsize;                /* Maximum log size */
+       int     maxage;                 /* Hours between log trimming */
+       time_t  trimat;                 /* Specific trim time */
+       int     flags;                  /* Flags (CE_*) */
+       int     signum;                 /* Signal to send */
+       char    pidfile[MAXPATHLEN];    /* File containing PID to signal */
+       char    logfile[MAXPATHLEN];    /* Path to log file */
 };
 
-char    *progname;              /* contains argv[0] */
-int     verbose = 0;            /* Print out what's going on */
-int     needroot = 1;           /* Root privs are necessary */
-int     noaction = 0;           /* Don't do anything, just show it */
-int    force;                  /* Force the trim no matter what */
-char    *conf = CONF;           /* Configuration file to use */
-time_t  timenow;
-int     syslog_pid;             /* read in from /etc/syslog.pid */
-#define MIN_PID                3
-#define MAX_PID                65534
-char    hostname[MAXHOSTNAMELEN + 1];           /* hostname */
-char    *daytime;               /* timenow in human readable form */
-
+int    verbose;                        /* Be verbose */
+int    noaction;                       /* Take no action */
+int    nosignal;                       /* Do not send signals */
+char    hostname[MAXHOSTNAMELEN + 1];  /* Hostname, stripped of domain */
+uid_t  myeuid;                         /* EUID we are running with */
 
-void   PRS __P((int, char **));
-int    age_old_log __P((char *));
-void   compress_log __P((char *));
-void   dotrim __P((char *, int, int, int, int, int, char *, int));
-void   do_entry __P((struct conf_entry *));
-int    isnumber __P((char *));
-int    log_trim __P((char *));
-int    main __P((int, char **));
-char   *missing_field __P((char *, char *));
-struct conf_entry *parse_file __P((void));
-int    sizefile __P((char *));
-char   *sob __P((char *));
-char   *son __P((char *));
-void   usage __P((void));
-int    getsig __P((char *));
+int    getsig(const char *);
+int    isnumber(const char *);
+int    main(int, char **);
+int    parse_cfgline(struct conf_entry *, FILE *, size_t *);
+time_t parse_iso8601(char *);
+time_t parse_dwm(char *);
+int    parse_userspec(const char *, struct passwd **, struct group **);
+pid_t  readpidfile(const char *);
+void   usage(void);
 
+void   log_compress(struct conf_entry *, const char *);
+void   log_create(struct conf_entry *);
+void   log_examine(struct conf_entry *, int);
+void   log_trim(struct conf_entry *);
+void   log_trimmed(struct conf_entry *);
+
+/*
+ * Program entry point.
+ */
 int
-main(argc,argv)
-        int argc;
-        char **argv;
-{
-        struct conf_entry *p, *q;
-        
-        PRS(argc,argv);
-        if (needroot && getuid() && geteuid()) {
-                fprintf(stderr,"%s: must have root privs\n",progname);
-                exit(1);
-        }
-        p = q = parse_file();
-        while (p) {
-                do_entry(p);
-                p=p->next;
-                free((char *) q);
-                q=p;
-        }
-        exit(0);
-}
-
-void
-do_entry(ent)
-        struct conf_entry       *ent;
+main(int argc, char **argv)
 {
-        int     size, modtime;
-        
-        if (verbose) {
-                if (ent->flags & CE_COMPACT)
-                        printf("%s <%dZ>: ",ent->log,ent->numlogs);
-                else
-                        printf("%s <%d>: ",ent->log,ent->numlogs);
-        }
-        size = sizefile(ent->log);
-        modtime = age_old_log(ent->log);
-        if (size < 0) {
-                if (verbose)
-                        printf("does not exist.\n");
-        } else {
-                if (verbose && (ent->size > 0))
-                        printf("size (Kb): %d [%d] ", size, ent->size);
-                if (verbose && (ent->hours > 0))
-                        printf(" age (hr): %d [%d] ", modtime, ent->hours);
-                if (force || ((ent->size > 0) && (size >= ent->size)) ||
-                    ((ent->hours > 0) && ((modtime >= ent->hours)
-                                        || (modtime < 0)))) {
-                        if (verbose)
-                                printf("--> trimming log....\n");
-                        if (noaction && !verbose) {
-                                if (ent->flags & CE_COMPACT)
-                                        printf("%s <%dZ>: trimming",
-                                               ent->log,ent->numlogs);
-                                else
-                                        printf("%s <%d>: trimming",
-                                               ent->log,ent->numlogs);
-                        }
-                        dotrim(ent->log, ent->numlogs, ent->flags,
-                               ent->permissions, ent->uid, ent->gid,
-                               ent->pidfile, ent->signum);
-                } else {
-                        if (verbose)
-                                printf("--> skipping\n");
-                }
-        }
-}
+       struct conf_entry log;
+       FILE *fd;
+       char *p, *cfile;
+       int c, needroot, i, force;
+       size_t lineno;
+
+       force = 0;
+       needroot = 1;
+       cfile = _PATH_NEWSYSLOGCONF;
+
+       gethostname(hostname, sizeof (hostname));
+       hostname[sizeof (hostname) - 1] = '\0';
+
+       /* Truncate domain. */
+       if ((p = strchr(hostname, '.')) != NULL)
+               *p = '\0';
 
-void
-PRS(argc,argv)
-        int argc;



Home | Main Index | Thread Index | Old Index