version 1.57, 2002/09/21 23:19:43 |
version 1.58, 2002/11/07 15:25:13 |
|
|
#define CE_FOLLOW 0x10 /* Follow symbolic links */ |
#define CE_FOLLOW 0x10 /* Follow symbolic links */ |
|
|
#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 512 /* Don't rotate if smaller than this */ |
#define MIN_SIZE 256 /* Don't rotate if smaller (in bytes) */ |
|
|
#define DPRINTF(x) do { if (verbose) printf x ; } while (0) |
#define DPRINTF(x) do { if (verbose) printf x ; } while (0) |
|
|
|
|
uid_t uid; /* Owner of log */ |
uid_t uid; /* Owner of log */ |
gid_t gid; /* Group of log */ |
gid_t gid; /* Group of log */ |
int numlogs; /* Number of logs to keep */ |
int numlogs; /* Number of logs to keep */ |
int size; /* Size cutoff to trigger trimming the log */ |
off_t size; /* Size cutoff to trigger trimming the log */ |
int hours; /* Hours between log trimming */ |
int hours; /* Hours between log trimming */ |
int permissions; /* File permissions on the log */ |
int permissions; /* File permissions on the log */ |
int signal; /* Signal to send (defaults to SIGHUP) */ |
int signal; /* Signal to send (defaults to SIGHUP) */ |
|
|
void dotrim(struct conf_entry *); |
void dotrim(struct conf_entry *); |
int log_trim(char *); |
int log_trim(char *); |
void compress_log(struct conf_entry *); |
void compress_log(struct conf_entry *); |
int sizefile(char *); |
off_t sizefile(char *); |
int age_old_log(struct conf_entry *); |
int age_old_log(struct conf_entry *); |
char *sob(char *); |
char *sob(char *); |
char *son(char *); |
char *son(char *); |
|
|
void |
void |
do_entry(struct conf_entry *ent) |
do_entry(struct conf_entry *ent) |
{ |
{ |
int modtime, size; |
int modtime; |
|
off_t size; |
struct stat sb; |
struct stat sb; |
|
|
if (lstat(ent->log, &sb) != 0) |
if (lstat(ent->log, &sb) != 0) |
|
|
DPRINTF(("does not exist.\n")); |
DPRINTF(("does not exist.\n")); |
} else { |
} else { |
if (ent->size > 0) |
if (ent->size > 0) |
DPRINTF(("size (Kb): %d [%d] ", size, ent->size)); |
DPRINTF(("size (KB): %.2f [%d] ", size / 1024.0, |
|
(int)(ent->size / 1024))); |
if (ent->hours > 0) |
if (ent->hours > 0) |
DPRINTF(("age (hr): %d [%d] ", modtime, ent->hours)); |
DPRINTF(("age (hr): %d [%d] ", modtime, ent->hours)); |
if (monitormode && ent->flags & CE_MONITOR) |
if (monitormode && ent->flags & CE_MONITOR) |
|
|
q = parse = missing_field(sob(++parse), errline); |
q = parse = missing_field(sob(++parse), errline); |
*(parse = son(parse)) = '\0'; |
*(parse = son(parse)) = '\0'; |
if (isdigit(*q)) |
if (isdigit(*q)) |
working->size = atoi(q); |
working->size = atoi(q) * 1024; |
else |
else |
working->size = -1; |
working->size = -1; |
|
|
|
|
} |
} |
|
|
/* Return size in kilobytes of a file */ |
/* Return size in kilobytes of a file */ |
int |
off_t |
sizefile(char *file) |
sizefile(char *file) |
{ |
{ |
struct stat sb; |
struct stat sb; |
|
|
if (stat(file, &sb) < 0) |
if (stat(file, &sb) < 0) |
return (-1); |
return (-1); |
return (sb.st_blocks / (1024.0 / DEV_BSIZE)); |
|
|
/* For sparse files, return the size based on number of blocks used. */ |
|
if (sb.st_size / DEV_BSIZE > sb.st_blocks) |
|
return (sb.st_blocks * DEV_BSIZE); |
|
else |
|
return (sb.st_size); |
} |
} |
|
|
/* Return the age (in hours) of old log file (file.0), or -1 if none */ |
/* Return the age (in hours) of old log file (file.0), or -1 if none */ |