Deleted Added
full compact
newsyslog.c (233257) newsyslog.c (235647)
1/*-
2 * ------+---------+---------+-------- + --------+---------+---------+---------*
3 * This file includes significant modifications done by:
4 * Copyright (c) 2003, 2004 - Garance Alistair Drosehn <gad@FreeBSD.org>.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 40 unchanged lines hidden (view full) ---

49 */
50
51/*
52 * newsyslog - roll over selected logs at the appropriate time, keeping the a
53 * specified number of backup files around.
54 */
55
56#include <sys/cdefs.h>
1/*-
2 * ------+---------+---------+-------- + --------+---------+---------+---------*
3 * This file includes significant modifications done by:
4 * Copyright (c) 2003, 2004 - Garance Alistair Drosehn <gad@FreeBSD.org>.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 40 unchanged lines hidden (view full) ---

49 */
50
51/*
52 * newsyslog - roll over selected logs at the appropriate time, keeping the a
53 * specified number of backup files around.
54 */
55
56#include <sys/cdefs.h>
57__FBSDID("$FreeBSD: head/usr.sbin/newsyslog/newsyslog.c 233257 2012-03-21 06:51:45Z glebius $");
57__FBSDID("$FreeBSD: head/usr.sbin/newsyslog/newsyslog.c 235647 2012-05-19 12:44:27Z gleb $");
58
59#define OSF
60
61#include <sys/param.h>
62#include <sys/queue.h>
63#include <sys/stat.h>
64#include <sys/wait.h>
65

--- 1380 unchanged lines hidden (view full) ---

1446
1447/*
1448 * Delete the oldest logfiles, when using time based filenames.
1449 */
1450static void
1451delete_oldest_timelog(const struct conf_entry *ent, const char *archive_dir)
1452{
1453 char *logfname, *s, *dir, errbuf[80];
58
59#define OSF
60
61#include <sys/param.h>
62#include <sys/queue.h>
63#include <sys/stat.h>
64#include <sys/wait.h>
65

--- 1380 unchanged lines hidden (view full) ---

1446
1447/*
1448 * Delete the oldest logfiles, when using time based filenames.
1449 */
1450static void
1451delete_oldest_timelog(const struct conf_entry *ent, const char *archive_dir)
1452{
1453 char *logfname, *s, *dir, errbuf[80];
1454 int dirfd, i, logcnt, max_logcnt, valid;
1454 int dir_fd, i, logcnt, max_logcnt, valid;
1455 struct oldlog_entry *oldlogs;
1456 size_t logfname_len;
1457 struct dirent *dp;
1458 const char *cdir;
1459 struct tm tm;
1460 DIR *dirp;
1461 int c;
1462

--- 18 unchanged lines hidden (view full) ---

1481 errx(1, "Invalid log filename - became '/'");
1482
1483 if (verbose > 2)
1484 printf("Searching for old logs in %s\n", dir);
1485
1486 /* First we create a 'list' of all archived logfiles */
1487 if ((dirp = opendir(dir)) == NULL)
1488 err(1, "Cannot open log directory '%s'", dir);
1455 struct oldlog_entry *oldlogs;
1456 size_t logfname_len;
1457 struct dirent *dp;
1458 const char *cdir;
1459 struct tm tm;
1460 DIR *dirp;
1461 int c;
1462

--- 18 unchanged lines hidden (view full) ---

1481 errx(1, "Invalid log filename - became '/'");
1482
1483 if (verbose > 2)
1484 printf("Searching for old logs in %s\n", dir);
1485
1486 /* First we create a 'list' of all archived logfiles */
1487 if ((dirp = opendir(dir)) == NULL)
1488 err(1, "Cannot open log directory '%s'", dir);
1489 dirfd = dirfd(dirp);
1489 dir_fd = dirfd(dirp);
1490 while ((dp = readdir(dirp)) != NULL) {
1491 if (dp->d_type != DT_REG)
1492 continue;
1493
1494 /* Ignore everything but files with our logfile prefix */
1495 if (strncmp(dp->d_name, logfname, logfname_len) != 0)
1496 continue;
1497 /* Ignore the actual non-rotated logfile */

--- 75 unchanged lines hidden (view full) ---

1573 * number of records we want to keep.
1574 */
1575 qsort(oldlogs, logcnt, sizeof(struct oldlog_entry),
1576 oldlog_entry_compare);
1577 for (i = ent->numlogs - 1; i < logcnt; i++) {
1578 if (noaction)
1579 printf("\trm -f %s/%s\n", dir,
1580 oldlogs[i].fname);
1490 while ((dp = readdir(dirp)) != NULL) {
1491 if (dp->d_type != DT_REG)
1492 continue;
1493
1494 /* Ignore everything but files with our logfile prefix */
1495 if (strncmp(dp->d_name, logfname, logfname_len) != 0)
1496 continue;
1497 /* Ignore the actual non-rotated logfile */

--- 75 unchanged lines hidden (view full) ---

1573 * number of records we want to keep.
1574 */
1575 qsort(oldlogs, logcnt, sizeof(struct oldlog_entry),
1576 oldlog_entry_compare);
1577 for (i = ent->numlogs - 1; i < logcnt; i++) {
1578 if (noaction)
1579 printf("\trm -f %s/%s\n", dir,
1580 oldlogs[i].fname);
1581 else if (unlinkat(dirfd, oldlogs[i].fname, 0) != 0) {
1581 else if (unlinkat(dir_fd, oldlogs[i].fname, 0) != 0) {
1582 snprintf(errbuf, sizeof(errbuf),
1583 "Could not delet old logfile '%s'",
1584 oldlogs[i].fname);
1585 perror(errbuf);
1586 }
1587 }
1588 } else if (verbose > 1)
1589 printf("No old logs to delete for logfile %s\n", ent->log);

--- 968 unchanged lines hidden ---
1582 snprintf(errbuf, sizeof(errbuf),
1583 "Could not delet old logfile '%s'",
1584 oldlogs[i].fname);
1585 perror(errbuf);
1586 }
1587 }
1588 } else if (verbose > 1)
1589 printf("No old logs to delete for logfile %s\n", ent->log);

--- 968 unchanged lines hidden ---