newsyslog.c (e12f0d2fac9a974fd424bbbd930d2ca40fb1f062) | newsyslog.c (9674b13dcb28623b2bd8f40aeac5f6da4bb9b23e) |
---|---|
1/* 2 * This file contains changes from the Open Software Foundation. 3 */ 4 5/* 6 * Copyright 1988, 1989 by the Massachusetts Institute of Technology 7 * 8 * Permission to use, copy, modify, and distribute this software and its --- 77 unchanged lines hidden (view full) --- 86}; 87 88int archtodir = 0; /* Archive old logfiles to other directory */ 89int verbose = 0; /* Print out what's going on */ 90int needroot = 1; /* Root privs are necessary */ 91int noaction = 0; /* Don't do anything, just show it */ 92int force = 0; /* Force the trim no matter what */ 93char *archdirname; /* Directory path to old logfiles archive */ | 1/* 2 * This file contains changes from the Open Software Foundation. 3 */ 4 5/* 6 * Copyright 1988, 1989 by the Massachusetts Institute of Technology 7 * 8 * Permission to use, copy, modify, and distribute this software and its --- 77 unchanged lines hidden (view full) --- 86}; 87 88int archtodir = 0; /* Archive old logfiles to other directory */ 89int verbose = 0; /* Print out what's going on */ 90int needroot = 1; /* Root privs are necessary */ 91int noaction = 0; /* Don't do anything, just show it */ 92int force = 0; /* Force the trim no matter what */ 93char *archdirname; /* Directory path to old logfiles archive */ |
94char *conf = _PATH_CONF; /* Configuration file to use */ | 94const char *conf = _PATH_CONF; /* Configuration file to use */ |
95time_t timenow; 96 97#define MIN_PID 5 98#define MAX_PID 99999 /* was lower, see /usr/include/sys/proc.h */ 99char hostname[MAXHOSTNAMELEN]; /* hostname */ 100char *daytime; /* timenow in human readable form */ 101 102static struct conf_entry *parse_file(char **files); 103static char *sob(char *p); 104static char *son(char *p); 105static char *missing_field(char *p, char *errline); 106static void do_entry(struct conf_entry * ent); 107static void PRS(int argc, char **argv); | 95time_t timenow; 96 97#define MIN_PID 5 98#define MAX_PID 99999 /* was lower, see /usr/include/sys/proc.h */ 99char hostname[MAXHOSTNAMELEN]; /* hostname */ 100char *daytime; /* timenow in human readable form */ 101 102static struct conf_entry *parse_file(char **files); 103static char *sob(char *p); 104static char *son(char *p); 105static char *missing_field(char *p, char *errline); 106static void do_entry(struct conf_entry * ent); 107static void PRS(int argc, char **argv); |
108static void usage(); 109static void dotrim(char *log, char *pid_file, int numdays, int falgs, int perm, int owner_uid, int group_gid, int sig); | 108static void usage(void); 109static void dotrim(char *log, const char *pid_file, int numdays, int falgs, int perm, int owner_uid, int group_gid, int sig); |
110static int log_trim(char *log); 111static void compress_log(char *log); 112static void bzcompress_log(char *log); 113static int sizefile(char *file); 114static int age_old_log(char *file); | 110static int log_trim(char *log); 111static void compress_log(char *log); 112static void bzcompress_log(char *log); 113static int sizefile(char *file); 114static int age_old_log(char *file); |
115static pid_t get_pid(char *pid_file); | 115static pid_t get_pid(const char *pid_file); |
116static time_t parse8601(char *s); 117static void movefile(char *from, char *to, int perm, int owner_uid, int group_gid); 118static void createdir(char *dirpart); 119static time_t parseDWM(char *s); 120 121int 122main(int argc, char **argv) 123{ --- 12 unchanged lines hidden (view full) --- 136 } 137 return (0); 138} 139 140static void 141do_entry(struct conf_entry * ent) 142{ 143 int size, modtime; | 116static time_t parse8601(char *s); 117static void movefile(char *from, char *to, int perm, int owner_uid, int group_gid); 118static void createdir(char *dirpart); 119static time_t parseDWM(char *s); 120 121int 122main(int argc, char **argv) 123{ --- 12 unchanged lines hidden (view full) --- 136 } 137 return (0); 138} 139 140static void 141do_entry(struct conf_entry * ent) 142{ 143 int size, modtime; |
144 char *pid_file; | 144 const char *pid_file; |
145 146 if (verbose) { 147 if (ent->flags & CE_COMPACT) 148 printf("%s <%dZ>: ", ent->log, ent->numlogs); 149 else if (ent->flags & CE_BZCOMPACT) 150 printf("%s <%dJ>: ", ent->log, ent->numlogs); 151 else 152 printf("%s <%d>: ", ent->log, ent->numlogs); --- 328 unchanged lines hidden (view full) --- 481missing_field(char *p, char *errline) 482{ 483 if (!p || !*p) 484 errx(1, "missing field in config file:\n%s", errline); 485 return (p); 486} 487 488static void | 145 146 if (verbose) { 147 if (ent->flags & CE_COMPACT) 148 printf("%s <%dZ>: ", ent->log, ent->numlogs); 149 else if (ent->flags & CE_BZCOMPACT) 150 printf("%s <%dJ>: ", ent->log, ent->numlogs); 151 else 152 printf("%s <%d>: ", ent->log, ent->numlogs); --- 328 unchanged lines hidden (view full) --- 481missing_field(char *p, char *errline) 482{ 483 if (!p || !*p) 484 errx(1, "missing field in config file:\n%s", errline); 485 return (p); 486} 487 488static void |
489dotrim(char *log, char *pid_file, int numdays, int flags, int perm, | 489dotrim(char *log, const char *pid_file, int numdays, int flags, int perm, |
490 int owner_uid, int group_gid, int sig) 491{ 492 char dirpart[MAXPATHLEN], namepart[MAXPATHLEN]; 493 char file1[MAXPATHLEN], file2[MAXPATHLEN]; 494 char zfile1[MAXPATHLEN], zfile2[MAXPATHLEN]; 495 char jfile1[MAXPATHLEN]; 496 int notified, need_notification, fd, _numdays; 497 struct stat st; --- 276 unchanged lines hidden (view full) --- 774 775 if (stat(strcat(tmp, ".0"), &sb) < 0) 776 if (stat(strcat(tmp, COMPRESS_POSTFIX), &sb) < 0) 777 return (-1); 778 return ((int) (timenow - sb.st_mtime + 1800) / 3600); 779} 780 781static pid_t | 490 int owner_uid, int group_gid, int sig) 491{ 492 char dirpart[MAXPATHLEN], namepart[MAXPATHLEN]; 493 char file1[MAXPATHLEN], file2[MAXPATHLEN]; 494 char zfile1[MAXPATHLEN], zfile2[MAXPATHLEN]; 495 char jfile1[MAXPATHLEN]; 496 int notified, need_notification, fd, _numdays; 497 struct stat st; --- 276 unchanged lines hidden (view full) --- 774 775 if (stat(strcat(tmp, ".0"), &sb) < 0) 776 if (stat(strcat(tmp, COMPRESS_POSTFIX), &sb) < 0) 777 return (-1); 778 return ((int) (timenow - sb.st_mtime + 1800) / 3600); 779} 780 781static pid_t |
782get_pid(char *pid_file) | 782get_pid(const char *pid_file) |
783{ 784 FILE *f; 785 char line[BUFSIZ]; 786 pid_t pid = 0; 787 788 if ((f = fopen(pid_file, "r")) == NULL) 789 warn("can't open %s pid file to restart a daemon", 790 pid_file); --- 210 unchanged lines hidden (view full) --- 1001 for (;;) { 1002 switch (*s) { 1003 case 'D': 1004 if (Dseen) 1005 return -1; 1006 Dseen++; 1007 s++; 1008 ul = strtoul(s, &t, 10); | 783{ 784 FILE *f; 785 char line[BUFSIZ]; 786 pid_t pid = 0; 787 788 if ((f = fopen(pid_file, "r")) == NULL) 789 warn("can't open %s pid file to restart a daemon", 790 pid_file); --- 210 unchanged lines hidden (view full) --- 1001 for (;;) { 1002 switch (*s) { 1003 case 'D': 1004 if (Dseen) 1005 return -1; 1006 Dseen++; 1007 s++; 1008 ul = strtoul(s, &t, 10); |
1009 if (ul < 0 || ul > 23) | 1009 if (ul > 23) |
1010 return -1; 1011 tm.tm_hour = ul; 1012 break; 1013 1014 case 'W': 1015 if (WMseen) 1016 return -1; 1017 WMseen++; 1018 s++; 1019 ul = strtoul(s, &t, 10); | 1010 return -1; 1011 tm.tm_hour = ul; 1012 break; 1013 1014 case 'W': 1015 if (WMseen) 1016 return -1; 1017 WMseen++; 1018 s++; 1019 ul = strtoul(s, &t, 10); |
1020 if (ul < 0 || ul > 6) | 1020 if (ul > 6) |
1021 return -1; | 1021 return -1; |
1022 if (ul != tm.tm_wday) { | 1022 if (ul != (unsigned)tm.tm_wday) { |
1023 int save; 1024 | 1023 int save; 1024 |
1025 if (ul < tm.tm_wday) { | 1025 if (ul < (unsigned)tm.tm_wday) { |
1026 save = 6 - tm.tm_wday; 1027 save += (ul + 1); 1028 } else { 1029 save = ul - tm.tm_wday; 1030 } 1031 1032 tm.tm_mday += save; 1033 --- 13 unchanged lines hidden (view full) --- 1047 tm.tm_mday = nd; 1048 s++; 1049 t = s; 1050 } else { 1051 ul = strtoul(s, &t, 10); 1052 if (ul < 1 || ul > 31) 1053 return -1; 1054 | 1026 save = 6 - tm.tm_wday; 1027 save += (ul + 1); 1028 } else { 1029 save = ul - tm.tm_wday; 1030 } 1031 1032 tm.tm_mday += save; 1033 --- 13 unchanged lines hidden (view full) --- 1047 tm.tm_mday = nd; 1048 s++; 1049 t = s; 1050 } else { 1051 ul = strtoul(s, &t, 10); 1052 if (ul < 1 || ul > 31) 1053 return -1; 1054 |
1055 if (ul > nd) | 1055 if (ul > (unsigned)nd) |
1056 return -1; 1057 tm.tm_mday = ul; 1058 } 1059 break; 1060 1061 default: 1062 return (-1); 1063 break; 1064 } 1065 1066 if (*t == '\0' || isspace(*t)) 1067 break; 1068 else 1069 s = t; 1070 } 1071 return mktime(&tm); 1072} | 1056 return -1; 1057 tm.tm_mday = ul; 1058 } 1059 break; 1060 1061 default: 1062 return (-1); 1063 break; 1064 } 1065 1066 if (*t == '\0' || isspace(*t)) 1067 break; 1068 else 1069 s = t; 1070 } 1071 return mktime(&tm); 1072} |