newsyslog.c (90240) | newsyslog.c (93659) |
---|---|
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 --- 11 unchanged lines hidden (view full) --- 20 21/* 22 * newsyslog - roll over selected logs at the appropriate time, keeping the a 23 * specified number of backup files around. 24 */ 25 26#ifndef lint 27static const char rcsid[] = | 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 --- 11 unchanged lines hidden (view full) --- 20 21/* 22 * newsyslog - roll over selected logs at the appropriate time, keeping the a 23 * specified number of backup files around. 24 */ 25 26#ifndef lint 27static const char rcsid[] = |
28"$FreeBSD: head/usr.sbin/newsyslog/newsyslog.c 90240 2002-02-05 09:33:07Z roam $"; | 28"$FreeBSD: head/usr.sbin/newsyslog/newsyslog.c 93659 2002-04-02 12:03:16Z cjc $"; |
29#endif /* not lint */ 30 31#define OSF 32#ifndef COMPRESS_POSTFIX 33#define COMPRESS_POSTFIX ".gz" 34#endif 35#ifndef BZCOMPRESS_POSTFIX 36#define BZCOMPRESS_POSTFIX ".bz2" --- 72 unchanged lines hidden (view full) --- 109static void dotrim(char *log, const char *pid_file, int numdays, int falgs, 110 int perm, int owner_uid, int group_gid, int sig); 111static int log_trim(char *log); 112static void compress_log(char *log); 113static void bzcompress_log(char *log); 114static int sizefile(char *file); 115static int age_old_log(char *file); 116static pid_t get_pid(const char *pid_file); | 29#endif /* not lint */ 30 31#define OSF 32#ifndef COMPRESS_POSTFIX 33#define COMPRESS_POSTFIX ".gz" 34#endif 35#ifndef BZCOMPRESS_POSTFIX 36#define BZCOMPRESS_POSTFIX ".bz2" --- 72 unchanged lines hidden (view full) --- 109static void dotrim(char *log, const char *pid_file, int numdays, int falgs, 110 int perm, int owner_uid, int group_gid, int sig); 111static int log_trim(char *log); 112static void compress_log(char *log); 113static void bzcompress_log(char *log); 114static int sizefile(char *file); 115static int age_old_log(char *file); 116static pid_t get_pid(const char *pid_file); |
117static time_t parse8601(char *s); | 117static time_t parse8601(char *s, char *errline); |
118static void movefile(char *from, char *to, int perm, int owner_uid, 119 int group_gid); 120static void createdir(char *dirpart); | 118static void movefile(char *from, char *to, int perm, int owner_uid, 119 int group_gid); 120static void createdir(char *dirpart); |
121static time_t parseDWM(char *s); | 121static time_t parseDWM(char *s, char *errline); |
122 123int 124main(int argc, char **argv) 125{ 126 struct conf_entry *p, *q; 127 128 PRS(argc, argv); 129 if (needroot && getuid() && geteuid()) --- 276 unchanged lines hidden (view full) --- 406 errx(1, "interval is too large:\n%s", errline); 407 else 408 working->hours = ul; 409 410 if (*ep != '\0' && *ep != '@' && *ep != '*' && 411 *ep != '$') 412 errx(1, "malformed interval/at:\n%s", errline); 413 if (*ep == '@') { | 122 123int 124main(int argc, char **argv) 125{ 126 struct conf_entry *p, *q; 127 128 PRS(argc, argv); 129 if (needroot && getuid() && geteuid()) --- 276 unchanged lines hidden (view full) --- 406 errx(1, "interval is too large:\n%s", errline); 407 else 408 working->hours = ul; 409 410 if (*ep != '\0' && *ep != '@' && *ep != '*' && 411 *ep != '$') 412 errx(1, "malformed interval/at:\n%s", errline); 413 if (*ep == '@') { |
414 if ((working->trim_at = parse8601(ep + 1)) | 414 if ((working->trim_at = parse8601(ep + 1, errline)) |
415 == (time_t) - 1) 416 errx(1, "malformed at:\n%s", errline); 417 working->flags |= CE_TRIMAT; 418 } else if (*ep == '$') { | 415 == (time_t) - 1) 416 errx(1, "malformed at:\n%s", errline); 417 working->flags |= CE_TRIMAT; 418 } else if (*ep == '$') { |
419 if ((working->trim_at = parseDWM(ep + 1)) | 419 if ((working->trim_at = parseDWM(ep + 1, errline)) |
420 == (time_t) - 1) 421 errx(1, "malformed at:\n%s", errline); 422 working->flags |= CE_TRIMAT; 423 } 424 } 425 426 if (eol) 427 q = NULL; --- 427 unchanged lines hidden (view full) --- 855 * Parse a limited subset of ISO 8601. The specific format is as follows: 856 * 857 * [CC[YY[MM[DD]]]][THH[MM[SS]]] (where `T' is the literal letter) 858 * 859 * We don't accept a timezone specification; missing fields (including timezone) 860 * are defaulted to the current date but time zero. 861 */ 862static time_t | 420 == (time_t) - 1) 421 errx(1, "malformed at:\n%s", errline); 422 working->flags |= CE_TRIMAT; 423 } 424 } 425 426 if (eol) 427 q = NULL; --- 427 unchanged lines hidden (view full) --- 855 * Parse a limited subset of ISO 8601. The specific format is as follows: 856 * 857 * [CC[YY[MM[DD]]]][THH[MM[SS]]] (where `T' is the literal letter) 858 * 859 * We don't accept a timezone specification; missing fields (including timezone) 860 * are defaulted to the current date but time zero. 861 */ 862static time_t |
863parse8601(char *s) | 863parse8601(char *s, char *errline) |
864{ 865 char *t; | 864{ 865 char *t; |
866 time_t tsecs; |
|
866 struct tm tm, *tmp; 867 u_long ul; 868 869 tmp = localtime(&timenow); 870 tm = *tmp; 871 872 tm.tm_hour = tm.tm_min = tm.tm_sec = 0; 873 --- 51 unchanged lines hidden (view full) --- 925 return -1; 926 } 927 928 /* sanity check */ 929 if (tm.tm_sec < 0 || tm.tm_sec > 60 || tm.tm_min < 0 930 || tm.tm_min > 59 || tm.tm_hour < 0 || tm.tm_hour > 23) 931 return -1; 932 } | 867 struct tm tm, *tmp; 868 u_long ul; 869 870 tmp = localtime(&timenow); 871 tm = *tmp; 872 873 tm.tm_hour = tm.tm_min = tm.tm_sec = 0; 874 --- 51 unchanged lines hidden (view full) --- 926 return -1; 927 } 928 929 /* sanity check */ 930 if (tm.tm_sec < 0 || tm.tm_sec > 60 || tm.tm_min < 0 931 || tm.tm_min > 59 || tm.tm_hour < 0 || tm.tm_hour > 23) 932 return -1; 933 } |
933 return mktime(&tm); | 934 if ((tsecs = mktime(&tm)) == -1) 935 errx(1, "nonexistent time:\n%s", errline); 936 return tsecs; |
934} 935 936/* physically move file */ 937static void 938movefile(char *from, char *to, int perm, int owner_uid, int group_gid) 939{ 940 FILE *src, *dst; 941 int c; --- 55 unchanged lines hidden (view full) --- 997 * - every day (D) within a specific hour (hh) (hh = 0...23) 998 * - once a week (W) at a specific day (d) OR (d = 0..6, 0 = Sunday) 999 * - once a month (M) at a specific day (d) (d = 1..31,l|L) 1000 * 1001 * We don't accept a timezone specification; missing fields 1002 * are defaulted to the current date but time zero. 1003 */ 1004static time_t | 937} 938 939/* physically move file */ 940static void 941movefile(char *from, char *to, int perm, int owner_uid, int group_gid) 942{ 943 FILE *src, *dst; 944 int c; --- 55 unchanged lines hidden (view full) --- 1000 * - every day (D) within a specific hour (hh) (hh = 0...23) 1001 * - once a week (W) at a specific day (d) OR (d = 0..6, 0 = Sunday) 1002 * - once a month (M) at a specific day (d) (d = 1..31,l|L) 1003 * 1004 * We don't accept a timezone specification; missing fields 1005 * are defaulted to the current date but time zero. 1006 */ 1007static time_t |
1005parseDWM(char *s) | 1008parseDWM(char *s, char *errline) |
1006{ 1007 char *t; | 1009{ 1010 char *t; |
1011 time_t tsecs; |
|
1008 struct tm tm, *tmp; 1009 long l; 1010 int nd; 1011 static int mtab[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 1012 int WMseen = 0; 1013 int Dseen = 0; 1014 1015 tmp = localtime(&timenow); --- 77 unchanged lines hidden (view full) --- 1093 break; 1094 } 1095 1096 if (*t == '\0' || isspace(*t)) 1097 break; 1098 else 1099 s = t; 1100 } | 1012 struct tm tm, *tmp; 1013 long l; 1014 int nd; 1015 static int mtab[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 1016 int WMseen = 0; 1017 int Dseen = 0; 1018 1019 tmp = localtime(&timenow); --- 77 unchanged lines hidden (view full) --- 1097 break; 1098 } 1099 1100 if (*t == '\0' || isspace(*t)) 1101 break; 1102 else 1103 s = t; 1104 } |
1101 return mktime(&tm); | 1105 if ((tsecs = mktime(&tm)) == -1) 1106 errx(1, "nonexistent time:\n%s", errline); 1107 return tsecs; |
1102} | 1108} |