WARNSify, fix .Nm usage, getopt returns -1 not EOF
This commit is contained in:
parent
0c67cce512
commit
6c49a51bc6
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: newsyslog.c,v 1.12 1996/09/27 01:56:56 thorpej Exp $ */
|
||||
/* $NetBSD: newsyslog.c,v 1.13 1997/10/19 06:23:50 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* This file contains changes from the Open Software Foundation.
|
||||
|
@ -27,8 +27,9 @@ provided "as is" without express or implied warranty.
|
|||
* keeping the a specified number of backup files around.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$NetBSD: newsyslog.c,v 1.12 1996/09/27 01:56:56 thorpej Exp $";
|
||||
__RCSID("$NetBSD: newsyslog.c,v 1.13 1997/10/19 06:23:50 lukem Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef CONF
|
||||
|
@ -44,19 +45,22 @@ static char rcsid[] = "$NetBSD: newsyslog.c,v 1.12 1996/09/27 01:56:56 thorpej E
|
|||
#define COMPRESS_POSTFIX ".Z"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define kbytes(size) (((size) + 1023) >> 10)
|
||||
#ifdef _IBMR2
|
||||
/* Calculates (db * DEV_BSIZE) */
|
||||
|
@ -80,12 +84,6 @@ struct conf_entry {
|
|||
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] */
|
||||
int verbose = 0; /* Print out what's going on */
|
||||
int needroot = 1; /* Root privs are necessary */
|
||||
|
@ -99,9 +97,22 @@ char hostname[64]; /* hostname */
|
|||
char *daytime; /* timenow in human readable form */
|
||||
|
||||
|
||||
struct conf_entry *parse_file();
|
||||
char *sob(), *son(), *strdup(), *missing_field();
|
||||
void PRS __P((int, char **));
|
||||
int age_old_log __P((char *));
|
||||
void compress_log __P((char *));
|
||||
void dotrim __P((char *, int, int, int, int, int));
|
||||
void do_entry __P((struct conf_entry *));
|
||||
int isnumber __P((char *));
|
||||
int log_trim __P((char *));
|
||||
int main __P((int, char **));
|
||||
char *missing_field __P((char *, char *));
|
||||
struct conf_entry *parse_file __P((void));
|
||||
int sizefile __P((char *));
|
||||
char *sob __P((char *));
|
||||
char *son __P((char *));
|
||||
void usage __P((void));
|
||||
|
||||
int
|
||||
main(argc,argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
|
@ -123,9 +134,9 @@ main(argc,argv)
|
|||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
do_entry(ent)
|
||||
struct conf_entry *ent;
|
||||
|
||||
{
|
||||
int size, modtime;
|
||||
|
||||
|
@ -167,6 +178,7 @@ do_entry(ent)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
PRS(argc,argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
|
@ -193,12 +205,12 @@ PRS(argc,argv)
|
|||
(void) gethostname(hostname, sizeof(hostname));
|
||||
|
||||
/* Truncate domain */
|
||||
if (p = strchr(hostname, '.')) {
|
||||
if ((p = strchr(hostname, '.')) != NULL) {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
optind = 1; /* Start options parsing */
|
||||
while ((c=getopt(argc,argv,"nrvf:t:")) != EOF)
|
||||
while ((c=getopt(argc,argv,"nrvf:t:")) != -1)
|
||||
switch (c) {
|
||||
case 'n':
|
||||
noaction++; /* This implies needroot as off */
|
||||
|
@ -215,8 +227,9 @@ PRS(argc,argv)
|
|||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr,
|
||||
|
@ -227,7 +240,8 @@ usage()
|
|||
/* Parse a configuration file and return a linked list of all the logs
|
||||
* to process
|
||||
*/
|
||||
struct conf_entry *parse_file()
|
||||
struct conf_entry *
|
||||
parse_file()
|
||||
{
|
||||
FILE *f;
|
||||
char line[BUFSIZ], *parse, *q;
|
||||
|
@ -237,6 +251,7 @@ struct conf_entry *parse_file()
|
|||
struct passwd *pass;
|
||||
struct group *grp;
|
||||
|
||||
working = NULL;
|
||||
if (strcmp(conf,"-"))
|
||||
f = fopen(conf,"r");
|
||||
else
|
||||
|
@ -356,7 +371,8 @@ struct conf_entry *parse_file()
|
|||
return(first);
|
||||
}
|
||||
|
||||
char *missing_field(p,errline)
|
||||
char *
|
||||
missing_field(p,errline)
|
||||
char *p,*errline;
|
||||
{
|
||||
if (!p || !*p) {
|
||||
|
@ -367,6 +383,7 @@ char *missing_field(p,errline)
|
|||
return(p);
|
||||
}
|
||||
|
||||
void
|
||||
dotrim(log,numdays,flags,perm,owner_uid,group_gid)
|
||||
char *log;
|
||||
int numdays;
|
||||
|
@ -480,6 +497,7 @@ dotrim(log,numdays,flags,perm,owner_uid,group_gid)
|
|||
}
|
||||
|
||||
/* Log the fact that the logs were turned over */
|
||||
int
|
||||
log_trim(log)
|
||||
char *log;
|
||||
{
|
||||
|
@ -496,6 +514,7 @@ log_trim(log)
|
|||
}
|
||||
|
||||
/* Fork of /usr/ucb/compress to compress the old log file */
|
||||
void
|
||||
compress_log(log)
|
||||
char *log;
|
||||
{
|
||||
|
@ -517,7 +536,8 @@ compress_log(log)
|
|||
}
|
||||
|
||||
/* Return size in kilobytes of a file */
|
||||
int sizefile(file)
|
||||
int
|
||||
sizefile(file)
|
||||
char *file;
|
||||
{
|
||||
struct stat sb;
|
||||
|
@ -528,7 +548,8 @@ int sizefile(file)
|
|||
}
|
||||
|
||||
/* Return the age of old log file (file.0) */
|
||||
int age_old_log(file)
|
||||
int
|
||||
age_old_log(file)
|
||||
char *file;
|
||||
{
|
||||
struct stat sb;
|
||||
|
@ -545,10 +566,11 @@ int age_old_log(file)
|
|||
#ifndef OSF
|
||||
/* Duplicate a string using malloc */
|
||||
|
||||
char *strdup(strp)
|
||||
register char *strp;
|
||||
char *
|
||||
strdup(strp)
|
||||
char *strp;
|
||||
{
|
||||
register char *cp;
|
||||
char *cp;
|
||||
|
||||
if ((cp = malloc((unsigned) strlen(strp) + 1)) == NULL)
|
||||
abort();
|
||||
|
@ -558,7 +580,7 @@ register char *strp;
|
|||
|
||||
/* Skip Over Blanks */
|
||||
char *sob(p)
|
||||
register char *p;
|
||||
char *p;
|
||||
{
|
||||
while (p && *p && isspace(*p))
|
||||
p++;
|
||||
|
@ -566,8 +588,9 @@ char *sob(p)
|
|||
}
|
||||
|
||||
/* Skip Over Non-Blanks */
|
||||
char *son(p)
|
||||
register char *p;
|
||||
char *
|
||||
son(p)
|
||||
char *p;
|
||||
{
|
||||
while (p && *p && !isspace(*p))
|
||||
p++;
|
||||
|
@ -577,8 +600,9 @@ char *son(p)
|
|||
|
||||
/* Check if string is actually a number */
|
||||
|
||||
int
|
||||
isnumber(string)
|
||||
char *string;
|
||||
char *string;
|
||||
{
|
||||
while (*string != '\0') {
|
||||
if (*string < '0' || *string > '9') return(0);
|
||||
|
|
Loading…
Reference in New Issue