Allow user to specify which logs to rotate

This commit is contained in:
Dag-Erling Smørgrav 2000-05-11 10:17:54 +00:00
parent d220443d1c
commit 78ae26252e
2 changed files with 25 additions and 10 deletions

View File

@ -28,6 +28,7 @@
.Op Fl Fnrv .Op Fl Fnrv
.Op Fl f Ar config_file .Op Fl f Ar config_file
.Op Fl a Ar directory .Op Fl a Ar directory
.Op Ar
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm Newsyslog .Nm Newsyslog
is a program that should be scheduled to run periodically by is a program that should be scheduled to run periodically by
@ -355,6 +356,11 @@ to trim the logs, even if the trim conditions have not been met. This
option is useful for diagnosing system problems by providing you with option is useful for diagnosing system problems by providing you with
fresh logs that contain only the problems. fresh logs that contain only the problems.
.El .El
.Pp
If additional command line arguments are given,
.Nm
will only examine log files that match those arguments; otherwise, it
will examine all files listed in the configuration file.
.Sh FILES .Sh FILES
.Bl -tag -width /etc/newsyslog.confxxxx -compact .Bl -tag -width /etc/newsyslog.confxxxx -compact
.It Pa /etc/newsyslog.conf .It Pa /etc/newsyslog.conf

View File

@ -95,7 +95,7 @@ time_t timenow;
char hostname[MAXHOSTNAMELEN + 1]; /* hostname */ char hostname[MAXHOSTNAMELEN + 1]; /* hostname */
char *daytime; /* timenow in human readable form */ char *daytime; /* timenow in human readable form */
static struct conf_entry *parse_file(); static struct conf_entry *parse_file(char **files);
static char *sob(char *p); static char *sob(char *p);
static char *son(char *p); static char *son(char *p);
static char *missing_field(char *p, char *errline); static char *missing_field(char *p, char *errline);
@ -121,7 +121,7 @@ main(int argc, char **argv)
PRS(argc, argv); PRS(argc, argv);
if (needroot && getuid() && geteuid()) if (needroot && getuid() && geteuid())
errx(1, "must have root privs"); errx(1, "must have root privs");
p = q = parse_file(); p = q = parse_file(argv + optind);
while (p) { while (p) {
do_entry(p); do_entry(p);
@ -214,7 +214,6 @@ PRS(int argc, char **argv)
if ((p = strchr(hostname, '.'))) { if ((p = strchr(hostname, '.'))) {
*p = '\0'; *p = '\0';
} }
optind = 1; /* Start options parsing */
while ((c = getopt(argc, argv, "nrvFf:a:t:")) != -1) while ((c = getopt(argc, argv, "nrvFf:a:t:")) != -1)
switch (c) { switch (c) {
case 'n': case 'n':
@ -253,11 +252,12 @@ usage(void)
* process * process
*/ */
static struct conf_entry * static struct conf_entry *
parse_file(void) parse_file(char **files)
{ {
FILE *f; FILE *f;
char line[BUFSIZ], *parse, *q; char line[BUFSIZ], *parse, *q;
char *errline, *group; char *errline, *group;
char **p;
struct conf_entry *first = NULL; struct conf_entry *first = NULL;
struct conf_entry *working = NULL; struct conf_entry *working = NULL;
struct passwd *pass; struct passwd *pass;
@ -274,6 +274,21 @@ parse_file(void)
if ((line[0] == '\n') || (line[0] == '#')) if ((line[0] == '\n') || (line[0] == '#'))
continue; continue;
errline = strdup(line); errline = strdup(line);
q = parse = missing_field(sob(line), errline);
parse = son(line);
if (!*parse)
errx(1, "malformed line (missing fields):\n%s", errline);
*parse = '\0';
if (*files) {
for (p = files; *p; ++p)
if (strcmp(*p, q) == 0)
break;
if (!*p)
continue;
}
if (!first) { if (!first) {
working = (struct conf_entry *) malloc(sizeof(struct conf_entry)); working = (struct conf_entry *) malloc(sizeof(struct conf_entry));
first = working; first = working;
@ -281,12 +296,6 @@ parse_file(void)
working->next = (struct conf_entry *) malloc(sizeof(struct conf_entry)); working->next = (struct conf_entry *) malloc(sizeof(struct conf_entry));
working = working->next; working = working->next;
} }
q = parse = missing_field(sob(line), errline);
parse = son(line);
if (!*parse)
errx(1, "malformed line (missing fields):\n%s", errline);
*parse = '\0';
working->log = strdup(q); working->log = strdup(q);
q = parse = missing_field(sob(++parse), errline); q = parse = missing_field(sob(++parse), errline);