modernize:

- make crash() called atexit
	- use err/errx
	- remove __P
This commit is contained in:
christos 2015-05-09 21:44:47 +00:00
parent a409b95d7f
commit 8cde9e3d9b
6 changed files with 48 additions and 60 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: rpc_main.c,v 1.39 2013/12/15 09:18:31 wiz Exp $ */ /* $NetBSD: rpc_main.c,v 1.40 2015/05/09 21:44:47 christos Exp $ */
/* /*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@ -39,7 +39,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI"; static char sccsid[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI";
#else #else
__RCSID("$NetBSD: rpc_main.c,v 1.39 2013/12/15 09:18:31 wiz Exp $"); __RCSID("$NetBSD: rpc_main.c,v 1.40 2015/05/09 21:44:47 christos Exp $");
#endif #endif
#endif #endif
@ -128,6 +128,7 @@ int logflag; /* Use syslog instead of fprintf for errors */
int tblflag; /* Support for dispatch table file */ int tblflag; /* Support for dispatch table file */
int BSDflag; /* use BSD cplusplus macros */ int BSDflag; /* use BSD cplusplus macros */
int callerflag; /* Generate svc_caller() function */ int callerflag; /* Generate svc_caller() function */
int docleanup = 1; /* cause atexit to remove files */
#define INLINE 3 #define INLINE 3
/*length at which to start doing an inline */ /*length at which to start doing an inline */
@ -187,6 +188,7 @@ main(int argc, char *argv[])
(void) memset((char *) &cmd, 0, sizeof(struct commandline)); (void) memset((char *) &cmd, 0, sizeof(struct commandline));
clear_args(); clear_args();
atexit(crash);
if (!parseargs(argc, argv, &cmd)) if (!parseargs(argc, argv, &cmd))
usage(); usage();
@ -255,6 +257,7 @@ main(int argc, char *argv[])
(void) unlink(dos_cppfile); (void) unlink(dos_cppfile);
} }
#endif #endif
docleanup = 0;
exit(nonfatalerrors); exit(nonfatalerrors);
/* NOTREACHED */ /* NOTREACHED */
} }
@ -297,15 +300,11 @@ open_output(const char *infile, const char *outfile)
return; return;
} }
if (infile != NULL && streq(outfile, infile)) { if (infile != NULL && streq(outfile, infile)) {
f_print(stderr, "%s: output would overwrite %s\n", cmdname, errx(EXIT_FAILURE, "output would overwrite `%s'", infile);
infile);
crash();
} }
fout = fopen(outfile, "w"); fout = fopen(outfile, "w");
if (fout == NULL) { if (fout == NULL) {
f_print(stderr, "%s: unable to open ", cmdname); err(EXIT_FAILURE, "Can't to open `%s'", outfile);
perror(outfile);
crash();
} }
record_open(outfile); record_open(outfile);
@ -360,22 +359,18 @@ open_input(const char *infile, const char *define)
retval = spawnvp(P_WAIT, arglist[0], arglist); retval = spawnvp(P_WAIT, arglist[0], arglist);
if (retval != 0) { if (retval != 0) {
fprintf(stderr, "%s: C PreProcessor failed\n", cmdname); err(EXIT_FAILURE, "C PreProcessor failed");
crash();
} }
fnsplit(infile, drive, dir, name, ext); fnsplit(infile, drive, dir, name, ext);
fnmerge(cppfile, drive, dir, name, ".i"); fnmerge(cppfile, drive, dir, name, ".i");
fin = fopen(cppfile, "r"); fin = fopen(cppfile, "r");
if (fin == NULL) { if (fin == NULL) {
f_print(stderr, "%s: ", cmdname); err(EXIT_FAILURE, "Can't open `%s'", cppfile);
perror(cppfile);
crash();
} }
dos_cppfile = strdup(cppfile); dos_cppfile = strdup(cppfile);
if (dos_cppfile == NULL) { if (dos_cppfile == NULL) {
fprintf(stderr, "%s: out of memory\n", cmdname); err(EXIT_FAILURE, "Can't copy `%s'", cppfile);
crash();
} }
} }
#else #else
@ -391,17 +386,15 @@ open_input(const char *infile, const char *define)
(void) dup2(pd[1], 1); (void) dup2(pd[1], 1);
(void) close(pd[0]); (void) close(pd[0]);
execvp(arglist[0], __UNCONST(arglist)); execvp(arglist[0], __UNCONST(arglist));
err(1, "$RPCGEN_CPP: %s", CPP); err(EXIT_FAILURE, "$RPCGEN_CPP: %s", CPP);
case -1: case -1:
err(1, "fork"); err(EXIT_FAILURE, "fork");
} }
(void) close(pd[1]); (void) close(pd[1]);
fin = fdopen(pd[0], "r"); fin = fdopen(pd[0], "r");
#endif #endif
if (fin == NULL) { if (fin == NULL) {
f_print(stderr, "%s: ", cmdname); err(EXIT_FAILURE, "Can't open `%s'", infilename);
perror(infilename);
crash();
} }
} }
/* valid tirpc nettypes */ /* valid tirpc nettypes */
@ -543,7 +536,7 @@ h_output(const char *infile, const char *define, int extend,
else { else {
guard = strdup("STDIN_"); guard = strdup("STDIN_");
if (guard == NULL) { if (guard == NULL) {
err(1, "strdup"); err(EXIT_FAILURE, "strdup");
} }
} }
@ -608,6 +601,7 @@ s_output(int argc, char *argv[], char *infile,
f_print(fout, "#include <sys/ioctl.h>\n"); f_print(fout, "#include <sys/ioctl.h>\n");
f_print(fout, "#include <fcntl.h>\n"); f_print(fout, "#include <fcntl.h>\n");
f_print(fout, "#include <stdio.h>\n"); f_print(fout, "#include <stdio.h>\n");
f_print(fout, "#include <err.h>\n");
f_print(fout, "#include <stdlib.h>\n"); f_print(fout, "#include <stdlib.h>\n");
f_print(fout, "#include <unistd.h>\n"); f_print(fout, "#include <unistd.h>\n");
f_print(fout, "#include <rpc/pmap_clnt.h>\n"); f_print(fout, "#include <rpc/pmap_clnt.h>\n");
@ -780,6 +774,7 @@ clnt_output(const char *infile, const char *define, int extend,
open_output(infile, outfilename); open_output(infile, outfilename);
add_sample_msg(); add_sample_msg();
f_print(fout, "#include <stdio.h>\n"); f_print(fout, "#include <stdio.h>\n");
f_print(fout, "#include <err.h>\n");
if (infile && (include = extendfile(infile, ".h"))) { if (infile && (include = extendfile(infile, ".h"))) {
f_print(fout, "#include \"%s\"\n", include); f_print(fout, "#include \"%s\"\n", include);
free(include); free(include);
@ -837,8 +832,7 @@ static void
addarg(const char *cp) addarg(const char *cp)
{ {
if (argcount >= ARGLISTLEN) { if (argcount >= ARGLISTLEN) {
f_print(stderr, "rpcgen: too many defines\n"); errx(EXIT_FAILURE, "too many defines");
crash();
/* NOTREACHED */ /* NOTREACHED */
} }
arglist[argcount++] = cp; arglist[argcount++] = cp;
@ -849,8 +843,7 @@ static void
putarg(int pwhere, const char *cp) putarg(int pwhere, const char *cp)
{ {
if (pwhere >= ARGLISTLEN) { if (pwhere >= ARGLISTLEN) {
f_print(stderr, "rpcgen: arglist coding error\n"); errx(EXIT_FAILURE, "arglist coding error");
crash();
/* NOTREACHED */ /* NOTREACHED */
} }
arglist[pwhere] = cp; arglist[pwhere] = cp;
@ -870,17 +863,15 @@ checkfiles(const char *infile, const char *outfile)
if (infile) /* infile ! = NULL */ if (infile) /* infile ! = NULL */
if (stat(infile, &buf) < 0) { if (stat(infile, &buf) < 0) {
perror(infile); err(EXIT_FAILURE, "Can't stat `%s'", infile);
crash();
}; };
#if 0 #if 0
if (outfile) { if (outfile) {
if (stat(outfile, &buf) < 0) if (stat(outfile, &buf) < 0)
return; /* file does not exist */ return; /* file does not exist */
else { else {
f_print(stderr, errx("`%s' already exists and may be overwritten",
"file '%s' already exists and may be overwritten\n", outfile); outfile);
crash();
} }
} }
#endif #endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: rpc_parse.h,v 1.5 2013/08/11 08:03:10 dholland Exp $ */ /* $NetBSD: rpc_parse.h,v 1.6 2015/05/09 21:44:47 christos Exp $ */
/* /*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape * unrestricted use provided that this legend is included on all tape
@ -156,7 +156,7 @@ struct definition {
}; };
typedef struct definition definition; typedef struct definition definition;
definition *get_definition __P((void)); definition *get_definition(void);
struct bas_type struct bas_type
{ {

View File

@ -1,4 +1,4 @@
/* $NetBSD: rpc_scan.h,v 1.9 2013/08/11 08:03:10 dholland Exp $ */ /* $NetBSD: rpc_scan.h,v 1.10 2015/05/09 21:44:47 christos Exp $ */
/* /*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape * unrestricted use provided that this legend is included on all tape
@ -99,10 +99,10 @@ typedef struct token token;
/* /*
* routine interface * routine interface
*/ */
void scan __P((tok_kind, token *)); void scan(tok_kind, token *);
void scan2 __P((tok_kind, tok_kind, token *)); void scan2(tok_kind, tok_kind, token *);
void scan3 __P((tok_kind, tok_kind, tok_kind, token *)); void scan3(tok_kind, tok_kind, tok_kind, token *);
void scan_num __P((token *)); void scan_num(token *);
void peek __P((token *)); void peek(token *);
int peekscan __P((tok_kind, token *)); int peekscan(tok_kind, token *);
void get_token __P((token *)); void get_token(token *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: rpc_svcout.c,v 1.28 2015/05/09 18:48:14 dholland Exp $ */ /* $NetBSD: rpc_svcout.c,v 1.29 2015/05/09 21:44:47 christos Exp $ */
/* /*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape * unrestricted use provided that this legend is included on all tape
@ -38,7 +38,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)rpc_svcout.c 1.29 89/03/30 (C) 1987 SMI"; static char sccsid[] = "@(#)rpc_svcout.c 1.29 89/03/30 (C) 1987 SMI";
#else #else
__RCSID("$NetBSD: rpc_svcout.c,v 1.28 2015/05/09 18:48:14 dholland Exp $"); __RCSID("$NetBSD: rpc_svcout.c,v 1.29 2015/05/09 21:44:47 christos Exp $");
#endif #endif
#endif #endif
@ -812,19 +812,15 @@ write_rpc_svc_fg(char *infile, const char *sp)
f_print(fout, "%sint pid, i;\n\n", sp); f_print(fout, "%sint pid, i;\n\n", sp);
f_print(fout, "%spid = fork();\n", sp); f_print(fout, "%spid = fork();\n", sp);
f_print(fout, "%sif (pid < 0) {\n", sp); f_print(fout, "%sif (pid < 0) {\n", sp);
f_print(fout, "%s\tperror(\"cannot fork\");\n", sp); f_print(fout, "%s\terr(EXIT_FAILURE, \"cannot fork\");\n", sp);
f_print(fout, "%s\texit(1);\n", sp);
f_print(fout, "%s}\n", sp); f_print(fout, "%s}\n", sp);
f_print(fout, "%sif (pid)\n", sp); f_print(fout, "%sif (pid)\n", sp);
f_print(fout, "%s\texit(0);\n", sp); f_print(fout, "%s\texit(0);\n", sp);
/* get number of file descriptors */ /* get number of file descriptors */
if (tirpcflag) { if (tirpcflag) {
f_print(fout, "%srl.rlim_max = 0;\n", sp); f_print(fout, "%srl.rlim_max = 0;\n", sp);
f_print(fout, "%sif (getrlimit(RLIMIT_NOFILE, &rl) == -1) {\n", f_print(fout, "%sif (getrlimit(RLIMIT_NOFILE, &rl) == -1)\n", sp);
sp); f_print(fout, "%s\terr(EXIT_FAILURE, \"getrlimit(RLIMIT_NOFILE)\");\n", sp);
f_print(fout, "%s\tperror(\"getrlimit\");\n", sp);
f_print(fout, "%s\texit(1);\n", sp);
f_print(fout, "%s}\n", sp);
f_print(fout, "%sif ((size = rl.rlim_max) == 0)\n", sp); f_print(fout, "%sif ((size = rl.rlim_max) == 0)\n", sp);
f_print(fout, "%s\texit(1);\n", sp); f_print(fout, "%s\texit(1);\n", sp);
} else { } else {

View File

@ -1,4 +1,4 @@
/* $NetBSD: rpc_util.c,v 1.13 2013/12/15 00:40:17 christos Exp $ */ /* $NetBSD: rpc_util.c,v 1.14 2015/05/09 21:44:47 christos Exp $ */
/* /*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape * unrestricted use provided that this legend is included on all tape
@ -38,7 +38,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI"; static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI";
#else #else
__RCSID("$NetBSD: rpc_util.c,v 1.13 2013/12/15 00:40:17 christos Exp $"); __RCSID("$NetBSD: rpc_util.c,v 1.14 2015/05/09 21:44:47 christos Exp $");
#endif #endif
#endif #endif
@ -49,6 +49,7 @@ __RCSID("$NetBSD: rpc_util.c,v 1.13 2013/12/15 00:40:17 christos Exp $");
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <err.h>
#include <ctype.h> #include <ctype.h>
#include "rpc_scan.h" #include "rpc_scan.h"
#include "rpc_parse.h" #include "rpc_parse.h"
@ -257,9 +258,7 @@ void
error(const char *msg) error(const char *msg)
{ {
printwhere(); printwhere();
f_print(stderr, "%s, line %d: ", infilename, linenum); errx(EXIT_FAILURE, "%s, line %d: %s", infilename, linenum, msg);
f_print(stderr, "%s\n", msg);
crash();
} }
/* /*
* Something went wrong, unlink any files that we may have created and then * Something went wrong, unlink any files that we may have created and then
@ -270,10 +269,12 @@ crash(void)
{ {
int i; int i;
if (!docleanup)
return;
for (i = 0; i < nfiles; i++) { for (i = 0; i < nfiles; i++) {
(void) unlink(outfiles[i]); (void) unlink(outfiles[i]);
} }
exit(1);
} }
void void
@ -282,8 +283,7 @@ record_open(const char *file)
if (nfiles < NFILES) { if (nfiles < NFILES) {
outfiles[nfiles++] = file; outfiles[nfiles++] = file;
} else { } else {
f_print(stderr, "too many files!\n"); errx(EXIT_FAILURE, "too many files!");
crash();
} }
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: rpc_util.h,v 1.8 2013/12/15 00:40:17 christos Exp $ */ /* $NetBSD: rpc_util.h,v 1.9 2015/05/09 21:44:47 christos Exp $ */
/* /*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape * unrestricted use provided that this legend is included on all tape
@ -57,6 +57,7 @@ typedef struct list list;
extern char curline[MAXLINESIZE]; extern char curline[MAXLINESIZE];
extern char *where; extern char *where;
extern int linenum; extern int linenum;
extern int docleanup;
extern const char *infilename; extern const char *infilename;
extern FILE *fout; extern FILE *fout;
@ -113,8 +114,8 @@ int isvectordef(const char *, relation);
char *locase(const char *); char *locase(const char *);
void pvname_svc(const char *, const char *); void pvname_svc(const char *, const char *);
void pvname(const char *, const char *); void pvname(const char *, const char *);
void error(const char *) __dead; void error(const char *);
void crash(void) __dead; void crash(void);
void record_open(const char *); void record_open(const char *);
void expected1(tok_kind) __dead; void expected1(tok_kind) __dead;
void expected2(tok_kind, tok_kind) __dead; void expected2(tok_kind, tok_kind) __dead;