version 1.14, 2002/06/12 06:07:16 |
version 1.15, 2002/07/05 05:39:42 |
|
|
char _errbuf[256]; /* For all messages */ |
char _errbuf[256]; /* For all messages */ |
|
|
void internal_proctype(proc_list *); |
void internal_proctype(proc_list *); |
static write_real_program(definition *); |
static void write_real_program(definition *); |
static write_program(definition *, char *); |
static void write_program(definition *, char *); |
static printerr(char *, char *); |
static void printerr(char *, char *); |
static printif(char *, char *, char *, char *); |
static void printif(char *, char *, char *, char *); |
static write_inetmost(char *); |
static void write_inetmost(char *); |
static print_return(char *); |
static void print_return(char *); |
static print_pmapunset(char *); |
static void print_pmapunset(char *); |
static print_err_message(char *); |
static void print_err_message(char *); |
static write_timeout_func(void); |
static void write_timeout_func(void); |
static write_pm_most(char *, int); |
static void write_pm_most(char *, int); |
static write_caller_func(void); |
static void write_caller_func(void); |
static write_rpc_svc_fg(char *, char *); |
static void write_rpc_svc_fg(char *, char *); |
static open_log_file(char *, char *); |
static void write_msg_out(); |
|
static void open_log_file(char *, char *); |
|
int nullproc(proc_list *proc); |
|
|
static |
static void |
p_xdrfunc(rname, typename) |
p_xdrfunc(rname, typename) |
char *rname; |
char *rname; |
char *typename; |
char *typename; |
|
|
int nomain; |
int nomain; |
{ |
{ |
if (inetdflag || pmflag) { |
if (inetdflag || pmflag) { |
char *var_type; |
char *var_type; |
var_type = (nomain? "extern" : "static"); |
var_type = (nomain? "extern" : "static"); |
fprintf(fout, "%s int _rpcpmstart;", var_type); |
fprintf(fout, "%s int _rpcpmstart;", var_type); |
fprintf(fout, "\t\t/* Started by a port monitor ? */\n"); |
fprintf(fout, "\t\t/* Started by a port monitor ? */\n"); |
|
|
/* write out dispatcher and stubs */ |
/* write out dispatcher and stubs */ |
write_programs(nomain? (char *)NULL : "static"); |
write_programs(nomain? (char *)NULL : "static"); |
|
|
if (nomain) |
if (nomain) |
return; |
return; |
|
|
fprintf(fout, "\nmain()\n"); |
fprintf(fout, "\nmain()\n"); |
|
|
if (inetdflag) { |
if (inetdflag) { |
write_inetmost(infile); /* Includes call to write_rpc_svc_fg() */ |
write_inetmost(infile); /* Includes call to write_rpc_svc_fg() */ |
} else { |
} else { |
if (tirpcflag) { |
if (tirpcflag) { |
if (netflag) { |
if (netflag) { |
|
fprintf(fout, "\tSVCXPRT *%s;\n", TRANSP); |
|
fprintf(fout, "\tstruct netconfig *nconf = NULL;\n"); |
|
} |
|
fprintf(fout, "\tpid_t pid;\n"); |
|
fprintf(fout, "\tint i;\n"); |
|
fprintf(fout, "\tchar mname[FMNAMESZ + 1];\n\n"); |
|
write_pm_most(infile, netflag); |
|
fprintf(fout, "\telse {\n"); |
|
write_rpc_svc_fg(infile, "\t\t"); |
|
fprintf(fout, "\t}\n"); |
|
} else { |
fprintf(fout, "\tSVCXPRT *%s;\n", TRANSP); |
fprintf(fout, "\tSVCXPRT *%s;\n", TRANSP); |
fprintf(fout, "\tstruct netconfig *nconf = NULL;\n"); |
fprintf(fout, "\n"); |
|
print_pmapunset("\t"); |
} |
} |
fprintf(fout, "\tpid_t pid;\n"); |
|
fprintf(fout, "\tint i;\n"); |
|
fprintf(fout, "\tchar mname[FMNAMESZ + 1];\n\n"); |
|
write_pm_most(infile, netflag); |
|
fprintf(fout, "\telse {\n"); |
|
write_rpc_svc_fg(infile, "\t\t"); |
|
fprintf(fout, "\t}\n"); |
|
} else { |
|
fprintf(fout, "\tSVCXPRT *%s;\n", TRANSP); |
|
fprintf(fout, "\n"); |
|
print_pmapunset("\t"); |
|
} |
|
} |
} |
|
|
if (logflag && !inetdflag) { |
if (logflag && !inetdflag) { |
|
|
which calls server's defintion of actual function (e.g. printmsg_1(...)). |
which calls server's defintion of actual function (e.g. printmsg_1(...)). |
Unpacks single user argument of printmsg_1 to call-by-value format |
Unpacks single user argument of printmsg_1 to call-by-value format |
expected by printmsg_1. */ |
expected by printmsg_1. */ |
static |
static void |
write_real_program(def) |
write_real_program(def) |
definition *def; |
definition *def; |
{ |
{ |
|
|
fprintf(fout, "\n_"); |
fprintf(fout, "\n_"); |
pvname(proc->proc_name, vp->vers_num); |
pvname(proc->proc_name, vp->vers_num); |
if (Cflag) { |
if (Cflag) { |
fprintf(fout, "("); |
fprintf(fout, "("); |
/* arg name */ |
/* arg name */ |
if (proc->arg_num > 1) |
if (proc->arg_num > 1) |
fprintf(fout, proc->args.argname); |
fprintf(fout, proc->args.argname); |
else |
else |
ptype(proc->args.decls->decl.prefix, |
ptype(proc->args.decls->decl.prefix, |
proc->args.decls->decl.type, 0); |
proc->args.decls->decl.type, 0); |
fprintf(fout, " *argp, struct svc_req *%s)\n", |
fprintf(fout, " *argp, struct svc_req *%s)\n", |
RQSTP); |
RQSTP); |
} else { |
} else { |
fprintf(fout, "(argp, %s)\n", RQSTP); |
fprintf(fout, "(argp, %s)\n", RQSTP); |
/* arg name */ |
/* arg name */ |
if (proc->arg_num > 1) |
if (proc->arg_num > 1) |
fprintf(fout, "\t%s *argp;\n", proc->args.argname); |
fprintf(fout, "\t%s *argp;\n", |
else { |
proc->args.argname); |
fprintf(fout, "\t"); |
else { |
ptype(proc->args.decls->decl.prefix, |
fprintf(fout, "\t"); |
proc->args.decls->decl.type, 0); |
ptype(proc->args.decls->decl.prefix, |
fprintf(fout, " *argp;\n"); |
proc->args.decls->decl.type, 0); |
} |
fprintf(fout, " *argp;\n"); |
fprintf(fout, " struct svc_req *%s;\n", RQSTP); |
} |
|
fprintf(fout, " struct svc_req *%s;\n", RQSTP); |
} |
} |
|
|
fprintf(fout, "{\n"); |
fprintf(fout, "{\n"); |
|
|
pvname_svc(proc->proc_name, vp->vers_num); |
pvname_svc(proc->proc_name, vp->vers_num); |
fprintf(fout, "("); |
fprintf(fout, "("); |
if (proc->arg_num < 2) { /* single argument */ |
if (proc->arg_num < 2) { /* single argument */ |
if (!streq(proc->args.decls->decl.type, "void")) |
if (!streq(proc->args.decls->decl.type, "void")) |
fprintf(fout, "*argp, "); /* non-void */ |
fprintf(fout, "*argp, "); /* non-void */ |
} else { |
} else { |
for (l = proc->args.decls; l != NULL; l = l->next) |
for (l = proc->args.decls; l != NULL; l = l->next) |
fprintf(fout, "argp->%s, ", l->decl.name); |
fprintf(fout, "argp->%s, ", l->decl.name); |
} |
} |
fprintf(fout, "%s));\n}\n", RQSTP); |
fprintf(fout, "%s));\n}\n", RQSTP); |
} |
} |
} |
} |
} |
} |
|
|
static |
static void |
write_program(def, storage) |
write_program(def, storage) |
definition *def; |
definition *def; |
char *storage; |
char *storage; |
|
|
} |
} |
} |
} |
|
|
static |
static void |
printerr(err, transp) |
printerr(err, transp) |
char *err; |
char *err; |
char *transp; |
char *transp; |
|
|
fprintf(fout, "\t\tsvcerr_%s(%s);\n", err, transp); |
fprintf(fout, "\t\tsvcerr_%s(%s);\n", err, transp); |
} |
} |
|
|
static |
static void |
printif (proc, transp, prefix, arg) |
printif(proc, transp, prefix, arg) |
char *proc; |
char *proc; |
char *transp; |
char *transp; |
char *prefix; |
char *prefix; |
|
|
proc, transp, arg, prefix, arg); |
proc, transp, arg, prefix, arg); |
} |
} |
|
|
|
int |
nullproc(proc) |
nullproc(proc) |
proc_list *proc; |
proc_list *proc; |
{ |
{ |
|
|
return (0); |
return (0); |
} |
} |
|
|
static |
static void |
write_inetmost(infile) |
write_inetmost(infile) |
char *infile; |
char *infile; |
{ |
{ |
|
|
fprintf(fout, "\t}\n"); |
fprintf(fout, "\t}\n"); |
} |
} |
|
|
static |
static void |
print_return(space) |
print_return(space) |
char *space; |
char *space; |
{ |
{ |
|
|
} |
} |
} |
} |
|
|
static |
static void |
print_pmapunset(space) |
print_pmapunset(space) |
char *space; |
char *space; |
{ |
{ |
|
|
} |
} |
} |
} |
|
|
static |
static void |
print_err_message(space) |
print_err_message(space) |
char *space; |
char *space; |
{ |
{ |
|
|
*/ |
*/ |
void |
void |
write_svc_aux(nomain) |
write_svc_aux(nomain) |
int nomain; |
int nomain; |
{ |
{ |
if (!logflag) |
if (!logflag) |
write_msg_out(); |
write_msg_out(); |
|
|
* Write the _msgout function |
* Write the _msgout function |
*/ |
*/ |
|
|
|
void |
write_msg_out() |
write_msg_out() |
{ |
{ |
fprintf(fout, "\n"); |
fprintf(fout, "\n"); |
|
|
/* |
/* |
* Write the timeout function |
* Write the timeout function |
*/ |
*/ |
static |
static void |
write_timeout_func() |
write_timeout_func() |
{ |
{ |
if (!timerflag) |
if (!timerflag) |
|
|
fprintf(fout, "}\n"); |
fprintf(fout, "}\n"); |
} |
} |
|
|
static |
static void |
write_caller_func() /*EVAS*/ |
write_caller_func() /*EVAS*/ |
{ |
{ |
#define P(s) fprintf(fout, s); |
#define P(s) fprintf(fout, s); |
|
|
/* |
/* |
* Write the most of port monitor support |
* Write the most of port monitor support |
*/ |
*/ |
static |
static void |
write_pm_most(infile, netflag) |
write_pm_most(infile, netflag) |
char *infile; |
char *infile; |
int netflag; |
int netflag; |
|
|
fprintf(fout, "\t\tSVCXPRT *%s;\n", TRANSP); |
fprintf(fout, "\t\tSVCXPRT *%s;\n", TRANSP); |
} |
} |
if (timerflag) |
if (timerflag) |
fprintf(fout, "\t\tint pmclose;\n"); |
fprintf(fout, "\t\tint pmclose;\n"); |
/* not necessary, defined in /usr/include/stdlib */ |
/* not necessary, defined in /usr/include/stdlib */ |
/* fprintf(fout, "\t\textern char *getenv();\n");*/ |
/* fprintf(fout, "\t\textern char *getenv();\n");*/ |
fprintf(fout, "\n"); |
fprintf(fout, "\n"); |
|
|
fprintf(fout, "\t\t\t}\n"); |
fprintf(fout, "\t\t\t}\n"); |
fprintf(fout, "\t\t}\n"); |
fprintf(fout, "\t\t}\n"); |
if (timerflag) |
if (timerflag) |
fprintf(fout, "\t\tpmclose = (t_getstate(0) != T_DATAXFER);\n"); |
fprintf(fout, "\t\tpmclose = (t_getstate(0) != T_DATAXFER);\n"); |
fprintf(fout, "\t\tif ((%s = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) {\n", |
fprintf(fout, "\t\tif ((%s = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) {\n", |
TRANSP); |
TRANSP); |
snprintf(_errbuf, sizeof _errbuf, "cannot create server handle"); |
snprintf(_errbuf, sizeof _errbuf, "cannot create server handle"); |
|
|
/* |
/* |
* Support for backgrounding the server if self started. |
* Support for backgrounding the server if self started. |
*/ |
*/ |
static |
static void |
write_rpc_svc_fg(infile, sp) |
write_rpc_svc_fg(infile, sp) |
char *infile; |
char *infile; |
char *sp; |
char *sp; |
|
|
fprintf(fout, "#ifndef RPC_SVC_FG\n"); |
fprintf(fout, "#ifndef RPC_SVC_FG\n"); |
fprintf(fout, "%sint size;\n", sp); |
fprintf(fout, "%sint size;\n", sp); |
if (tirpcflag) |
if (tirpcflag) |
fprintf(fout, "%sstruct rlimit rl;\n", sp); |
fprintf(fout, "%sstruct rlimit rl;\n", sp); |
if (inetdflag) { |
if (inetdflag) { |
fprintf(fout, "%sint i;\n\n", sp); |
fprintf(fout, "%sint i;\n\n", sp); |
fprintf(fout, "%spid_t pid;\n\n", sp); |
fprintf(fout, "%spid_t pid;\n\n", sp); |
|
|
fprintf(fout, "%s\texit(0);\n", sp); |
fprintf(fout, "%s\texit(0);\n", sp); |
/* get number of file descriptors */ |
/* get number of file descriptors */ |
if (tirpcflag) { |
if (tirpcflag) { |
fprintf(fout, "%srl.rlim_max = 0;\n", sp); |
fprintf(fout, "%srl.rlim_max = 0;\n", sp); |
fprintf(fout, "%sgetrlimit(RLIMIT_NOFILE, &rl);\n", sp); |
fprintf(fout, "%sgetrlimit(RLIMIT_NOFILE, &rl);\n", sp); |
fprintf(fout, "%sif ((size = rl.rlim_max) == 0)\n", sp); |
fprintf(fout, "%sif ((size = rl.rlim_max) == 0)\n", sp); |
fprintf(fout, "%s\texit(1);\n", sp); |
fprintf(fout, "%s\texit(1);\n", sp); |
} else { |
} else { |
fprintf(fout, "%ssize = getdtablesize();\n", sp); |
fprintf(fout, "%ssize = getdtablesize();\n", sp); |
} |
} |
|
|
fprintf(fout, "%sfor (i = 0; i < size; i++)\n", sp); |
fprintf(fout, "%sfor (i = 0; i < size; i++)\n", sp); |
|
|
fprintf(fout, "%s(void) dup2(i, 2);\n", sp); |
fprintf(fout, "%s(void) dup2(i, 2);\n", sp); |
/* This removes control of the controlling terminal */ |
/* This removes control of the controlling terminal */ |
if (tirpcflag) |
if (tirpcflag) |
fprintf(fout, "%ssetsid();\n", sp); |
fprintf(fout, "%ssetsid();\n", sp); |
else { |
else { |
fprintf(fout, "%si = open(\"/dev/tty\", 2);\n", sp); |
fprintf(fout, "%si = open(\"/dev/tty\", 2);\n", sp); |
fprintf(fout, "%sif (i >= 0) {\n", sp); |
fprintf(fout, "%sif (i >= 0) {\n", sp); |
fprintf(fout, "%s\t(void) ioctl(i, TIOCNOTTY, (char *)NULL);\n", sp);; |
fprintf(fout, "%s\t(void) ioctl(i, TIOCNOTTY, (char *)NULL);\n", sp);; |
fprintf(fout, "%s\t(void) close(i);\n", sp); |
fprintf(fout, "%s\t(void) close(i);\n", sp); |
fprintf(fout, "%s}\n", sp); |
fprintf(fout, "%s}\n", sp); |
} |
} |
if (!logflag) |
if (!logflag) |
open_log_file(infile, sp); |
open_log_file(infile, sp); |
|
|
open_log_file(infile, sp); |
open_log_file(infile, sp); |
} |
} |
|
|
static |
static void |
open_log_file(infile, sp) |
open_log_file(infile, sp) |
char *infile; |
char *infile; |
char *sp; |
char *sp; |