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
@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI";
#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
@ -128,6 +128,7 @@ int logflag; /* Use syslog instead of fprintf for errors */
int tblflag; /* Support for dispatch table file */
int BSDflag; /* use BSD cplusplus macros */
int callerflag; /* Generate svc_caller() function */
int docleanup = 1; /* cause atexit to remove files */
#define INLINE 3
/*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));
clear_args();
atexit(crash);
if (!parseargs(argc, argv, &cmd))
usage();
@ -255,6 +257,7 @@ main(int argc, char *argv[])
(void) unlink(dos_cppfile);
}
#endif
docleanup = 0;
exit(nonfatalerrors);
/* NOTREACHED */
}
@ -297,15 +300,11 @@ open_output(const char *infile, const char *outfile)
return;
}
if (infile != NULL && streq(outfile, infile)) {
f_print(stderr, "%s: output would overwrite %s\n", cmdname,
infile);
crash();
errx(EXIT_FAILURE, "output would overwrite `%s'", infile);
}
fout = fopen(outfile, "w");
if (fout == NULL) {
f_print(stderr, "%s: unable to open ", cmdname);
perror(outfile);
crash();
err(EXIT_FAILURE, "Can't to open `%s'", outfile);
}
record_open(outfile);
@ -360,22 +359,18 @@ open_input(const char *infile, const char *define)
retval = spawnvp(P_WAIT, arglist[0], arglist);
if (retval != 0) {
fprintf(stderr, "%s: C PreProcessor failed\n", cmdname);
crash();
err(EXIT_FAILURE, "C PreProcessor failed");
}
fnsplit(infile, drive, dir, name, ext);
fnmerge(cppfile, drive, dir, name, ".i");
fin = fopen(cppfile, "r");
if (fin == NULL) {
f_print(stderr, "%s: ", cmdname);
perror(cppfile);
crash();
err(EXIT_FAILURE, "Can't open `%s'", cppfile);
}
dos_cppfile = strdup(cppfile);
if (dos_cppfile == NULL) {
fprintf(stderr, "%s: out of memory\n", cmdname);
crash();
err(EXIT_FAILURE, "Can't copy `%s'", cppfile);
}
}
#else
@ -391,17 +386,15 @@ open_input(const char *infile, const char *define)
(void) dup2(pd[1], 1);
(void) close(pd[0]);
execvp(arglist[0], __UNCONST(arglist));
err(1, "$RPCGEN_CPP: %s", CPP);
err(EXIT_FAILURE, "$RPCGEN_CPP: %s", CPP);
case -1:
err(1, "fork");
err(EXIT_FAILURE, "fork");
}
(void) close(pd[1]);
fin = fdopen(pd[0], "r");
#endif
if (fin == NULL) {
f_print(stderr, "%s: ", cmdname);
perror(infilename);
crash();
err(EXIT_FAILURE, "Can't open `%s'", infilename);
}
}
/* valid tirpc nettypes */
@ -543,7 +536,7 @@ h_output(const char *infile, const char *define, int extend,
else {
guard = strdup("STDIN_");
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 <fcntl.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 <unistd.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);
add_sample_msg();
f_print(fout, "#include <stdio.h>\n");
f_print(fout, "#include <err.h>\n");
if (infile && (include = extendfile(infile, ".h"))) {
f_print(fout, "#include \"%s\"\n", include);
free(include);
@ -837,8 +832,7 @@ static void
addarg(const char *cp)
{
if (argcount >= ARGLISTLEN) {
f_print(stderr, "rpcgen: too many defines\n");
crash();
errx(EXIT_FAILURE, "too many defines");
/* NOTREACHED */
}
arglist[argcount++] = cp;
@ -849,8 +843,7 @@ static void
putarg(int pwhere, const char *cp)
{
if (pwhere >= ARGLISTLEN) {
f_print(stderr, "rpcgen: arglist coding error\n");
crash();
errx(EXIT_FAILURE, "arglist coding error");
/* NOTREACHED */
}
arglist[pwhere] = cp;
@ -870,17 +863,15 @@ checkfiles(const char *infile, const char *outfile)
if (infile) /* infile ! = NULL */
if (stat(infile, &buf) < 0) {
perror(infile);
crash();
err(EXIT_FAILURE, "Can't stat `%s'", infile);
};
#if 0
if (outfile) {
if (stat(outfile, &buf) < 0)
return; /* file does not exist */
else {
f_print(stderr,
"file '%s' already exists and may be overwritten\n", outfile);
crash();
errx("`%s' already exists and may be overwritten",
outfile);
}
}
#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
* unrestricted use provided that this legend is included on all tape
@ -156,7 +156,7 @@ struct definition {
};
typedef struct definition definition;
definition *get_definition __P((void));
definition *get_definition(void);
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
* unrestricted use provided that this legend is included on all tape
@ -99,10 +99,10 @@ typedef struct token token;
/*
* routine interface
*/
void scan __P((tok_kind, token *));
void scan2 __P((tok_kind, tok_kind, token *));
void scan3 __P((tok_kind, tok_kind, tok_kind, token *));
void scan_num __P((token *));
void peek __P((token *));
int peekscan __P((tok_kind, token *));
void get_token __P((token *));
void scan(tok_kind, token *);
void scan2(tok_kind, tok_kind, token *);
void scan3(tok_kind, tok_kind, tok_kind, token *);
void scan_num(token *);
void peek(token *);
int peekscan(tok_kind, 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
* unrestricted use provided that this legend is included on all tape
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)rpc_svcout.c 1.29 89/03/30 (C) 1987 SMI";
#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
@ -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, "%spid = fork();\n", sp);
f_print(fout, "%sif (pid < 0) {\n", sp);
f_print(fout, "%s\tperror(\"cannot fork\");\n", sp);
f_print(fout, "%s\texit(1);\n", sp);
f_print(fout, "%s\terr(EXIT_FAILURE, \"cannot fork\");\n", sp);
f_print(fout, "%s}\n", sp);
f_print(fout, "%sif (pid)\n", sp);
f_print(fout, "%s\texit(0);\n", sp);
/* get number of file descriptors */
if (tirpcflag) {
f_print(fout, "%srl.rlim_max = 0;\n", sp);
f_print(fout, "%sif (getrlimit(RLIMIT_NOFILE, &rl) == -1) {\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 (getrlimit(RLIMIT_NOFILE, &rl) == -1)\n", sp);
f_print(fout, "%s\terr(EXIT_FAILURE, \"getrlimit(RLIMIT_NOFILE)\");\n", sp);
f_print(fout, "%sif ((size = rl.rlim_max) == 0)\n", sp);
f_print(fout, "%s\texit(1);\n", sp);
} 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
* unrestricted use provided that this legend is included on all tape
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI";
#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
@ -49,6 +49,7 @@ __RCSID("$NetBSD: rpc_util.c,v 1.13 2013/12/15 00:40:17 christos Exp $");
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <err.h>
#include <ctype.h>
#include "rpc_scan.h"
#include "rpc_parse.h"
@ -257,9 +258,7 @@ void
error(const char *msg)
{
printwhere();
f_print(stderr, "%s, line %d: ", infilename, linenum);
f_print(stderr, "%s\n", msg);
crash();
errx(EXIT_FAILURE, "%s, line %d: %s", infilename, linenum, msg);
}
/*
* Something went wrong, unlink any files that we may have created and then
@ -270,10 +269,12 @@ crash(void)
{
int i;
if (!docleanup)
return;
for (i = 0; i < nfiles; i++) {
(void) unlink(outfiles[i]);
}
exit(1);
}
void
@ -282,8 +283,7 @@ record_open(const char *file)
if (nfiles < NFILES) {
outfiles[nfiles++] = file;
} else {
f_print(stderr, "too many files!\n");
crash();
errx(EXIT_FAILURE, "too many files!");
}
}

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
* 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 *where;
extern int linenum;
extern int docleanup;
extern const char *infilename;
extern FILE *fout;
@ -113,8 +114,8 @@ int isvectordef(const char *, relation);
char *locase(const char *);
void pvname_svc(const char *, const char *);
void pvname(const char *, const char *);
void error(const char *) __dead;
void crash(void) __dead;
void error(const char *);
void crash(void);
void record_open(const char *);
void expected1(tok_kind) __dead;
void expected2(tok_kind, tok_kind) __dead;