version 1.64, 2003/04/25 20:07:09 |
version 1.65, 2003/05/15 03:25:02 |
|
|
|
|
/* |
/* |
* newsyslog - roll over selected logs at the appropriate time, |
* newsyslog - roll over selected logs at the appropriate time, |
* keeping the a specified number of backup files around. |
* keeping the specified number of backup files around. |
* |
* |
*/ |
*/ |
|
|
|
|
#include <unistd.h> |
#include <unistd.h> |
|
|
#define CE_ROTATED 0x01 /* Log file has been rotated */ |
#define CE_ROTATED 0x01 /* Log file has been rotated */ |
#define CE_COMPACT 0x02 /* Compact the achived log files */ |
#define CE_COMPACT 0x02 /* Compact the archived log files */ |
#define CE_BINARY 0x04 /* Logfile is in binary, don't add */ |
#define CE_BINARY 0x04 /* Logfile is in binary, don't add */ |
/* status messages */ |
/* status messages */ |
#define CE_MONITOR 0x08 /* Monitory for changes */ |
#define CE_MONITOR 0x08 /* Monitor for changes */ |
#define CE_FOLLOW 0x10 /* Follow symbolic links */ |
#define CE_FOLLOW 0x10 /* Follow symbolic links */ |
#define CE_TRIMAT 0x20 /* trim at a specific time */ |
#define CE_TRIMAT 0x20 /* Trim at a specific time */ |
|
|
#define MIN_PID 4 /* Don't touch pids lower than this */ |
#define MIN_PID 4 /* Don't touch pids lower than this */ |
#define MIN_SIZE 256 /* Don't rotate if smaller (in bytes) */ |
#define MIN_SIZE 256 /* Don't rotate if smaller (in bytes) */ |
|
|
int signal; /* Signal to send (defaults to SIGHUP) */ |
int signal; /* Signal to send (defaults to SIGHUP) */ |
int flags; /* Flags (CE_COMPACT & CE_BINARY) */ |
int flags; /* Flags (CE_COMPACT & CE_BINARY) */ |
char *whom; /* Whom to notify if logfile changes */ |
char *whom; /* Whom to notify if logfile changes */ |
char *pidfile; /* Path to file containg pid to signal */ |
char *pidfile; /* Path to file containing pid to signal */ |
char *runcmd; /* Command to run instead of sending a signal */ |
char *runcmd; /* Command to run instead of sending a signal */ |
struct conf_entry *next; /* Linked list pointer */ |
struct conf_entry *next; /* Linked list pointer */ |
}; |
}; |
|
|
int force = 0; /* Force the logs to be rotated */ |
int force = 0; /* Force the logs to be rotated */ |
char *conf = CONF; /* Configuration file to use */ |
char *conf = CONF; /* Configuration file to use */ |
time_t timenow; |
time_t timenow; |
char hostname[MAXHOSTNAMELEN]; /* hostname */ |
char hostname[MAXHOSTNAMELEN]; /* Hostname */ |
char *daytime; /* timenow in human readable form */ |
char *daytime; /* timenow in human readable form */ |
char *arcdir; /* dir to put archives in (if it exists) */ |
char *arcdir; /* Dir to put archives in (if it exists) */ |
|
|
void do_entry(struct conf_entry *); |
void do_entry(struct conf_entry *); |
void parse_args(int, char **); |
void parse_args(int, char **); |
|
|
DPRINTF(("--> will trim at %s", |
DPRINTF(("--> will trim at %s", |
ctime(&ent->trim_at))); |
ctime(&ent->trim_at))); |
return; |
return; |
} else if (verbose && ent->hours <= 0) { |
} else if (ent->hours <= 0) { |
DPRINTF(("--> time is up\n")); |
DPRINTF(("--> time is up\n")); |
} |
} |
} |
} |
|
|
/* Move down log files */ |
/* Move down log files */ |
while (numdays--) { |
while (numdays--) { |
/* |
/* |
* If both the compressed archive or the non-compressed archive |
* If both the compressed archive and the non-compressed archive |
* exist, we one or the other based on the CE_COMPACT flag. |
* exist, we decide which to rotate based on the CE_COMPACT flag. |
*/ |
*/ |
(void)snprintf(file1, sizeof(file1), "%s.%d", oldlog, numdays); |
(void)snprintf(file1, sizeof(file1), "%s.%d", oldlog, numdays); |
suffix = lstat_log(file1, sizeof(file1), ent->flags); |
suffix = lstat_log(file1, sizeof(file1), ent->flags); |
|
|
} |
} |
|
|
/* |
/* |
* lstat() a log, possibily appending a suffix; order is based on flags. |
* lstat() a log, possibly appending a suffix; order is based on flags. |
* Returns the suffix appended (may be empty string) or NULL if no file. |
* Returns the suffix appended (may be empty string) or NULL if no file. |
*/ |
*/ |
char * |
char * |