Lines Matching +full:zero +full:- +full:crossing +full:- +full:detect

1 /*-
2 * ------+---------+---------+-------- + --------+---------+---------+---------*
4 * Copyright (c) 2003, 2004 - Garance Alistair Drosehn <gad@FreeBSD.org>.
28 * ------+---------+---------+-------- + --------+---------+---------+---------*
52 * newsyslog - roll over selected logs at the appropriate time, keeping the a
104 * Bit-values for the 'flags' parsed from a config-file entry.
112 #define CE_SIGNALGROUP 0x0080 /* Signal a process-group instead of a single */
117 #define CE_PLAIN0 0x0800 /* Do not compress zero'th history file */
120 /* is zero */
143 static const char *gzip_flags[] = { "-f" };
146 static const char *zstd_flags[] = { "-q", "-T0", "--adapt", "--long", "--rm" };
176 int firstcreate; /* Creating log for the first time (-C). */
177 int rotate; /* Non-zero if this file should be rotated */
231 int dbg_at_times; /* -D Show details of 'trim_at' code */
234 static int createlogs; /* Create (non-GLOB) logfiles which do not */
244 static int defsignal = SIGHUP; /* -I Signal to send by default */
245 static int rotatereq = 0; /* -R = Always rotate the file(s) as given */
249 static char *requestor; /* The name given on a -R request */
258 struct ptime_data *dbg_timenow; /* A "timenow" value set via -D option */
259 static struct ptime_data *timenow; /* The time to use for checking at-fields */
263 * used for rotation-tracking messages. */
267 * rotation-tracking messages written by newsyslog and so are not accounted for
270 #define DAYTIME_RFC5424_LEN sizeof("YYYY-MM-DDTHH:MM:SS+00:00")
336 argc -= optind; in main()
356 * them to close and re-open the log file(s) we have rotated. in main()
409 printf("\t--> [creating entry for %s]\n", fname); in init_entry()
416 tempwork->log = strdup(fname); in init_entry()
418 asprintf(&tempwork->log, "%s%s", destdir, fname); in init_entry()
419 if (tempwork->log == NULL) in init_entry()
423 tempwork->pid_cmd_file = NULL; in init_entry()
424 if (src_entry->pid_cmd_file) in init_entry()
425 tempwork->pid_cmd_file = strdup(src_entry->pid_cmd_file); in init_entry()
426 tempwork->r_reason = NULL; in init_entry()
427 tempwork->firstcreate = 0; in init_entry()
428 tempwork->rotate = 0; in init_entry()
429 tempwork->fsize = -1; in init_entry()
430 tempwork->uid = src_entry->uid; in init_entry()
431 tempwork->gid = src_entry->gid; in init_entry()
432 tempwork->numlogs = src_entry->numlogs; in init_entry()
433 tempwork->trsize = src_entry->trsize; in init_entry()
434 tempwork->hours = src_entry->hours; in init_entry()
435 tempwork->trim_at = NULL; in init_entry()
436 if (src_entry->trim_at != NULL) in init_entry()
437 tempwork->trim_at = ptime_init(src_entry->trim_at); in init_entry()
438 tempwork->permissions = src_entry->permissions; in init_entry()
439 tempwork->flags = src_entry->flags; in init_entry()
440 tempwork->compress = src_entry->compress; in init_entry()
441 tempwork->sig = src_entry->sig; in init_entry()
442 tempwork->def_cfg = src_entry->def_cfg; in init_entry()
444 /* Initialize as a "do-nothing" entry */ in init_entry()
445 tempwork->pid_cmd_file = NULL; in init_entry()
446 tempwork->r_reason = NULL; in init_entry()
447 tempwork->firstcreate = 0; in init_entry()
448 tempwork->rotate = 0; in init_entry()
449 tempwork->fsize = -1; in init_entry()
450 tempwork->uid = (uid_t)-1; in init_entry()
451 tempwork->gid = (gid_t)-1; in init_entry()
452 tempwork->numlogs = 1; in init_entry()
453 tempwork->trsize = -1; in init_entry()
454 tempwork->hours = -1; in init_entry()
455 tempwork->trim_at = NULL; in init_entry()
456 tempwork->permissions = 0; in init_entry()
457 tempwork->flags = 0; in init_entry()
458 tempwork->compress = COMPRESS_NONE; in init_entry()
459 tempwork->sig = defsignal; in init_entry()
460 tempwork->def_cfg = 0; in init_entry()
473 if (ent->log != NULL) { in free_entry()
475 printf("\t--> [freeing entry for %s]\n", ent->log); in free_entry()
476 free(ent->log); in free_entry()
477 ent->log = NULL; in free_entry()
480 if (ent->pid_cmd_file != NULL) { in free_entry()
481 free(ent->pid_cmd_file); in free_entry()
482 ent->pid_cmd_file = NULL; in free_entry()
485 if (ent->r_reason != NULL) { in free_entry()
486 free(ent->r_reason); in free_entry()
487 ent->r_reason = NULL; in free_entry()
490 if (ent->trim_at != NULL) { in free_entry()
491 ptime_free(ent->trim_at); in free_entry()
492 ent->trim_at = NULL; in free_entry()
556 printf("%s <%d%s>: ", ent->log, ent->numlogs, in do_entry()
557 compress_type[ent->compress].flag); in do_entry()
558 ent->fsize = sizefile(ent->log); in do_entry()
559 oversized = ((ent->trsize > 0) && (ent->fsize >= ent->trsize)); in do_entry()
560 modtime = age_old_log(ent->log); in do_entry()
561 ent->rotate = 0; in do_entry()
562 ent->firstcreate = 0; in do_entry()
563 if (ent->fsize < 0) { in do_entry()
565 * If either the C flag or the -C option was specified, in do_entry()
572 ent->firstcreate = 1; in do_entry()
573 else if ((ent->flags & CE_CREATE) && createlogs) in do_entry()
574 ent->firstcreate = 1; in do_entry()
575 else if (ent->flags & CE_CREATE) in do_entry()
576 strlcpy(temp_reason, " (no -C option)", REASON_MAX); in do_entry()
580 if (ent->firstcreate) { in do_entry()
582 printf("does not exist -> will create.\n"); in do_entry()
588 if (ent->flags & CE_NOEMPTY && ent->fsize == 0) { in do_entry()
590 printf("--> Not rotating empty file\n"); in do_entry()
593 if (ent->flags & CE_TRIMAT && !force && !rotatereq && in do_entry()
595 diffsecs = ptimeget_diff(timenow, ent->trim_at); in do_entry()
599 ptime_adjust4dst(ent->trim_at, in do_entry()
601 printf("--> will trim at %s", in do_entry()
602 ptimeget_ctime(ent->trim_at)); in do_entry()
612 printf("\n\t--> prev trim at %s\t", in do_entry()
613 ptimeget_ctime(ent->trim_at)); in do_entry()
615 ptimeset_nxtime(ent->trim_at); in do_entry()
616 printf("--> will trim at %s", in do_entry()
617 ptimeget_ctime(ent->trim_at)); in do_entry()
622 * If we are just debugging at-times, then in do_entry()
625 * would all be turned off by no-action. in do_entry()
627 printf("\n\t--> timematch at %s", in do_entry()
628 ptimeget_ctime(ent->trim_at)); in do_entry()
630 } else if (verbose && ent->hours <= 0) { in do_entry()
631 printf("--> time is up\n"); in do_entry()
634 if (verbose && (ent->trsize > 0)) in do_entry()
635 printf("size (Kb): %d [%d] ", ent->fsize, ent->trsize); in do_entry()
636 if (verbose && (ent->hours > 0)) in do_entry()
637 printf(" age (hr): %d [%d] ", modtime, ent->hours); in do_entry()
644 ent->rotate = 1; in do_entry()
645 snprintf(temp_reason, REASON_MAX, " due to -R from %s", in do_entry()
648 ent->rotate = 1; in do_entry()
649 snprintf(temp_reason, REASON_MAX, " due to -F request"); in do_entry()
651 ent->rotate = 1; in do_entry()
653 ent->trsize); in do_entry()
654 } else if (ent->hours <= 0 && (ent->flags & CE_TRIMAT)) { in do_entry()
655 ent->rotate = 1; in do_entry()
656 } else if ((ent->hours > 0) && ((modtime >= ent->hours) || in do_entry()
658 ent->rotate = 1; in do_entry()
664 if (ent->rotate && !norotate) { in do_entry()
666 ent->r_reason = strdup(temp_reason); in do_entry()
668 if (ent->compress == COMPRESS_NONE) in do_entry()
669 printf("--> trimming log....\n"); in do_entry()
671 printf("--> trimming log and compressing with %s....\n", in do_entry()
672 compression_type_name(ent->compress)); in do_entry()
675 printf("%s <%d%s>: trimming\n", ent->log, in do_entry()
676 ent->numlogs, in do_entry()
677 compress_type[ent->compress].flag); in do_entry()
681 printf("--> skipping\n"); in do_entry()
704 while ((ch = getopt(argc, argv, "a:d:f:nrst:vCD:FI:NPR:S:")) != -1) in parse_args()
776 warnx("Only one of -F and -N may be specified."); in parse_args()
783 warnx("At least one filename must be given when -R is specified."); in parse_args()
811 * as writing regression-tests. They would not be needed by users
820 if (strncmp(doption, TN, sizeof(TN) - 1) == 0) { in parse_doption()
823 * by an hour when crossing a timezone change. in parse_doption()
827 time(NULL), doption + sizeof(TN) - 1); in parse_doption()
828 if (res == -2) { in parse_doption()
829 warnx("Non-existent time specified on -D %s", doption); in parse_doption()
832 warnx("Malformed time given on -D %s", doption); in parse_doption()
844 warnx("Unknown -D (debug) option: '%s'", doption); in parse_doption()
853 "usage: newsyslog [-CFNPnrsv] [-a directory] [-d directory] [-f config_file]\n" in usage()
854 " [-I signal] [-S pidfile] [-t timefmt] [[-R tagname] file ...]\n"); in usage()
888 inc->file = conf; in get_worklist()
889 if (inc->file == NULL) in get_worklist()
890 inc->file = _PATH_CONF; in get_worklist()
894 if (strcmp(inc->file, "-") != 0) in get_worklist()
895 f = fopen(inc->file, "r"); in get_worklist()
898 inc->file = "<stdin>"; in get_worklist()
901 err(1, "%s", inc->file); in get_worklist()
904 printf("Processing %s\n", inc->file); in get_worklist()
910 * All config-file information has been read in and turned into in get_worklist()
928 * rotation action. First, create the default-rotation action in get_worklist()
933 defconf->numlogs = 3; in get_worklist()
934 defconf->trsize = 50; in get_worklist()
935 defconf->permissions = S_IRUSR|S_IWUSR; in get_worklist()
941 * it, picking up the rotation-rules for those files from in get_worklist()
944 * XXX - Note that this will copy multiple rules for a single in get_worklist()
957 * First try to find exact-matches for this given file. in get_worklist()
961 if (strcmp(ent->log, *given) == 0) { in get_worklist()
974 * There was no exact-match for this given file, so look in get_worklist()
981 fnres = fnmatch(ent->log, *given, FNM_PATHNAME); in get_worklist()
984 ent->log); in get_worklist()
989 dupent->flags &= ~CE_GLOB; in get_worklist()
991 /* Only allow a match to one glob-entry */ in get_worklist()
998 ent->log); in get_worklist()
1011 dupent->def_cfg = 1; in get_worklist()
1029 * which match those glob-entries onto the worklist.
1042 * The worklist contains all fully-specified (non-GLOB) names. in expand_globs()
1044 * Now expand the list of filename-pattern (GLOB) entries into in expand_globs()
1046 * that already exist. Do not add a glob-related entry for any in expand_globs()
1047 * file which already exists in the fully-specified list. in expand_globs()
1050 gres = glob(globent->log, GLOB_NOCHECK, NULL, &pglob); in expand_globs()
1053 globent->log); in expand_globs()
1058 printf("\t+ Expanding pattern %s\n", globent->log); in expand_globs()
1065 if (strcmp(mfname, ent->log) == 0) { in expand_globs()
1077 warn("Skipping %s - lstat() error", mfname); in expand_globs()
1092 dupent->flags &= ~CE_GLOB; in expand_globs()
1099 printf("\t+ Done with pattern %s\n", globent->log); in expand_globs()
1131 if (*(cp - 1) == '\\') { in parse_file()
1132 strcpy(cp - 1, cp); in parse_file()
1133 cp--; in parse_file()
1257 working->uid = pwd->pw_uid; in parse_file()
1259 working->uid = atoi(q); in parse_file()
1261 working->uid = (uid_t)-1; in parse_file()
1270 working->gid = grp->gr_gid; in parse_file()
1272 working->gid = atoi(q); in parse_file()
1274 working->gid = (gid_t)-1; in parse_file()
1283 working->uid = (uid_t)-1; in parse_file()
1284 working->gid = (gid_t)-1; in parse_file()
1287 if (!sscanf(q, "%o", &working->permissions)) in parse_file()
1290 if ((working->permissions & ~DEFFILEMODE) != 0) { in parse_file()
1292 working->permissions, in parse_file()
1293 working->permissions & DEFFILEMODE, errline); in parse_file()
1294 working->permissions &= DEFFILEMODE; in parse_file()
1303 if (!sscanf(q, "%d", &working->numlogs) || working->numlogs < 0) in parse_file()
1314 char last_digit = q[strlen(q) - 1]; in parse_file()
1316 working->trsize = atoi(q); in parse_file()
1320 working->trsize = trsize / 1024; in parse_file()
1322 working->trsize = -1; in parse_file()
1328 working->trsize = -1; in parse_file()
1332 working->trsize = -1; in parse_file()
1335 working->flags = 0; in parse_file()
1336 working->compress = COMPRESS_NONE; in parse_file()
1347 working->hours = 0; in parse_file()
1349 working->hours = -1; in parse_file()
1353 working->hours = ul; in parse_file()
1360 working->flags |= CE_TRIMAT; in parse_file()
1361 working->trim_at = ptime_init(NULL); in parse_file()
1366 res = ptime_relparse(working->trim_at, ptm_opts, in parse_file()
1368 if (res == -2) in parse_file()
1389 working->flags |= CE_BINARY; in parse_file()
1392 working->flags |= CE_CREATE; in parse_file()
1395 working->flags |= CE_NODUMP; in parse_file()
1398 working->flags |= CE_NOEMPTY; in parse_file()
1401 working->flags |= CE_GLOB; in parse_file()
1405 working->compress = COMPRESS_BZIP2; in parse_file()
1407 working->compress = compress_type_override; in parse_file()
1411 working->flags |= CE_NOSIGNAL; in parse_file()
1414 working->flags |= CE_PLAIN0; in parse_file()
1417 working->flags |= CE_PID2CMD; in parse_file()
1420 working->flags |= CE_RFC5424; in parse_file()
1423 working->flags |= CE_SIGNALGROUP; in parse_file()
1426 /* Deprecated flag - keep for compatibility purposes */ in parse_file()
1430 working->compress = COMPRESS_XZ; in parse_file()
1432 working->compress = compress_type_override; in parse_file()
1437 working->compress = COMPRESS_ZSTD; in parse_file()
1439 working->compress = compress_type_override; in parse_file()
1444 working->compress = COMPRESS_GZIP; in parse_file()
1446 working->compress = compress_type_override; in parse_file()
1449 case '-': in parse_file()
1454 badline("illegal flag in config file -- %c", in parse_file()
1469 working->pid_cmd_file = NULL; in parse_file()
1472 working->pid_cmd_file = strdup(q); in parse_file()
1489 working->sig = defsignal; in parse_file()
1492 if (str2sig(q, &working->sig) != 0) { in parse_file()
1500 * Finish figuring out what pid-file to use (if any) in in parse_file()
1503 if ((working->flags & CE_NOSIGNAL) == CE_NOSIGNAL) { in parse_file()
1505 * This config-entry specified 'n' for nosignal, in parse_file()
1509 if (working->pid_cmd_file != NULL) { in parse_file()
1511 working->pid_cmd_file, errline); in parse_file()
1512 free(working->pid_cmd_file); in parse_file()
1513 working->pid_cmd_file = NULL; in parse_file()
1515 } else if (working->pid_cmd_file == NULL) { in parse_file()
1519 * specified some other pid-file (and obviously the in parse_file()
1520 * syslog pid-file will not be for a process-group). in parse_file()
1524 if (working->flags & CE_SIGNALGROUP) { in parse_file()
1527 working->flags &= ~CE_SIGNALGROUP; in parse_file()
1530 working->pid_cmd_file = strdup(path_syslogpid); in parse_file()
1539 } else if (working->flags & CE_GLOB) { in parse_file()
1574 if (ola->t > olb->t) in oldlog_entry_compare()
1575 return (-1); in oldlog_entry_compare()
1576 else if (ola->t < olb->t) in oldlog_entry_compare()
1598 if (dp->d_type != DT_REG) { in validate_old_timelog()
1604 if (dp->d_type != DT_UNKNOWN || in validate_old_timelog()
1605 fstatat(fd, dp->d_name, &sb, AT_SYMLINK_NOFOLLOW) != 0 || in validate_old_timelog()
1610 if (strncmp(dp->d_name, logfname, logfname_len) != 0) in validate_old_timelog()
1612 /* Ignore the actual non-rotated logfile. */ in validate_old_timelog()
1613 if (dp->d_namlen == logfname_len) in validate_old_timelog()
1620 if (dp->d_name[logfname_len] != '.') { in validate_old_timelog()
1623 "extension '%s'\n", dp->d_name, in validate_old_timelog()
1624 &dp->d_name[logfname_len]); in validate_old_timelog()
1628 if ((s = strptime(&dp->d_name[logfname_len + 1], in validate_old_timelog()
1638 "match time format\n", dp->d_name); in validate_old_timelog()
1649 dp->d_name, s); in validate_old_timelog()
1676 if ((dirbuf = strdup(ent->log)) == NULL) in delete_oldest_timelog()
1681 if ((basebuf = strdup(ent->log)) == NULL) in delete_oldest_timelog()
1685 errx(1, "Invalid log filename - became '/'"); in delete_oldest_timelog()
1702 if ((oldlogs[logcnt].t = timegm(&tm)) == -1) in delete_oldest_timelog()
1704 if ((oldlogs[logcnt].fname = strdup(dp->d_name)) == NULL) in delete_oldest_timelog()
1715 /* Detect integer overflow */ in delete_oldest_timelog()
1726 if (logcnt > 0 && logcnt >= ent->numlogs && ent->numlogs > 1) { in delete_oldest_timelog()
1739 for (i = ent->numlogs - 1; i < logcnt; i++) { in delete_oldest_timelog()
1741 printf("\trm -f %s/%s\n", dir, in delete_oldest_timelog()
1751 printf("No old logs to delete for logfile %s\n", ent->log); in delete_oldest_timelog()
1795 printf("\trm -f %s\n", zfile1); in delete_classiclog()
1811 if (strcmp(fname, inc->file) == 0) { in add_to_queue()
1820 inc->file = strdup(fname); in add_to_queue()
1830 * The suffix detection is first-match in the order of compress_types
1833 * a zero-length string is returned
1866 flags = ent->flags; in do_rotate()
1877 strlcpy(dirpart, ent->log, sizeof(dirpart)); in do_rotate()
1890 if ((p = strrchr(ent->log, '/')) == NULL) in do_rotate()
1891 strlcpy(namepart, ent->log, sizeof(namepart)); in do_rotate()
1900 strlcpy(namepart, ent->log, sizeof(namepart)); in do_rotate()
1909 * kept ent->numlogs + 1 files. This code can go away in do_rotate()
1912 delete_classiclog(dirpart, namepart, ent->numlogs); in do_rotate()
1914 if (ent->numlogs > 0) in do_rotate()
1915 delete_classiclog(dirpart, namepart, ent->numlogs - 1); in do_rotate()
1921 if (time(&now) == (time_t)-1 || in do_rotate()
1931 ent->log, datetimestr); in do_rotate()
1934 numlogs_c = -1; in do_rotate()
1937 ent->numlogs - 1); in do_rotate()
1938 numlogs_c = ent->numlogs - 2; /* copy for countdown */ in do_rotate()
1942 for (; numlogs_c >= 0; numlogs_c--) { in do_rotate()
1959 /* XXX - Ought to be checking for failure! */ in do_rotate()
1963 if (ent->compress && strlen(logfile_suffix) == 0) { in do_rotate()
1973 zwork->zw_conf = ent; in do_rotate()
1974 zwork->zw_fsize = sizefile(zfile2); in do_rotate()
1975 strcpy(zwork->zw_fname, zfile2); in do_rotate()
1981 if (ent->numlogs > 0) { in do_rotate()
1990 printf("\tcp %s %s\n", ent->log, file1); in do_rotate()
1992 printf("\tln %s %s\n", ent->log, file1); in do_rotate()
1994 "# Update mtime for 'when'-interval processing\n", in do_rotate()
1999 log_trim(ent->log, ent); in do_rotate()
2001 savelog(ent->log, file1); in do_rotate()
2003 * Interval-based rotations are done using the mtime of in do_rotate()
2018 * Save all signalling and file-compression to be done after log in do_rotate()
2024 if (ent->pid_cmd_file != NULL) in do_rotate()
2026 if (ent->numlogs > 0 && ent->compress > COMPRESS_NONE) { in do_rotate()
2027 if (!(ent->flags & CE_PLAIN0) || in do_rotate()
2028 strcmp(&file1[strlen(file1) - 2], ".0") != 0) { in do_rotate()
2034 save_zipwork(ent, swork, ent->fsize, file1); in do_rotate()
2048 if (swork->sw_runcmd == 0 && (!(swork->sw_pidok) || swork->sw_pid == 0)) in do_sigwork()
2052 * If nosignal (-s) was specified, then do not signal any process. in do_sigwork()
2054 * rotated logfile needs to be compressed, *unless* -R was also in do_sigwork()
2055 * specified. We assume that an `-sR' request came from a process in do_sigwork()
2058 * just sets swork->sw_pidok to a special value, and do_zipwork in do_sigwork()
2063 swork->sw_pidok = -1; in do_sigwork()
2070 * daemon or process-group. in do_sigwork()
2075 if (swork->sw_pid == nextsig->sw_pid) in do_sigwork()
2082 if (swork->sw_runcmd) in do_sigwork()
2083 printf("\tsh -c '%s %d'\n", swork->sw_fname, in do_sigwork()
2084 swork->sw_signum); in do_sigwork()
2086 printf("\tkill -%d %d \t\t# %s\n", swork->sw_signum, in do_sigwork()
2087 (int)swork->sw_pid, swork->sw_fname); in do_sigwork()
2094 if (swork->sw_runcmd) { in do_sigwork()
2095 asprintf(&tmp, "%s %d", swork->sw_fname, swork->sw_signum); in do_sigwork()
2098 swork->sw_fname); in do_sigwork()
2105 warnx("%s: returned non-zero exit code: %d", in do_sigwork()
2112 kres = kill(swork->sw_pid, swork->sw_signum); in do_sigwork()
2122 swork->sw_pidok = 0; in do_sigwork()
2123 warn("can't notify %s, pid %d = %s", swork->sw_pidtype, in do_sigwork()
2124 (int)swork->sw_pid, swork->sw_fname); in do_sigwork()
2127 printf("Notified %s pid %d = %s\n", swork->sw_pidtype, in do_sigwork()
2128 (int)swork->sw_pid, swork->sw_fname); in do_sigwork()
2149 assert(zwork->zw_conf != NULL); in do_zipwork()
2150 assert(zwork->zw_conf->compress > COMPRESS_NONE); in do_zipwork()
2151 assert(zwork->zw_conf->compress < COMPRESS_TYPES); in do_zipwork()
2152 assert(zwork->zw_conf->compress != COMPRESS_LEGACY); in do_zipwork()
2154 if (zwork->zw_swork != NULL && zwork->zw_swork->sw_runcmd == 0 && in do_zipwork()
2155 zwork->zw_swork->sw_pidok <= 0) { in do_zipwork()
2158 zwork->zw_fname); in do_zipwork()
2159 change_attrs(zwork->zw_fname, zwork->zw_conf); in do_zipwork()
2163 ct = &compress_type[zwork->zw_conf->compress]; in do_zipwork()
2169 args = calloc(ct->nflags + 3, sizeof(*args)); in do_zipwork()
2173 pgm_path = ct->path; in do_zipwork()
2182 for (c = 0; c < ct->nflags; c++) in do_zipwork()
2183 args[c + 1] = ct->flags[c]; in do_zipwork()
2184 args[c + 1] = zwork->zw_fname; in do_zipwork()
2186 /* Also create a space-delimited version if we need to print it. */ in do_zipwork()
2194 if (sbuf_finish(command) == -1) in do_zipwork()
2198 asprintf(&zresult, "%s%s", zwork->zw_fname, ct->suffix); in do_zipwork()
2206 printf("\t%s %s\n", pgm_name, zwork->zw_fname); in do_zipwork()
2207 change_attrs(zresult, zwork->zw_conf); in do_zipwork()
2219 warn("fork() for `%s %s'", pgm_name, zwork->zw_fname); in do_zipwork()
2233 if (wpid == -1) { in do_zipwork()
2234 /* XXX - should this be a fatal error? */ in do_zipwork()
2243 warnx("`%s' terminated with a non-zero status (%d)", in do_zipwork()
2249 change_attrs(zresult, zwork->zw_conf); in do_zipwork()
2259 * process may need to be sent different signal-values for different
2260 * log files, but usually a single signal-value will cause the process
2261 * to close and re-open all of its log files.
2273 ndiff = strcmp(ent->pid_cmd_file, stmp->sw_fname); in save_sigwork()
2277 if (ent->sig == stmp->sw_signum) in save_sigwork()
2279 if (ent->sig > stmp->sw_signum) { in save_sigwork()
2289 tmpsiz = sizeof(struct sigwork_entry) + strlen(ent->pid_cmd_file) + 1; in save_sigwork()
2292 stmp->sw_runcmd = 0; in save_sigwork()
2294 if (ent->flags & CE_PID2CMD) { in save_sigwork()
2295 stmp->sw_pid = -1; in save_sigwork()
2296 stmp->sw_pidok = 0; in save_sigwork()
2297 stmp->sw_runcmd = 1; in save_sigwork()
2301 stmp->sw_signum = ent->sig; in save_sigwork()
2302 strcpy(stmp->sw_fname, ent->pid_cmd_file); in save_sigwork()
2313 * list itself is sorted smallest-to-largest, because that's the order we
2333 ndiff = strcmp(zipfname, ztmp->zw_fname); in save_zipwork()
2336 if (zsize > ztmp->zw_fsize) in save_zipwork()
2344 ztmp->zw_conf = ent; in save_zipwork()
2345 ztmp->zw_swork = swork; in save_zipwork()
2346 ztmp->zw_fsize = zsize; in save_zipwork()
2347 strcpy(ztmp->zw_fname, zipfname); in save_zipwork()
2365 swork->sw_pidok = 0; in set_swpid()
2366 swork->sw_pid = 0; in set_swpid()
2367 swork->sw_pidtype = "daemon"; in set_swpid()
2368 if (ent->flags & CE_SIGNALGROUP) { in set_swpid()
2370 * If we are expected to signal a process-group when in set_swpid()
2374 minok = -MAX_PID; in set_swpid()
2375 maxok = -MIN_PID; in set_swpid()
2376 swork->sw_pidtype = "process-group"; in set_swpid()
2379 f = fopen(ent->pid_cmd_file, "r"); in set_swpid()
2389 swork->sw_pidok = 1; in set_swpid()
2390 warnx("pid file doesn't exist: %s", ent->pid_cmd_file); in set_swpid()
2392 warn("can't open pid file: %s", ent->pid_cmd_file); in set_swpid()
2404 swork->sw_pidok = 1; in set_swpid()
2405 warnx("pid/cmd file is empty: %s", ent->pid_cmd_file); in set_swpid()
2407 warn("can't read from pid file: %s", ent->pid_cmd_file); in set_swpid()
2420 ent->pid_cmd_file); in set_swpid()
2423 rval, ent->pid_cmd_file); in set_swpid()
2428 swork->sw_pidok = 1; in set_swpid()
2429 swork->sw_pid = rval; in set_swpid()
2443 return (-1); in log_trim()
2445 if (log_ent->def_cfg) in log_trim()
2447 if (log_ent->flags & CE_RFC5424) { in log_trim()
2448 if (log_ent->firstcreate) { in log_trim()
2449 fprintf(f, "<%d>1 %s %s newsyslog %d - - %s%s\n", in log_trim()
2453 } else if (log_ent->r_reason != NULL) { in log_trim()
2454 fprintf(f, "<%d>1 %s %s newsyslog %d - - %s%s%s\n", in log_trim()
2457 "logfile turned over", log_ent->r_reason, xtra); in log_trim()
2459 fprintf(f, "<%d>1 %s %s newsyslog %d - - %s%s\n", in log_trim()
2465 if (log_ent->firstcreate) in log_trim()
2470 else if (log_ent->r_reason != NULL) in log_trim()
2474 log_ent->r_reason, xtra); in log_trim()
2493 return (-1); in sizefile()
2512 t = -1; in mtime_old_timelog()
2540 if (fstatat(dir_fd, dp->d_name, &sb, AT_SYMLINK_NOFOLLOW) == -1) { in mtime_old_timelog()
2605 if (mtime == -1) in age_old_log()
2606 return (-1); in age_old_log()
2611 return (-1); in age_old_log()
2614 return (-1); in age_old_log()
2618 return ((int)(ptimeget_secs(timenow) - mtime + 180) / 3600); in age_old_log()
2630 /* Skip Over Non-Blanks */
2665 * is the quick-and-easy way to do this. If that fails (which it will
2721 err(1, "Error on mkdir(\"%s\") for -a", in createdir()
2729 if (ent->firstcreate) in createdir()
2731 dirpart, ent->log); in createdir()
2733 printf("Created directory '%s' for -a\n", dirpart); in createdir()
2738 * Create a new log file, destroying any currently-existing version
2750 fd = -1; in createlog()
2751 realfile = ent->log; in createlog()
2754 * If this log file is being created for the first time (-C option), in createlog()
2758 if (ent->firstcreate) { in createlog()
2792 if (!(ent->flags & CE_BINARY)) { in createlog()
2799 if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1) { in createlog()
2801 printf("\tchown %u:%u %s\n", ent->uid, ent->gid, in createlog()
2804 failed = fchown(fd, ent->uid, ent->gid); in createlog()
2810 /* Turn on NODUMP if it was requested in the config-file. */ in createlog()
2811 if (ent->flags & CE_NODUMP) { in createlog()
2829 * XXX - ? It may be that for some error conditions, we could in createlog()
2833 printf("\tchmod %o %s\n", ent->permissions, tempfile); in createlog()
2836 failed = fchmod(fd, ent->permissions); in createlog()
2860 printf("\tchmod %o %s\n", ent->permissions, fname); in change_attrs()
2862 if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1) in change_attrs()
2864 ent->uid, ent->gid, fname); in change_attrs()
2866 if (ent->flags & CE_NODUMP) in change_attrs()
2871 failed = chmod(fname, ent->permissions); in change_attrs()
2878 if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1) { in change_attrs()
2879 failed = chown(fname, ent->uid, ent->gid); in change_attrs()
2884 if (ent->flags & CE_NODUMP) { in change_attrs()