Lines Matching +full:sig +full:- +full:dir +full:- +full:cmd

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 */
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 */
188 int sig; /* Signal to send */ member
199 char sw_fname[1]; /* file the PID was read from or shell cmd */
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 rotatereq = 0; /* -R = Always rotate the file(s) as given */
248 static char *requestor; /* The name given on a -R request */
257 struct ptime_data *dbg_timenow; /* A "timenow" value set via -D option */
258 static struct ptime_data *timenow; /* The time to use for checking at-fields */
262 * used for rotation-tracking messages. */
266 * rotation-tracking messages written by newsyslog and so are not accounted for
269 #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 = SIGHUP; 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:c:d:f:nrst:vCD:FNPR:S:")) != -1) in parse_args()
779 warnx("Only one of -F and -N may be specified."); in parse_args()
786 warnx("At least one filename must be given when -R is specified."); in parse_args()
814 * as writing regression-tests. They would not be needed by users
823 if (strncmp(doption, TN, sizeof(TN) - 1) == 0) { in parse_doption()
830 time(NULL), doption + sizeof(TN) - 1); in parse_doption()
831 if (res == -2) { in parse_doption()
832 warnx("Non-existent time specified on -D %s", doption); in parse_doption()
835 warnx("Malformed time given on -D %s", doption); in parse_doption()
847 /* XXX - This check could probably be dropped. */ in parse_doption()
854 warnx("Unknown -D (debug) option: '%s'", doption); in parse_doption()
877 "usage: newsyslog [-CFNPnrsv] [-a directory] [-c %s]\n" in usage()
878 " [-d directory] [-f config_file]\n" in usage()
879 " [-S pidfile] [-t timefmt] [[-R tagname] file ...]\n", in usage()
914 inc->file = conf; in get_worklist()
915 if (inc->file == NULL) in get_worklist()
916 inc->file = _PATH_CONF; in get_worklist()
920 if (strcmp(inc->file, "-") != 0) in get_worklist()
921 f = fopen(inc->file, "r"); in get_worklist()
924 inc->file = "<stdin>"; in get_worklist()
927 err(1, "%s", inc->file); in get_worklist()
930 printf("Processing %s\n", inc->file); in get_worklist()
936 * All config-file information has been read in and turned into in get_worklist()
954 * rotation action. First, create the default-rotation action in get_worklist()
959 defconf->numlogs = 3; in get_worklist()
960 defconf->trsize = 50; in get_worklist()
961 defconf->permissions = S_IRUSR|S_IWUSR; in get_worklist()
967 * it, picking up the rotation-rules for those files from in get_worklist()
970 * XXX - Note that this will copy multiple rules for a single in get_worklist()
983 * First try to find exact-matches for this given file. in get_worklist()
987 if (strcmp(ent->log, *given) == 0) { in get_worklist()
1000 * There was no exact-match for this given file, so look in get_worklist()
1007 fnres = fnmatch(ent->log, *given, FNM_PATHNAME); in get_worklist()
1010 ent->log); in get_worklist()
1015 dupent->flags &= ~CE_GLOB; in get_worklist()
1017 /* Only allow a match to one glob-entry */ in get_worklist()
1024 ent->log); in get_worklist()
1037 dupent->def_cfg = 1; in get_worklist()
1055 * which match those glob-entries onto the worklist.
1068 * The worklist contains all fully-specified (non-GLOB) names. in expand_globs()
1070 * Now expand the list of filename-pattern (GLOB) entries into in expand_globs()
1072 * that already exist. Do not add a glob-related entry for any in expand_globs()
1073 * file which already exists in the fully-specified list. in expand_globs()
1076 gres = glob(globent->log, GLOB_NOCHECK, NULL, &pglob); in expand_globs()
1079 globent->log); in expand_globs()
1084 printf("\t+ Expanding pattern %s\n", globent->log); in expand_globs()
1091 if (strcmp(mfname, ent->log) == 0) { in expand_globs()
1103 warn("Skipping %s - lstat() error", mfname); in expand_globs()
1118 dupent->flags &= ~CE_GLOB; in expand_globs()
1125 printf("\t+ Done with pattern %s\n", globent->log); in expand_globs()
1157 if (*(cp - 1) == '\\') { in parse_file()
1158 strcpy(cp - 1, cp); in parse_file()
1159 cp--; in parse_file()
1283 working->uid = pwd->pw_uid; in parse_file()
1285 working->uid = atoi(q); in parse_file()
1287 working->uid = (uid_t)-1; in parse_file()
1296 working->gid = grp->gr_gid; in parse_file()
1298 working->gid = atoi(q); in parse_file()
1300 working->gid = (gid_t)-1; in parse_file()
1309 working->uid = (uid_t)-1; in parse_file()
1310 working->gid = (gid_t)-1; in parse_file()
1313 if (!sscanf(q, "%o", &working->permissions)) in parse_file()
1316 if ((working->permissions & ~DEFFILEMODE) != 0) { in parse_file()
1318 working->permissions, in parse_file()
1319 working->permissions & DEFFILEMODE, errline); in parse_file()
1320 working->permissions &= DEFFILEMODE; in parse_file()
1329 if (!sscanf(q, "%d", &working->numlogs) || working->numlogs < 0) in parse_file()
1340 char last_digit = q[strlen(q) - 1]; in parse_file()
1342 working->trsize = atoi(q); in parse_file()
1346 working->trsize = trsize / 1024; in parse_file()
1348 working->trsize = -1; in parse_file()
1354 working->trsize = -1; in parse_file()
1358 working->trsize = -1; in parse_file()
1361 working->flags = 0; in parse_file()
1362 working->compress = COMPRESS_NONE; in parse_file()
1373 working->hours = 0; in parse_file()
1375 working->hours = -1; in parse_file()
1379 working->hours = ul; in parse_file()
1386 working->flags |= CE_TRIMAT; in parse_file()
1387 working->trim_at = ptime_init(NULL); in parse_file()
1392 res = ptime_relparse(working->trim_at, ptm_opts, in parse_file()
1394 if (res == -2) in parse_file()
1415 working->flags |= CE_BINARY; in parse_file()
1418 working->flags |= CE_CREATE; in parse_file()
1421 working->flags |= CE_NODUMP; in parse_file()
1424 working->flags |= CE_NOEMPTY; in parse_file()
1427 working->flags |= CE_GLOB; in parse_file()
1431 working->compress = COMPRESS_BZIP2; in parse_file()
1433 working->compress = compress_type_override; in parse_file()
1437 working->flags |= CE_NOSIGNAL; in parse_file()
1440 working->flags |= CE_PLAIN0; in parse_file()
1443 working->flags |= CE_PID2CMD; in parse_file()
1446 working->flags |= CE_RFC5424; in parse_file()
1449 working->flags |= CE_SIGNALGROUP; in parse_file()
1452 /* Deprecated flag - keep for compatibility purposes */ in parse_file()
1456 working->compress = COMPRESS_XZ; in parse_file()
1458 working->compress = compress_type_override; in parse_file()
1463 working->compress = COMPRESS_ZSTD; in parse_file()
1465 working->compress = compress_type_override; in parse_file()
1470 working->compress = COMPRESS_GZIP; in parse_file()
1472 working->compress = compress_type_override; in parse_file()
1475 case '-': in parse_file()
1480 badline("illegal flag in config file -- %c", in parse_file()
1495 working->pid_cmd_file = NULL; in parse_file()
1498 working->pid_cmd_file = strdup(q); in parse_file()
1515 working->sig = SIGHUP; in parse_file()
1518 working->sig = parse_signal(q); in parse_file()
1519 if (working->sig < 1 || working->sig >= sys_nsig) { in parse_file()
1527 * Finish figuring out what pid-file to use (if any) in in parse_file()
1530 if ((working->flags & CE_NOSIGNAL) == CE_NOSIGNAL) { in parse_file()
1532 * This config-entry specified 'n' for nosignal, in parse_file()
1536 if (working->pid_cmd_file != NULL) { in parse_file()
1538 working->pid_cmd_file, errline); in parse_file()
1539 free(working->pid_cmd_file); in parse_file()
1540 working->pid_cmd_file = NULL; in parse_file()
1542 } else if (working->pid_cmd_file == NULL) { in parse_file()
1546 * specified some other pid-file (and obviously the in parse_file()
1547 * syslog pid-file will not be for a process-group). in parse_file()
1551 if (working->flags & CE_SIGNALGROUP) { in parse_file()
1554 working->flags &= ~CE_SIGNALGROUP; in parse_file()
1557 working->pid_cmd_file = strdup(path_syslogpid); in parse_file()
1566 } else if (working->flags & CE_GLOB) { in parse_file()
1601 if (ola->t > olb->t) in oldlog_entry_compare()
1602 return (-1); in oldlog_entry_compare()
1603 else if (ola->t < olb->t) in oldlog_entry_compare()
1625 if (dp->d_type != DT_REG) { in validate_old_timelog()
1631 if (dp->d_type != DT_UNKNOWN || in validate_old_timelog()
1632 fstatat(fd, dp->d_name, &sb, AT_SYMLINK_NOFOLLOW) != 0 || in validate_old_timelog()
1637 if (strncmp(dp->d_name, logfname, logfname_len) != 0) in validate_old_timelog()
1639 /* Ignore the actual non-rotated logfile. */ in validate_old_timelog()
1640 if (dp->d_namlen == logfname_len) in validate_old_timelog()
1647 if (dp->d_name[logfname_len] != '.') { in validate_old_timelog()
1650 "extension '%s'\n", dp->d_name, in validate_old_timelog()
1651 &dp->d_name[logfname_len]); in validate_old_timelog()
1655 if ((s = strptime(&dp->d_name[logfname_len + 1], in validate_old_timelog()
1665 "match time format\n", dp->d_name); in validate_old_timelog()
1676 dp->d_name, s); in validate_old_timelog()
1688 const char *base, *dir; in delete_oldest_timelog() local
1693 DIR *dirp; in delete_oldest_timelog()
1701 dir = archive_dir; in delete_oldest_timelog()
1703 if ((dirbuf = strdup(ent->log)) == NULL) in delete_oldest_timelog()
1705 dir = dirname(dirbuf); in delete_oldest_timelog()
1708 if ((basebuf = strdup(ent->log)) == NULL) in delete_oldest_timelog()
1712 errx(1, "Invalid log filename - became '/'"); in delete_oldest_timelog()
1715 printf("Searching for old logs in %s\n", dir); in delete_oldest_timelog()
1718 if ((dirp = opendir(dir)) == NULL) in delete_oldest_timelog()
1719 err(1, "Cannot open log directory '%s'", dir); in delete_oldest_timelog()
1729 if ((oldlogs[logcnt].t = timegm(&tm)) == -1) in delete_oldest_timelog()
1731 if ((oldlogs[logcnt].fname = strdup(dp->d_name)) == NULL) in delete_oldest_timelog()
1753 if (logcnt > 0 && logcnt >= ent->numlogs && ent->numlogs > 1) { in delete_oldest_timelog()
1766 for (i = ent->numlogs - 1; i < logcnt; i++) { in delete_oldest_timelog()
1768 printf("\trm -f %s/%s\n", dir, in delete_oldest_timelog()
1778 printf("No old logs to delete for logfile %s\n", ent->log); in delete_oldest_timelog()
1822 printf("\trm -f %s\n", zfile1); in delete_classiclog()
1838 if (strcmp(fname, inc->file) == 0) { in add_to_queue()
1847 inc->file = strdup(fname); in add_to_queue()
1857 * The suffix detection is first-match in the order of compress_types
1860 * a zero-length string is returned
1893 flags = ent->flags; in do_rotate()
1904 strlcpy(dirpart, ent->log, sizeof(dirpart)); in do_rotate()
1917 if ((p = strrchr(ent->log, '/')) == NULL) in do_rotate()
1918 strlcpy(namepart, ent->log, sizeof(namepart)); in do_rotate()
1924 * dir. in do_rotate()
1927 strlcpy(namepart, ent->log, sizeof(namepart)); in do_rotate()
1936 * kept ent->numlogs + 1 files. This code can go away in do_rotate()
1939 delete_classiclog(dirpart, namepart, ent->numlogs); in do_rotate()
1941 if (ent->numlogs > 0) in do_rotate()
1942 delete_classiclog(dirpart, namepart, ent->numlogs - 1); in do_rotate()
1948 if (time(&now) == (time_t)-1 || in do_rotate()
1958 ent->log, datetimestr); in do_rotate()
1961 numlogs_c = -1; in do_rotate()
1964 ent->numlogs - 1); in do_rotate()
1965 numlogs_c = ent->numlogs - 2; /* copy for countdown */ in do_rotate()
1969 for (; numlogs_c >= 0; numlogs_c--) { in do_rotate()
1986 /* XXX - Ought to be checking for failure! */ in do_rotate()
1990 if (ent->compress && strlen(logfile_suffix) == 0) { in do_rotate()
2000 zwork->zw_conf = ent; in do_rotate()
2001 zwork->zw_fsize = sizefile(zfile2); in do_rotate()
2002 strcpy(zwork->zw_fname, zfile2); in do_rotate()
2008 if (ent->numlogs > 0) { in do_rotate()
2017 printf("\tcp %s %s\n", ent->log, file1); in do_rotate()
2019 printf("\tln %s %s\n", ent->log, file1); in do_rotate()
2021 "# Update mtime for 'when'-interval processing\n", in do_rotate()
2026 log_trim(ent->log, ent); in do_rotate()
2028 savelog(ent->log, file1); in do_rotate()
2030 * Interval-based rotations are done using the mtime of in do_rotate()
2045 * Save all signalling and file-compression to be done after log in do_rotate()
2051 if (ent->pid_cmd_file != NULL) in do_rotate()
2053 if (ent->numlogs > 0 && ent->compress > COMPRESS_NONE) { in do_rotate()
2054 if (!(ent->flags & CE_PLAIN0) || in do_rotate()
2055 strcmp(&file1[strlen(file1) - 2], ".0") != 0) { in do_rotate()
2061 save_zipwork(ent, swork, ent->fsize, file1); in do_rotate()
2075 if (swork->sw_runcmd == 0 && (!(swork->sw_pidok) || swork->sw_pid == 0)) in do_sigwork()
2079 * If nosignal (-s) was specified, then do not signal any process. in do_sigwork()
2081 * rotated logfile needs to be compressed, *unless* -R was also in do_sigwork()
2082 * specified. We assume that an `-sR' request came from a process in do_sigwork()
2085 * just sets swork->sw_pidok to a special value, and do_zipwork in do_sigwork()
2090 swork->sw_pidok = -1; in do_sigwork()
2097 * daemon or process-group. in do_sigwork()
2102 if (swork->sw_pid == nextsig->sw_pid) in do_sigwork()
2109 if (swork->sw_runcmd) in do_sigwork()
2110 printf("\tsh -c '%s %d'\n", swork->sw_fname, in do_sigwork()
2111 swork->sw_signum); in do_sigwork()
2113 printf("\tkill -%d %d \t\t# %s\n", swork->sw_signum, in do_sigwork()
2114 (int)swork->sw_pid, swork->sw_fname); in do_sigwork()
2121 if (swork->sw_runcmd) { in do_sigwork()
2122 asprintf(&tmp, "%s %d", swork->sw_fname, swork->sw_signum); in do_sigwork()
2125 swork->sw_fname); in do_sigwork()
2132 warnx("%s: returned non-zero exit code: %d", in do_sigwork()
2139 kres = kill(swork->sw_pid, swork->sw_signum); in do_sigwork()
2149 swork->sw_pidok = 0; in do_sigwork()
2150 warn("can't notify %s, pid %d = %s", swork->sw_pidtype, in do_sigwork()
2151 (int)swork->sw_pid, swork->sw_fname); in do_sigwork()
2154 printf("Notified %s pid %d = %s\n", swork->sw_pidtype, in do_sigwork()
2155 (int)swork->sw_pid, swork->sw_fname); in do_sigwork()
2176 assert(zwork->zw_conf != NULL); in do_zipwork()
2177 assert(zwork->zw_conf->compress > COMPRESS_NONE); in do_zipwork()
2178 assert(zwork->zw_conf->compress < COMPRESS_TYPES); in do_zipwork()
2179 assert(zwork->zw_conf->compress != COMPRESS_LEGACY); in do_zipwork()
2181 if (zwork->zw_swork != NULL && zwork->zw_swork->sw_runcmd == 0 && in do_zipwork()
2182 zwork->zw_swork->sw_pidok <= 0) { in do_zipwork()
2185 zwork->zw_fname); in do_zipwork()
2186 change_attrs(zwork->zw_fname, zwork->zw_conf); in do_zipwork()
2190 ct = &compress_type[zwork->zw_conf->compress]; in do_zipwork()
2196 args = calloc(ct->nflags + 3, sizeof(*args)); in do_zipwork()
2200 pgm_path = ct->path; in do_zipwork()
2209 for (c = 0; c < ct->nflags; c++) in do_zipwork()
2210 args[c + 1] = ct->flags[c]; in do_zipwork()
2211 args[c + 1] = zwork->zw_fname; in do_zipwork()
2213 /* Also create a space-delimited version if we need to print it. */ in do_zipwork()
2221 if (sbuf_finish(command) == -1) in do_zipwork()
2225 asprintf(&zresult, "%s%s", zwork->zw_fname, ct->suffix); in do_zipwork()
2233 printf("\t%s %s\n", pgm_name, zwork->zw_fname); in do_zipwork()
2234 change_attrs(zresult, zwork->zw_conf); in do_zipwork()
2246 warn("fork() for `%s %s'", pgm_name, zwork->zw_fname); in do_zipwork()
2260 if (wpid == -1) { in do_zipwork()
2261 /* XXX - should this be a fatal error? */ in do_zipwork()
2270 warnx("`%s' terminated with a non-zero status (%d)", in do_zipwork()
2276 change_attrs(zresult, zwork->zw_conf); in do_zipwork()
2286 * process may need to be sent different signal-values for different
2287 * log files, but usually a single signal-value will cause the process
2288 * to close and re-open all of its log files.
2300 ndiff = strcmp(ent->pid_cmd_file, stmp->sw_fname); in save_sigwork()
2304 if (ent->sig == stmp->sw_signum) in save_sigwork()
2306 if (ent->sig > stmp->sw_signum) { in save_sigwork()
2316 tmpsiz = sizeof(struct sigwork_entry) + strlen(ent->pid_cmd_file) + 1; in save_sigwork()
2319 stmp->sw_runcmd = 0; in save_sigwork()
2321 if (ent->flags & CE_PID2CMD) { in save_sigwork()
2322 stmp->sw_pid = -1; in save_sigwork()
2323 stmp->sw_pidok = 0; in save_sigwork()
2324 stmp->sw_runcmd = 1; in save_sigwork()
2328 stmp->sw_signum = ent->sig; in save_sigwork()
2329 strcpy(stmp->sw_fname, ent->pid_cmd_file); in save_sigwork()
2340 * list itself is sorted smallest-to-largest, because that's the order we
2360 ndiff = strcmp(zipfname, ztmp->zw_fname); in save_zipwork()
2363 if (zsize > ztmp->zw_fsize) in save_zipwork()
2371 ztmp->zw_conf = ent; in save_zipwork()
2372 ztmp->zw_swork = swork; in save_zipwork()
2373 ztmp->zw_fsize = zsize; in save_zipwork()
2374 strcpy(ztmp->zw_fname, zipfname); in save_zipwork()
2392 swork->sw_pidok = 0; in set_swpid()
2393 swork->sw_pid = 0; in set_swpid()
2394 swork->sw_pidtype = "daemon"; in set_swpid()
2395 if (ent->flags & CE_SIGNALGROUP) { in set_swpid()
2397 * If we are expected to signal a process-group when in set_swpid()
2401 minok = -MAX_PID; in set_swpid()
2402 maxok = -MIN_PID; in set_swpid()
2403 swork->sw_pidtype = "process-group"; in set_swpid()
2406 f = fopen(ent->pid_cmd_file, "r"); in set_swpid()
2416 swork->sw_pidok = 1; in set_swpid()
2417 warnx("pid file doesn't exist: %s", ent->pid_cmd_file); in set_swpid()
2419 warn("can't open pid file: %s", ent->pid_cmd_file); in set_swpid()
2431 swork->sw_pidok = 1; in set_swpid()
2432 warnx("pid/cmd file is empty: %s", ent->pid_cmd_file); in set_swpid()
2434 warn("can't read from pid file: %s", ent->pid_cmd_file); in set_swpid()
2447 ent->pid_cmd_file); in set_swpid()
2450 rval, ent->pid_cmd_file); in set_swpid()
2455 swork->sw_pidok = 1; in set_swpid()
2456 swork->sw_pid = rval; in set_swpid()
2470 return (-1); in log_trim()
2472 if (log_ent->def_cfg) in log_trim()
2474 if (log_ent->flags & CE_RFC5424) { in log_trim()
2475 if (log_ent->firstcreate) { in log_trim()
2476 fprintf(f, "<%d>1 %s %s newsyslog %d - - %s%s\n", in log_trim()
2480 } else if (log_ent->r_reason != NULL) { in log_trim()
2481 fprintf(f, "<%d>1 %s %s newsyslog %d - - %s%s%s\n", in log_trim()
2484 "logfile turned over", log_ent->r_reason, xtra); in log_trim()
2486 fprintf(f, "<%d>1 %s %s newsyslog %d - - %s%s\n", in log_trim()
2492 if (log_ent->firstcreate) in log_trim()
2497 else if (log_ent->r_reason != NULL) in log_trim()
2501 log_ent->r_reason, xtra); in log_trim()
2520 return (-1); in sizefile()
2536 DIR *dirp; in mtime_old_timelog()
2537 char *logfname, *logfnamebuf, *dir, *dirbuf; in mtime_old_timelog() local
2539 t = -1; in mtime_old_timelog()
2545 dir = dirname(dirbuf); in mtime_old_timelog()
2557 if ((dirp = opendir(dir)) == NULL) { in mtime_old_timelog()
2558 warn("Cannot open log directory '%s'", dir); in mtime_old_timelog()
2562 /* Open the archive dir and find the most recent archive of logfname. */ in mtime_old_timelog()
2567 if (fstatat(dir_fd, dp->d_name, &sb, AT_SYMLINK_NOFOLLOW) == -1) { in mtime_old_timelog()
2632 if (mtime == -1) in age_old_log()
2633 return (-1); in age_old_log()
2638 return (-1); in age_old_log()
2641 return (-1); in age_old_log()
2645 return ((int)(ptimeget_secs(timenow) - mtime + 1800) / 3600); in age_old_log()
2657 /* Skip Over Non-Blanks */
2692 * is the quick-and-easy way to do this. If that fails (which it will
2748 err(1, "Error on mkdir(\"%s\") for -a", in createdir()
2756 if (ent->firstcreate) in createdir()
2758 dirpart, ent->log); in createdir()
2760 printf("Created directory '%s' for -a\n", dirpart); in createdir()
2765 * Create a new log file, destroying any currently-existing version
2777 fd = -1; in createlog()
2778 realfile = ent->log; in createlog()
2781 * If this log file is being created for the first time (-C option), in createlog()
2785 if (ent->firstcreate) { in createlog()
2819 if (!(ent->flags & CE_BINARY)) { in createlog()
2826 if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1) { in createlog()
2828 printf("\tchown %u:%u %s\n", ent->uid, ent->gid, in createlog()
2831 failed = fchown(fd, ent->uid, ent->gid); in createlog()
2837 /* Turn on NODUMP if it was requested in the config-file. */ in createlog()
2838 if (ent->flags & CE_NODUMP) { in createlog()
2856 * XXX - ? It may be that for some error conditions, we could in createlog()
2860 printf("\tchmod %o %s\n", ent->permissions, tempfile); in createlog()
2863 failed = fchmod(fd, ent->permissions); in createlog()
2887 printf("\tchmod %o %s\n", ent->permissions, fname); in change_attrs()
2889 if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1) in change_attrs()
2891 ent->uid, ent->gid, fname); in change_attrs()
2893 if (ent->flags & CE_NODUMP) in change_attrs()
2898 failed = chmod(fname, ent->permissions); in change_attrs()
2905 if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1) { in change_attrs()
2906 failed = chown(fname, ent->uid, ent->gid); in change_attrs()
2911 if (ent->flags & CE_NODUMP) { in change_attrs()
2919 * Parse a signal number or signal name. Returns the signal number parsed or -1
2925 int sig, i; in parse_signal() local
2928 sig = strtonum(str, 1, sys_nsig - 1, &errstr); in parse_signal()
2931 return (sig); in parse_signal()
2932 if (strncasecmp(str, "SIG", 3) == 0) in parse_signal()
2940 return (-1); in parse_signal()