=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/newsyslog/newsyslog.c,v retrieving revision 1.49 retrieving revision 1.50 diff -c -r1.49 -r1.50 *** src/usr.bin/newsyslog/newsyslog.c 2002/09/13 18:50:09 1.49 --- src/usr.bin/newsyslog/newsyslog.c 2002/09/16 01:41:54 1.50 *************** *** 1,4 **** ! /* $OpenBSD: newsyslog.c,v 1.49 2002/09/13 18:50:09 millert Exp $ */ /* * Copyright (c) 1999, 2002 Todd C. Miller --- 1,4 ---- ! /* $OpenBSD: newsyslog.c,v 1.50 2002/09/16 01:41:54 millert Exp $ */ /* * Copyright (c) 1999, 2002 Todd C. Miller *************** *** 64,86 **** */ /* - 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. --- 64,84 ---- */ /* + * 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. *************** *** 88,94 **** */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: newsyslog.c,v 1.49 2002/09/13 18:50:09 millert Exp $"; #endif /* not lint */ #ifndef CONF --- 86,92 ---- */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: newsyslog.c,v 1.50 2002/09/16 01:41:54 millert Exp $"; #endif /* not lint */ #ifndef CONF *************** *** 134,144 **** /* status messages */ #define CE_MONITOR 0x08 /* Monitory for changes */ #define CE_FOLLOW 0x10 /* Follow symbolic links */ - #define NONE -1 #define MIN_PID 4 /* Don't touch pids lower than this */ #define MIN_SIZE 512 /* Don't rotate if smaller than this */ struct conf_entry { char *log; /* Name of the log */ uid_t uid; /* Owner of log */ --- 132,143 ---- /* status messages */ #define CE_MONITOR 0x08 /* Monitory for changes */ #define CE_FOLLOW 0x10 /* Follow symbolic links */ #define MIN_PID 4 /* Don't touch pids lower than this */ #define MIN_SIZE 512 /* Don't rotate if smaller than this */ + #define DPRINTF(x) do { if (verbose) printf x ; } while (0) + struct conf_entry { char *log; /* Name of the log */ uid_t uid; /* Owner of log */ *************** *** 267,312 **** int modtime, size; struct stat sb; ! if (!(ent->flags & CE_FOLLOW)) { ! if (lstat(ent->log, &sb) != 0) ! return; ! if ((sb.st_mode & S_IFLNK) != S_IFREG) { ! if (verbose) { ! printf("--> %s is not a regular file, skip\n", ! ent->log); ! return; ! } ! } } ! if (verbose) ! printf("%s <%d%s>: ", ent->log, ent->numlogs, ! (ent->flags & CE_COMPACT) ? "Z" : ""); 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 (monitormode && ent->flags & CE_MONITOR) domonitor(ent->log, ent->whom); if (!monitormode && ((ent->size > 0 && size >= ent->size) || (ent->hours > 0 && (modtime >= ent->hours || modtime < 0) && ((ent->flags & CE_BINARY) || size >= MIN_SIZE)))) { ! if (verbose) ! printf("--> trimming log....\n"); if (noaction && !verbose) ! printf("%s <%d%s>: ", ent->log, ent->numlogs, ! (ent->flags & CE_COMPACT) ? "Z" : ""); dotrim(ent->log, ent->numlogs, ent->flags, ent->permissions, ent->uid, ent->gid); ent->flags |= CE_ROTATED; ! } else if (verbose) ! printf("--> skipping\n"); } } --- 266,310 ---- int modtime, size; struct stat sb; ! if (lstat(ent->log, &sb) != 0) ! return; ! if (!S_ISREG(sb.st_mode) && ! (!S_ISLNK(sb.st_mode) || !(ent->flags & CE_FOLLOW))) { ! DPRINTF(("--> not a regular file, skipping\n")); ! return; } ! DPRINTF(("%s <%d%s%s%s>: ", ent->log, ent->numlogs, ! (ent->flags & CE_COMPACT) ? "Z" : "", ! (ent->flags & CE_BINARY) ? "B" : "", ! (ent->flags & CE_FOLLOW) ? "F" : "")); ! size = sizefile(ent->log); modtime = age_old_log(ent->log); if (size < 0) { ! DPRINTF(("does not exist.\n")); } else { ! if (ent->size > 0) ! DPRINTF(("size (Kb): %d [%d] ", size, ent->size)); ! if (ent->hours > 0) ! DPRINTF(("age (hr): %d [%d] ", modtime, ent->hours)); if (monitormode && ent->flags & CE_MONITOR) domonitor(ent->log, ent->whom); if (!monitormode && ((ent->size > 0 && size >= ent->size) || (ent->hours > 0 && (modtime >= ent->hours || modtime < 0) && ((ent->flags & CE_BINARY) || size >= MIN_SIZE)))) { ! DPRINTF(("--> trimming log....\n")); if (noaction && !verbose) ! printf("%s <%d%s%s%s>\n", ent->log, ! ent->numlogs, ! (ent->flags & CE_COMPACT) ? "Z" : "", ! (ent->flags & CE_BINARY) ? "B" : "", ! (ent->flags & CE_FOLLOW) ? "F" : ""); dotrim(ent->log, ent->numlogs, ent->flags, ent->permissions, ent->uid, ent->gid); ent->flags |= CE_ROTATED; ! } else ! DPRINTF(("--> skipping\n")); } } *************** *** 315,321 **** run_command(char *cmd) { if (noaction) ! (void)printf("run %s\n", cmd); else system(cmd); } --- 313,319 ---- run_command(char *cmd) { if (noaction) ! (void)printf("\trun %s\n", cmd); else system(cmd); } *************** *** 473,479 **** } else working->uid = atoi(q); } else ! working->uid = NONE; q = group; if (*q) { --- 471,477 ---- } else working->uid = atoi(q); } else ! working->uid = (uid_t)-1; q = group; if (*q) { *************** *** 484,495 **** } else working->gid = atoi(q); } else ! working->gid = NONE; q = parse = missing_field(sob(++parse), errline); *(parse = son(parse)) = '\0'; ! } else ! working->uid = working->gid = NONE; if (!sscanf(q, "%o", &working->permissions)) errx(1, "Error in config file; bad permissions: %s", q); --- 482,495 ---- } else working->gid = atoi(q); } else ! working->gid = (gid_t)-1; q = parse = missing_field(sob(++parse), errline); *(parse = son(parse)) = '\0'; ! } else { ! working->uid = (uid_t)-1; ! working->gid = (gid_t)-1; ! } if (!sscanf(q, "%o", &working->permissions)) errx(1, "Error in config file; bad permissions: %s", q); *************** *** 632,638 **** COMPRESS_POSTFIX); if (noaction) { ! printf("rm -f %s %s\n", file1, zfile1); } else { (void)unlink(file1); (void)unlink(zfile1); --- 632,638 ---- COMPRESS_POSTFIX); if (noaction) { ! printf("\trm -f %s %s\n", file1, zfile1); } else { (void)unlink(file1); (void)unlink(zfile1); *************** *** 651,667 **** continue; } if (noaction) { ! printf("mv %s %s\n", zfile1, zfile2); ! printf("chmod %o %s\n", perm, zfile2); ! printf("chown %u:%u %s\n", ! owner_uid, group_gid, zfile2); } else { if (rename(zfile1, zfile2)) warn("can't mv %s to %s", zfile1, zfile2); if (chmod(zfile2, perm)) warn("can't chmod %s", zfile2); ! if (chown(zfile2, owner_uid, group_gid)) ! warn("can't chown %s", zfile2); } } if (!noaction && !(flags & CE_BINARY)) --- 651,669 ---- continue; } if (noaction) { ! printf("\tmv %s %s\n", zfile1, zfile2); ! printf("\tchmod %o %s\n", perm, zfile2); ! if (owner_uid != (uid_t)-1 || group_gid != (gid_t)-1) ! printf("\tchown %u:%u %s\n", ! owner_uid, group_gid, zfile2); } else { if (rename(zfile1, zfile2)) warn("can't mv %s to %s", zfile1, zfile2); if (chmod(zfile2, perm)) warn("can't chmod %s", zfile2); ! if (owner_uid != (uid_t)-1 || group_gid != (gid_t)-1) ! if (chown(zfile2, owner_uid, group_gid)) ! warn("can't chown %s", zfile2); } } if (!noaction && !(flags & CE_BINARY)) *************** *** 669,680 **** (void)snprintf(file2, sizeof(file2), "%s.XXXXXXXXXX", log); if (noaction) { ! printf("Create new log file...\n"); } else { if ((fd = mkstemp(file2)) < 0) err(1, "can't start '%s' log", file2); ! if (fchown(fd, owner_uid, group_gid)) ! err(1, "can't chown '%s' log file", file2); if (fchmod(fd, perm)) err(1, "can't chmod '%s' log file", file2); (void)close(fd); --- 671,683 ---- (void)snprintf(file2, sizeof(file2), "%s.XXXXXXXXXX", log); if (noaction) { ! printf("\tmktemp %s\n", file2); } else { if ((fd = mkstemp(file2)) < 0) err(1, "can't start '%s' log", file2); ! if (owner_uid != (uid_t)-1 || group_gid != (gid_t)-1) ! if (fchown(fd, owner_uid, group_gid)) ! err(1, "can't chown '%s' log file", file2); if (fchmod(fd, perm)) err(1, "can't chmod '%s' log file", file2); (void)close(fd); *************** *** 685,703 **** if (days == 0) { if (noaction) ! printf("rm %s\n", log); else if (unlink(log)) warn("can't rm %s", log); } else { if (noaction) ! printf("mv %s to %s\n", log, file1); else if (rename(log, file1)) warn("can't to mv %s to %s", log, file1); } /* Now move the new log file into place */ if (noaction) ! printf("mv %s to %s\n", file2, log); else if (rename(file2, log)) warn("can't to mv %s to %s", file2, log); } --- 688,706 ---- if (days == 0) { if (noaction) ! printf("\trm %s\n", log); else if (unlink(log)) warn("can't rm %s", log); } else { if (noaction) ! printf("\tmv %s to %s\n", log, file1); else if (rename(log, file1)) warn("can't to mv %s to %s", log, file1); } /* Now move the new log file into place */ if (noaction) ! printf("\tmv %s to %s\n", file2, log); else if (rename(file2, log)) warn("can't to mv %s to %s", file2, log); } *************** *** 736,742 **** (void)snprintf(tmp, sizeof(tmp), "%s.0", log); if (pid < 0) { err(1, "fork"); ! } else if (!pid) { (void)execl(COMPRESS, base, "-f", tmp, (char *)NULL); warn(COMPRESS); _exit(1); --- 739,745 ---- (void)snprintf(tmp, sizeof(tmp), "%s.0", log); if (pid < 0) { err(1, "fork"); ! } else if (pid == 0) { (void)execl(COMPRESS, base, "-f", tmp, (char *)NULL); warn(COMPRESS); _exit(1);