version 1.8, 1997/01/15 23:42:56 |
version 1.9, 1997/04/27 13:48:55 |
|
|
#endif |
#endif |
|
|
#include <stdio.h> |
#include <stdio.h> |
|
#include <sys/types.h> |
|
#include <sys/time.h> |
|
#include <sys/stat.h> |
|
#include <sys/param.h> |
|
#include <sys/wait.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <signal.h> |
#include <signal.h> |
|
#include <fcntl.h> |
#include <pwd.h> |
#include <pwd.h> |
#include <grp.h> |
#include <grp.h> |
#include <sys/types.h> |
#include <unistd.h> |
#include <sys/time.h> |
|
#include <sys/stat.h> |
|
#include <sys/param.h> |
|
#include <sys/wait.h> |
|
|
|
#define kbytes(size) (((size) + 1023) >> 10) |
#define kbytes(size) (((size) + 1023) >> 10) |
#ifdef _IBMR2 |
|
/* Calculates (db * DEV_BSIZE) */ |
|
#define dbtob(db) ((unsigned)(db) << UBSHIFT) |
|
#endif |
|
|
|
#define CE_COMPACT 1 /* Compact the achived log files */ |
#define CE_COMPACT 1 /* Compact the achived log files */ |
#define CE_BINARY 2 /* Logfile is in binary, don't add */ |
#define CE_BINARY 2 /* Logfile is in binary, don't add */ |
|
|
struct conf_entry *next; /* Linked list pointer */ |
struct conf_entry *next; /* Linked list pointer */ |
}; |
}; |
|
|
extern int optind; |
|
extern char *optarg; |
|
extern char *malloc(); |
|
extern uid_t getuid(),geteuid(); |
|
extern time_t time(); |
|
|
|
char *progname; /* contains argv[0] */ |
char *progname; /* contains argv[0] */ |
int verbose = 0; /* Print out what's going on */ |
int verbose = 0; /* Print out what's going on */ |
int needroot = 1; /* Root privs are necessary */ |
int needroot = 1; /* Root privs are necessary */ |
|
|
char *daytime; /* timenow in human readable form */ |
char *daytime; /* timenow in human readable form */ |
|
|
|
|
struct conf_entry *parse_file(); |
void do_entry __P((struct conf_entry *)); |
char *sob(), *son(), *strdup(), *missing_field(); |
void PRS __P((int, char **)); |
|
void usage __P((void)); |
|
struct conf_entry *parse_file __P((void)); |
|
char *missing_field __P((char *, char *)); |
|
void dotrim __P((char *, int, int, int, int, int)); |
|
int log_trim __P((char *)); |
|
void compress_log __P((char *)); |
|
int sizefile __P((char *)); |
|
int age_old_log __P((char *)); |
|
char *sob __P((char *)); |
|
char *son __P((char *)); |
|
int isnumber __P((char *)); |
|
|
main(argc,argv) |
int main(argc, argv) |
int argc; |
int argc; |
char **argv; |
char **argv; |
{ |
{ |
|
|
exit(0); |
exit(0); |
} |
} |
|
|
do_entry(ent) |
void do_entry(ent) |
struct conf_entry *ent; |
struct conf_entry *ent; |
|
|
{ |
{ |
|
|
} |
} |
} |
} |
|
|
PRS(argc,argv) |
void PRS(argc, argv) |
int argc; |
int argc; |
char **argv; |
char **argv; |
{ |
{ |
|
|
(void) gethostname(hostname, sizeof(hostname)); |
(void) gethostname(hostname, sizeof(hostname)); |
|
|
/* Truncate domain */ |
/* Truncate domain */ |
if (p = strchr(hostname, '.')) { |
p = strchr(hostname, '.'); |
|
if (p) |
*p = '\0'; |
*p = '\0'; |
} |
|
|
|
optind = 1; /* Start options parsing */ |
optind = 1; /* Start options parsing */ |
while ((c = getopt(argc,argv,"nrvf:t:")) != -1) |
while ((c = getopt(argc,argv,"nrvf:t:")) != -1) { |
switch (c) { |
switch (c) { |
case 'n': |
case 'n': |
noaction++; /* This implies needroot as off */ |
noaction++; /* This implies needroot as off */ |
|
|
usage(); |
usage(); |
} |
} |
} |
} |
|
} |
|
|
usage() |
void usage() |
{ |
{ |
fprintf(stderr, |
fprintf(stderr, |
"Usage: %s <-nrv> <-f config-file>\n", progname); |
"Usage: %s <-nrv> <-f config-file>\n", progname); |
|
|
return(first); |
return(first); |
} |
} |
|
|
char *missing_field(p,errline) |
char *missing_field(p, errline) |
char *p,*errline; |
char *p,*errline; |
{ |
{ |
if (!p || !*p) { |
if (!p || !*p) { |
|
|
return(p); |
return(p); |
} |
} |
|
|
dotrim(log,numdays,flags,perm,owner_uid,group_gid) |
void dotrim(log, numdays, flags, perm, owner_uid, group_gid) |
char *log; |
char *log; |
int numdays; |
int numdays; |
int flags; |
int flags; |
|
|
struct stat st; |
struct stat st; |
int days = numdays; |
int days = numdays; |
|
|
#ifdef _IBMR2 |
|
/* AIX 3.1 has a broken fchown- if the owner_uid is -1, it will actually */ |
|
/* change it to be owned by uid -1, instead of leaving it as is, as it is */ |
|
/* supposed to. */ |
|
if (owner_uid == -1) |
|
owner_uid = geteuid(); |
|
#endif |
|
|
|
/* Remove oldest log */ |
/* Remove oldest log */ |
(void) sprintf(file1,"%s.%d",log,numdays); |
(void) sprintf(file1,"%s.%d",log,numdays); |
(void) strcpy(zfile1, file1); |
(void) strcpy(zfile1, file1); |
|
|
} |
} |
|
|
/* Log the fact that the logs were turned over */ |
/* Log the fact that the logs were turned over */ |
log_trim(log) |
int log_trim(log) |
char *log; |
char *log; |
{ |
{ |
FILE *f; |
FILE *f; |
|
|
} |
} |
|
|
/* Fork of /usr/ucb/compress to compress the old log file */ |
/* Fork of /usr/ucb/compress to compress the old log file */ |
compress_log(log) |
void compress_log(log) |
char *log; |
char *log; |
{ |
{ |
int pid; |
int pid; |
|
|
return( (int) (timenow - sb.st_mtime + 1800) / 3600); |
return( (int) (timenow - sb.st_mtime + 1800) / 3600); |
} |
} |
|
|
|
|
#ifndef OSF |
|
/* Duplicate a string using malloc */ |
|
|
|
char *strdup(strp) |
|
register char *strp; |
|
{ |
|
register char *cp; |
|
|
|
if ((cp = malloc((unsigned) strlen(strp) + 1)) == NULL) |
|
abort(); |
|
return(strcpy (cp, strp)); |
|
} |
|
#endif |
|
|
|
/* Skip Over Blanks */ |
/* Skip Over Blanks */ |
char *sob(p) |
char *sob(p) |
register char *p; |
register char *p; |
|
|
|
|
/* Check if string is actually a number */ |
/* Check if string is actually a number */ |
|
|
isnumber(string) |
int isnumber(string) |
char *string; |
char *string; |
{ |
{ |
while (*string != '\0') { |
while (*string != '\0') { |
if (*string < '0' || *string > '9') return(0); |
if (!isdigit(*string++)) |
string++; |
return(0); |
} |
} |
return(1); |
return(1); |
} |
} |