rpc_svcout.c revision 1.30 1 1.30 kamil /* $NetBSD: rpc_svcout.c,v 1.30 2015/09/20 15:52:11 kamil Exp $ */
2 1.1 glass /*
3 1.1 glass * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 1.1 glass * unrestricted use provided that this legend is included on all tape
5 1.1 glass * media and as a part of the software program in whole or part. Users
6 1.1 glass * may copy or modify Sun RPC without charge, but are not authorized
7 1.1 glass * to license or distribute it to anyone else except as part of a product or
8 1.6 pk * program developed by the user or with the express written consent of
9 1.6 pk * Sun Microsystems, Inc.
10 1.6 pk *
11 1.1 glass * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 1.1 glass * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 1.1 glass * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 1.6 pk *
15 1.1 glass * Sun RPC is provided with no support and without any obligation on the
16 1.1 glass * part of Sun Microsystems, Inc. to assist in its use, correction,
17 1.1 glass * modification or enhancement.
18 1.6 pk *
19 1.1 glass * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 1.1 glass * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 1.1 glass * OR ANY PART THEREOF.
22 1.6 pk *
23 1.1 glass * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 1.1 glass * or profits or other special, indirect and consequential damages, even if
25 1.1 glass * Sun has been advised of the possibility of such damages.
26 1.6 pk *
27 1.1 glass * Sun Microsystems, Inc.
28 1.1 glass * 2550 Garcia Avenue
29 1.1 glass * Mountain View, California 94043
30 1.1 glass */
31 1.6 pk
32 1.22 jmc #if HAVE_NBTOOL_CONFIG_H
33 1.22 jmc #include "nbtool_config.h"
34 1.22 jmc #endif
35 1.22 jmc
36 1.8 christos #include <sys/cdefs.h>
37 1.15 tv #if defined(__RCSID) && !defined(lint)
38 1.8 christos #if 0
39 1.8 christos static char sccsid[] = "@(#)rpc_svcout.c 1.29 89/03/30 (C) 1987 SMI";
40 1.8 christos #else
41 1.30 kamil __RCSID("$NetBSD: rpc_svcout.c,v 1.30 2015/09/20 15:52:11 kamil Exp $");
42 1.8 christos #endif
43 1.1 glass #endif
44 1.1 glass
45 1.1 glass /*
46 1.1 glass * rpc_svcout.c, Server-skeleton outputter for the RPC protocol compiler
47 1.1 glass */
48 1.1 glass #include <stdio.h>
49 1.6 pk #include <string.h>
50 1.8 christos #include "rpc_scan.h"
51 1.1 glass #include "rpc_parse.h"
52 1.1 glass #include "rpc_util.h"
53 1.1 glass
54 1.1 glass static char RQSTP[] = "rqstp";
55 1.1 glass static char TRANSP[] = "transp";
56 1.1 glass static char ARG[] = "argument";
57 1.1 glass static char RESULT[] = "result";
58 1.1 glass static char ROUTINE[] = "local";
59 1.1 glass
60 1.25 christos static void p_xdrfunc(const char *, const char *);
61 1.25 christos static void internal_proctype(proc_list *);
62 1.25 christos static void write_real_program(definition *);
63 1.25 christos static void write_program(definition *, const char *);
64 1.25 christos static void printerr(const char *, const char *);
65 1.25 christos static void printif(const char *, const char *, const char *, const char *);
66 1.25 christos static void write_inetmost(char *);
67 1.25 christos static void print_return(const char *);
68 1.25 christos static void print_pmapunset(const char *);
69 1.25 christos static void print_err_message(const char *);
70 1.25 christos static void write_timeout_func(void);
71 1.25 christos static void write_caller_func(void);
72 1.25 christos static void write_pm_most(char *, int);
73 1.25 christos static void write_rpc_svc_fg(char *, const char *);
74 1.25 christos static void open_log_file(char *, const char *);
75 1.25 christos static const char *aster(const char *);
76 1.8 christos
77 1.10 lukem char _errbuf[256]; /* For all messages */
78 1.6 pk
79 1.8 christos static void
80 1.24 dholland p_xdrfunc(const char *rname, const char *typename)
81 1.10 lukem {
82 1.25 christos f_print(fout, "\t\txdr_%s = (xdrproc_t)xdr_%s;\n", rname,
83 1.25 christos stringfix(typename));
84 1.10 lukem }
85 1.6 pk
86 1.8 christos static void
87 1.24 dholland internal_proctype(proc_list *plist)
88 1.6 pk {
89 1.6 pk f_print(fout, "static ");
90 1.10 lukem ptype(plist->res_prefix, plist->res_type, 1);
91 1.14 mycroft if (!Mflag)
92 1.14 mycroft f_print(fout, "*");
93 1.6 pk }
94 1.6 pk
95 1.6 pk
96 1.1 glass /*
97 1.10 lukem * write most of the service, that is, everything but the registrations.
98 1.1 glass */
99 1.1 glass void
100 1.24 dholland write_most(char *infile /* our name */, int netflag, int nomain)
101 1.6 pk {
102 1.6 pk if (inetdflag || pmflag) {
103 1.24 dholland const char *var_type;
104 1.19 christos var_type = (nomain ? "" : "static ");
105 1.19 christos f_print(fout, "%sint _rpcpmstart;", var_type);
106 1.10 lukem f_print(fout, "\t\t/* Started by a port monitor ? */\n");
107 1.19 christos f_print(fout, "%sint _rpcfdtype;", var_type);
108 1.6 pk f_print(fout, "\t\t/* Whether Stream or Datagram ? */\n");
109 1.6 pk if (timerflag) {
110 1.19 christos f_print(fout, "%sint _rpcsvcdirty;", var_type);
111 1.6 pk f_print(fout, "\t/* Still serving ? */\n");
112 1.6 pk }
113 1.10 lukem write_svc_aux(nomain);
114 1.6 pk }
115 1.6 pk /* write out dispatcher and stubs */
116 1.23 plunky write_programs(nomain ? NULL : "static");
117 1.6 pk
118 1.10 lukem if (nomain)
119 1.10 lukem return;
120 1.6 pk
121 1.26 christos f_print(fout, "\n\n");
122 1.26 christos f_print(fout, "int main(int, char *[]);\n");
123 1.10 lukem f_print(fout, "\nint\n");
124 1.25 christos f_print(fout, "main(int argc, char *argv[])\n");
125 1.6 pk f_print(fout, "{\n");
126 1.6 pk if (inetdflag) {
127 1.10 lukem write_inetmost(infile); /* Includes call to write_rpc_svc_fg() */
128 1.6 pk } else {
129 1.10 lukem if (tirpcflag) {
130 1.10 lukem if (netflag) {
131 1.10 lukem f_print(fout, "\tSVCXPRT *%s;\n", TRANSP);
132 1.10 lukem f_print(fout, "\tstruct netconfig *nconf = NULL;\n");
133 1.10 lukem }
134 1.10 lukem f_print(fout, "\tpid_t pid;\n");
135 1.10 lukem f_print(fout, "\tint i;\n");
136 1.10 lukem f_print(fout, "\tchar mname[FMNAMESZ + 1];\n\n");
137 1.10 lukem write_pm_most(infile, netflag);
138 1.10 lukem f_print(fout, "\telse {\n");
139 1.10 lukem write_rpc_svc_fg(infile, "\t\t");
140 1.10 lukem f_print(fout, "\t}\n");
141 1.10 lukem } else {
142 1.9 lukem f_print(fout, "\tSVCXPRT *%s;\n", TRANSP);
143 1.10 lukem f_print(fout, "\n");
144 1.10 lukem print_pmapunset("\t");
145 1.6 pk }
146 1.6 pk }
147 1.6 pk
148 1.6 pk if (logflag && !inetdflag) {
149 1.6 pk open_log_file(infile, "\t");
150 1.6 pk }
151 1.6 pk }
152 1.6 pk /*
153 1.10 lukem * write a registration for the given transport
154 1.6 pk */
155 1.6 pk void
156 1.24 dholland write_netid_register(const char *transp)
157 1.1 glass {
158 1.10 lukem list *l;
159 1.1 glass definition *def;
160 1.1 glass version_list *vp;
161 1.24 dholland const char *sp;
162 1.10 lukem char tmpbuf[32];
163 1.1 glass
164 1.6 pk sp = "";
165 1.1 glass f_print(fout, "\n");
166 1.6 pk f_print(fout, "%s\tnconf = getnetconfigent(\"%s\");\n", sp, transp);
167 1.6 pk f_print(fout, "%s\tif (nconf == NULL) {\n", sp);
168 1.6 pk (void) sprintf(_errbuf, "cannot find %s netid.", transp);
169 1.6 pk sprintf(tmpbuf, "%s\t\t", sp);
170 1.6 pk print_err_message(tmpbuf);
171 1.6 pk f_print(fout, "%s\t\texit(1);\n", sp);
172 1.6 pk f_print(fout, "%s\t}\n", sp);
173 1.6 pk f_print(fout, "%s\t%s = svc_tli_create(RPC_ANYFD, nconf, 0, 0, 0);\n",
174 1.10 lukem sp, TRANSP);
175 1.6 pk f_print(fout, "%s\tif (%s == NULL) {\n", sp, TRANSP);
176 1.6 pk (void) sprintf(_errbuf, "cannot create %s service.", transp);
177 1.6 pk print_err_message(tmpbuf);
178 1.6 pk f_print(fout, "%s\t\texit(1);\n", sp);
179 1.6 pk f_print(fout, "%s\t}\n", sp);
180 1.6 pk
181 1.1 glass for (l = defined; l != NULL; l = l->next) {
182 1.1 glass def = (definition *) l->val;
183 1.1 glass if (def->def_kind != DEF_PROGRAM) {
184 1.1 glass continue;
185 1.1 glass }
186 1.1 glass for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
187 1.6 pk f_print(fout,
188 1.10 lukem "%s\t(void) rpcb_unset(%s, %s, nconf);\n",
189 1.10 lukem sp, def->def_name, vp->vers_name);
190 1.6 pk f_print(fout,
191 1.10 lukem "%s\tif (!svc_reg(%s, %s, %s, ",
192 1.10 lukem sp, TRANSP, def->def_name, vp->vers_name);
193 1.6 pk pvname(def->def_name, vp->vers_num);
194 1.6 pk f_print(fout, ", nconf)) {\n");
195 1.6 pk (void) sprintf(_errbuf, "unable to register (%s, %s, %s).",
196 1.10 lukem def->def_name, vp->vers_name, transp);
197 1.6 pk print_err_message(tmpbuf);
198 1.6 pk f_print(fout, "%s\t\texit(1);\n", sp);
199 1.6 pk f_print(fout, "%s\t}\n", sp);
200 1.1 glass }
201 1.1 glass }
202 1.6 pk f_print(fout, "%s\tfreenetconfigent(nconf);\n", sp);
203 1.1 glass }
204 1.1 glass /*
205 1.6 pk * write a registration for the given transport for TLI
206 1.1 glass */
207 1.1 glass void
208 1.24 dholland write_nettype_register(const char *transp)
209 1.1 glass {
210 1.10 lukem list *l;
211 1.1 glass definition *def;
212 1.1 glass version_list *vp;
213 1.1 glass
214 1.1 glass for (l = defined; l != NULL; l = l->next) {
215 1.1 glass def = (definition *) l->val;
216 1.1 glass if (def->def_kind != DEF_PROGRAM) {
217 1.1 glass continue;
218 1.1 glass }
219 1.1 glass for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
220 1.6 pk f_print(fout, "\tif (!svc_create(");
221 1.1 glass pvname(def->def_name, vp->vers_num);
222 1.6 pk f_print(fout, ", %s, %s, \"%s\")) {\n ",
223 1.10 lukem def->def_name, vp->vers_name, transp);
224 1.6 pk (void) sprintf(_errbuf,
225 1.10 lukem "unable to create (%s, %s) for %s.",
226 1.10 lukem def->def_name, vp->vers_name, transp);
227 1.6 pk print_err_message("\t\t");
228 1.1 glass f_print(fout, "\t\texit(1);\n");
229 1.1 glass f_print(fout, "\t}\n");
230 1.1 glass }
231 1.1 glass }
232 1.1 glass }
233 1.1 glass /*
234 1.10 lukem * write the rest of the service
235 1.1 glass */
236 1.1 glass void
237 1.24 dholland write_rest(void)
238 1.1 glass {
239 1.6 pk f_print(fout, "\n");
240 1.6 pk if (inetdflag) {
241 1.23 plunky f_print(fout, "\tif (%s == NULL) {\n", TRANSP);
242 1.6 pk (void) sprintf(_errbuf, "could not create a handle");
243 1.6 pk print_err_message("\t\t");
244 1.6 pk f_print(fout, "\t\texit(1);\n");
245 1.6 pk f_print(fout, "\t}\n");
246 1.6 pk if (timerflag) {
247 1.6 pk f_print(fout, "\tif (_rpcpmstart) {\n");
248 1.10 lukem f_print(fout,
249 1.25 christos "\t\t(void) signal(SIGALRM, (SIG_PF)closedown);\n");
250 1.6 pk f_print(fout, "\t\t(void) alarm(_RPCSVC_CLOSEDOWN);\n");
251 1.6 pk f_print(fout, "\t}\n");
252 1.6 pk }
253 1.6 pk }
254 1.1 glass f_print(fout, "\tsvc_run();\n");
255 1.6 pk (void) sprintf(_errbuf, "svc_run returned");
256 1.6 pk print_err_message("\t");
257 1.1 glass f_print(fout, "\texit(1);\n");
258 1.6 pk f_print(fout, "\t/* NOTREACHED */\n");
259 1.1 glass f_print(fout, "}\n");
260 1.1 glass }
261 1.1 glass
262 1.1 glass void
263 1.24 dholland write_programs(const char *storage)
264 1.1 glass {
265 1.10 lukem list *l;
266 1.1 glass definition *def;
267 1.1 glass
268 1.6 pk /* write out stubs for procedure definitions */
269 1.6 pk for (l = defined; l != NULL; l = l->next) {
270 1.6 pk def = (definition *) l->val;
271 1.6 pk if (def->def_kind == DEF_PROGRAM) {
272 1.6 pk write_real_program(def);
273 1.6 pk }
274 1.6 pk }
275 1.6 pk
276 1.6 pk /* write out dispatcher for each program */
277 1.1 glass for (l = defined; l != NULL; l = l->next) {
278 1.1 glass def = (definition *) l->val;
279 1.1 glass if (def->def_kind == DEF_PROGRAM) {
280 1.1 glass write_program(def, storage);
281 1.1 glass }
282 1.1 glass }
283 1.6 pk
284 1.6 pk
285 1.1 glass }
286 1.6 pk /* write out definition of internal function (e.g. _printmsg_1(...))
287 1.21 wiz which calls server's definition of actual function (e.g. printmsg_1(...)).
288 1.6 pk Unpacks single user argument of printmsg_1 to call-by-value format
289 1.6 pk expected by printmsg_1. */
290 1.8 christos static void
291 1.24 dholland write_real_program(definition *def)
292 1.6 pk {
293 1.6 pk version_list *vp;
294 1.6 pk proc_list *proc;
295 1.6 pk decl_list *l;
296 1.1 glass
297 1.10 lukem if (!newstyle)
298 1.10 lukem return; /* not needed for old style */
299 1.6 pk for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
300 1.6 pk for (proc = vp->procs; proc != NULL; proc = proc->next) {
301 1.6 pk f_print(fout, "\n");
302 1.6 pk internal_proctype(proc);
303 1.6 pk f_print(fout, "\n_");
304 1.6 pk pvname(proc->proc_name, vp->vers_num);
305 1.25 christos f_print(fout, "(");
306 1.25 christos /* arg name */
307 1.25 christos if (proc->arg_num > 1)
308 1.25 christos f_print(fout, "%s ",
309 1.25 christos proc->args.argname);
310 1.25 christos else
311 1.25 christos ptype(proc->args.decls->decl.prefix,
312 1.25 christos proc->args.decls->decl.type, 0);
313 1.25 christos f_print(fout, "*argp, ");
314 1.25 christos if (Mflag) {
315 1.25 christos if (streq(proc->res_type, "void"))
316 1.25 christos f_print(fout, "char ");
317 1.10 lukem else
318 1.25 christos ptype(proc->res_prefix,
319 1.25 christos proc->res_type, 0);
320 1.25 christos f_print(fout, "%sresult, ",
321 1.25 christos aster(proc->res_type));
322 1.6 pk }
323 1.25 christos f_print(fout, "struct svc_req *%s)\n", RQSTP);
324 1.6 pk f_print(fout, "{\n");
325 1.14 mycroft f_print(fout, "\treturn (");
326 1.7 pk pvname_svc(proc->proc_name, vp->vers_num);
327 1.6 pk f_print(fout, "(");
328 1.10 lukem if (proc->arg_num < 2) { /* single argument */
329 1.10 lukem if (!streq(proc->args.decls->decl.type, "void"))
330 1.10 lukem f_print(fout, "*argp, "); /* non-void */
331 1.6 pk } else {
332 1.10 lukem for (l = proc->args.decls; l != NULL; l = l->next)
333 1.10 lukem f_print(fout, "argp->%s, ", l->decl.name);
334 1.6 pk }
335 1.6 pk f_print(fout, "%s));\n}\n", RQSTP);
336 1.10 lukem }
337 1.6 pk }
338 1.6 pk }
339 1.6 pk
340 1.8 christos static void
341 1.24 dholland write_program(definition *def, const char *storage)
342 1.1 glass {
343 1.1 glass version_list *vp;
344 1.1 glass proc_list *proc;
345 1.10 lukem int filled;
346 1.1 glass
347 1.1 glass for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
348 1.25 christos f_print(fout, "\n");
349 1.25 christos if (storage != NULL) {
350 1.25 christos f_print(fout, "%s ", storage);
351 1.9 lukem }
352 1.25 christos f_print(fout, "void ");
353 1.25 christos pvname(def->def_name, vp->vers_num);
354 1.25 christos f_print(fout, "(struct svc_req *%s, ", RQSTP);
355 1.25 christos f_print(fout, "SVCXPRT *%s);\n", TRANSP);
356 1.1 glass f_print(fout, "\n");
357 1.1 glass if (storage != NULL) {
358 1.1 glass f_print(fout, "%s ", storage);
359 1.1 glass }
360 1.1 glass f_print(fout, "void\n");
361 1.1 glass pvname(def->def_name, vp->vers_num);
362 1.6 pk
363 1.25 christos f_print(fout, "(struct svc_req *%s, ", RQSTP);
364 1.25 christos f_print(fout, "SVCXPRT *%s)\n", TRANSP);
365 1.1 glass f_print(fout, "{\n");
366 1.1 glass
367 1.1 glass filled = 0;
368 1.1 glass f_print(fout, "\tunion {\n");
369 1.1 glass for (proc = vp->procs; proc != NULL; proc = proc->next) {
370 1.10 lukem if (proc->arg_num < 2) { /* single argument */
371 1.10 lukem if (streq(proc->args.decls->decl.type,
372 1.10 lukem "void")) {
373 1.6 pk continue;
374 1.6 pk }
375 1.6 pk filled = 1;
376 1.6 pk f_print(fout, "\t\t");
377 1.10 lukem ptype(proc->args.decls->decl.prefix,
378 1.10 lukem proc->args.decls->decl.type, 0);
379 1.6 pk pvname(proc->proc_name, vp->vers_num);
380 1.6 pk f_print(fout, "_arg;\n");
381 1.6 pk
382 1.10 lukem } else {
383 1.6 pk filled = 1;
384 1.6 pk f_print(fout, "\t\t%s", proc->args.argname);
385 1.6 pk f_print(fout, " ");
386 1.6 pk pvname(proc->proc_name, vp->vers_num);
387 1.6 pk f_print(fout, "_arg;\n");
388 1.1 glass }
389 1.1 glass }
390 1.1 glass if (!filled) {
391 1.1 glass f_print(fout, "\t\tint fill;\n");
392 1.1 glass }
393 1.1 glass f_print(fout, "\t} %s;\n", ARG);
394 1.12 mycroft if (Mflag) {
395 1.12 mycroft f_print(fout, "\tunion {\n");
396 1.12 mycroft for (proc = vp->procs; proc != NULL; proc = proc->next) {
397 1.12 mycroft f_print(fout, "\t\t");
398 1.12 mycroft if (streq(proc->res_type, "void"))
399 1.12 mycroft f_print(fout, "char ");
400 1.12 mycroft else
401 1.12 mycroft ptype(proc->res_prefix, proc->res_type,
402 1.12 mycroft 1);
403 1.12 mycroft pvname(proc->proc_name, vp->vers_num);
404 1.12 mycroft f_print(fout, "_res;\n");
405 1.12 mycroft }
406 1.12 mycroft f_print(fout, "\t} %s;\n", RESULT);
407 1.12 mycroft f_print(fout, "\tbool_t retval;\n");
408 1.12 mycroft } else
409 1.12 mycroft f_print(fout, "\tchar *%s;\n", RESULT);
410 1.6 pk
411 1.25 christos f_print(fout, "\txdrproc_t xdr_%s, xdr_%s;\n", ARG, RESULT);
412 1.25 christos if (Mflag)
413 1.25 christos f_print(fout,
414 1.25 christos "\tbool_t (*%s)(char *, void *, struct svc_req *);\n",
415 1.25 christos ROUTINE);
416 1.25 christos else
417 1.25 christos f_print(fout,
418 1.25 christos "\tchar *(*%s)(char *, struct svc_req *);\n",
419 1.25 christos ROUTINE);
420 1.6 pk
421 1.1 glass f_print(fout, "\n");
422 1.6 pk
423 1.10 lukem if (callerflag)
424 1.10 lukem f_print(fout, "\tcaller = transp;\n"); /* EVAS */
425 1.6 pk if (timerflag)
426 1.6 pk f_print(fout, "\t_rpcsvcdirty = 1;\n");
427 1.1 glass f_print(fout, "\tswitch (%s->rq_proc) {\n", RQSTP);
428 1.1 glass if (!nullproc(vp->procs)) {
429 1.1 glass f_print(fout, "\tcase NULLPROC:\n");
430 1.25 christos f_print(fout,
431 1.25 christos "\t\t(void) svc_sendreply(%s, (xdrproc_t)xdr_void, NULL);\n", TRANSP);
432 1.6 pk print_return("\t\t");
433 1.6 pk f_print(fout, "\n");
434 1.1 glass }
435 1.1 glass for (proc = vp->procs; proc != NULL; proc = proc->next) {
436 1.1 glass f_print(fout, "\tcase %s:\n", proc->proc_name);
437 1.10 lukem if (proc->arg_num < 2) { /* single argument */
438 1.10 lukem p_xdrfunc(ARG, proc->args.decls->decl.type);
439 1.6 pk } else {
440 1.10 lukem p_xdrfunc(ARG, proc->args.argname);
441 1.6 pk }
442 1.10 lukem p_xdrfunc(RESULT, proc->res_type);
443 1.25 christos if (Mflag)
444 1.25 christos f_print(fout,
445 1.25 christos "\t\t%s = (bool_t (*)(char *, void *, struct svc_req *))",
446 1.25 christos ROUTINE);
447 1.25 christos else
448 1.25 christos f_print(fout,
449 1.25 christos "\t\t%s = (char *(*)(char *, struct svc_req *))",
450 1.25 christos ROUTINE);
451 1.6 pk
452 1.30 kamil if (newstyle) { /* new style: calls internal routine */
453 1.10 lukem f_print(fout, "_");
454 1.30 kamil pvname(proc->proc_name, vp->vers_num);
455 1.30 kamil } else {
456 1.30 kamil pvname_svc(proc->proc_name, vp->vers_num);
457 1.30 kamil }
458 1.1 glass f_print(fout, ";\n");
459 1.1 glass f_print(fout, "\t\tbreak;\n\n");
460 1.1 glass }
461 1.1 glass f_print(fout, "\tdefault:\n");
462 1.1 glass printerr("noproc", TRANSP);
463 1.6 pk print_return("\t\t");
464 1.1 glass f_print(fout, "\t}\n");
465 1.1 glass
466 1.16 christos f_print(fout, "\t(void) memset(&%s, 0, sizeof(%s));\n", ARG, ARG);
467 1.12 mycroft printif("getargs", TRANSP, "(caddr_t)&", ARG);
468 1.1 glass printerr("decode", TRANSP);
469 1.6 pk print_return("\t\t");
470 1.1 glass f_print(fout, "\t}\n");
471 1.1 glass
472 1.25 christos if (Mflag)
473 1.25 christos f_print(fout, "\tretval = (*%s)((char *)&%s, (void *)&%s, %s);\n",
474 1.25 christos ROUTINE, ARG, RESULT, RQSTP);
475 1.25 christos else
476 1.25 christos f_print(fout, "\t%s = (*%s)((char *)&%s, %s);\n",
477 1.25 christos RESULT, ROUTINE, ARG, RQSTP);
478 1.12 mycroft if (Mflag)
479 1.12 mycroft f_print(fout,
480 1.12 mycroft "\tif (retval > 0 && !svc_sendreply(%s, xdr_%s, (char *)&%s)) {\n",
481 1.12 mycroft TRANSP, RESULT, RESULT);
482 1.6 pk else
483 1.12 mycroft f_print(fout,
484 1.12 mycroft "\tif (%s != NULL && !svc_sendreply(%s, xdr_%s, %s)) {\n",
485 1.12 mycroft RESULT, TRANSP, RESULT, RESULT);
486 1.1 glass printerr("systemerr", TRANSP);
487 1.1 glass f_print(fout, "\t}\n");
488 1.1 glass
489 1.12 mycroft printif("freeargs", TRANSP, "(caddr_t)&", ARG);
490 1.6 pk (void) sprintf(_errbuf, "unable to free arguments");
491 1.6 pk print_err_message("\t\t");
492 1.1 glass f_print(fout, "\t\texit(1);\n");
493 1.1 glass f_print(fout, "\t}\n");
494 1.12 mycroft
495 1.13 mycroft if (Mflag) {
496 1.13 mycroft f_print(fout, "\tif (!");
497 1.13 mycroft pvname(def->def_name, vp->vers_num);
498 1.13 mycroft f_print(fout, "_freeresult");
499 1.13 mycroft f_print(fout, "(%s, xdr_%s, (caddr_t)&%s)) {\n",
500 1.13 mycroft TRANSP, RESULT, RESULT);
501 1.13 mycroft (void) sprintf(_errbuf, "unable to free results");
502 1.13 mycroft print_err_message("\t\t");
503 1.13 mycroft f_print(fout, "\t\texit(1);\n");
504 1.13 mycroft f_print(fout, "\t}\n");
505 1.13 mycroft }
506 1.12 mycroft
507 1.6 pk print_return("\t");
508 1.6 pk f_print(fout, "}\n");
509 1.1 glass }
510 1.1 glass }
511 1.1 glass
512 1.8 christos static void
513 1.24 dholland printerr(const char *err, const char *transp)
514 1.1 glass {
515 1.1 glass f_print(fout, "\t\tsvcerr_%s(%s);\n", err, transp);
516 1.1 glass }
517 1.1 glass
518 1.8 christos static void
519 1.24 dholland printif(const char *proc, const char *transp, const char *prefix, const char *arg)
520 1.1 glass {
521 1.1 glass f_print(fout, "\tif (!svc_%s(%s, xdr_%s, %s%s)) {\n",
522 1.10 lukem proc, transp, arg, prefix, arg);
523 1.1 glass }
524 1.1 glass
525 1.8 christos int
526 1.24 dholland nullproc(proc_list *proc)
527 1.1 glass {
528 1.1 glass for (; proc != NULL; proc = proc->next) {
529 1.1 glass if (streq(proc->proc_num, "0")) {
530 1.1 glass return (1);
531 1.1 glass }
532 1.1 glass }
533 1.1 glass return (0);
534 1.6 pk }
535 1.6 pk
536 1.8 christos static void
537 1.24 dholland write_inetmost(char *infile)
538 1.6 pk {
539 1.10 lukem f_print(fout, "\tSVCXPRT *%s = NULL;\n", TRANSP);
540 1.6 pk f_print(fout, "\tint sock;\n");
541 1.10 lukem f_print(fout, "\tint proto = 0;\n");
542 1.6 pk f_print(fout, "\tstruct sockaddr_in saddr;\n");
543 1.16 christos f_print(fout, "\tsocklen_t asize = (socklen_t)sizeof(saddr);\n");
544 1.6 pk f_print(fout, "\n");
545 1.10 lukem f_print(fout,
546 1.10 lukem "\tif (getsockname(0, (struct sockaddr *)&saddr, &asize) == 0) {\n");
547 1.16 christos f_print(fout, "\t\tsocklen_t ssize = (socklen_t)sizeof(int);\n\n");
548 1.6 pk f_print(fout, "\t\tif (saddr.sin_family != AF_INET)\n");
549 1.6 pk f_print(fout, "\t\t\texit(1);\n");
550 1.6 pk f_print(fout, "\t\tif (getsockopt(0, SOL_SOCKET, SO_TYPE,\n");
551 1.16 christos f_print(fout, "\t\t\t\t(void *)&_rpcfdtype, &ssize) == -1)\n");
552 1.6 pk f_print(fout, "\t\t\texit(1);\n");
553 1.6 pk f_print(fout, "\t\tsock = 0;\n");
554 1.6 pk f_print(fout, "\t\t_rpcpmstart = 1;\n");
555 1.6 pk f_print(fout, "\t\tproto = 0;\n");
556 1.6 pk open_log_file(infile, "\t\t");
557 1.6 pk f_print(fout, "\t} else {\n");
558 1.6 pk write_rpc_svc_fg(infile, "\t\t");
559 1.6 pk f_print(fout, "\t\tsock = RPC_ANYSOCK;\n");
560 1.6 pk print_pmapunset("\t\t");
561 1.6 pk f_print(fout, "\t}\n");
562 1.6 pk }
563 1.6 pk
564 1.8 christos static void
565 1.24 dholland print_return(const char *space)
566 1.6 pk {
567 1.6 pk if (exitnow)
568 1.6 pk f_print(fout, "%sexit(0);\n", space);
569 1.6 pk else {
570 1.6 pk if (timerflag)
571 1.6 pk f_print(fout, "%s_rpcsvcdirty = 0;\n", space);
572 1.6 pk f_print(fout, "%sreturn;\n", space);
573 1.6 pk }
574 1.6 pk }
575 1.6 pk
576 1.8 christos static void
577 1.24 dholland print_pmapunset(const char *space)
578 1.6 pk {
579 1.10 lukem list *l;
580 1.6 pk definition *def;
581 1.6 pk version_list *vp;
582 1.6 pk
583 1.6 pk for (l = defined; l != NULL; l = l->next) {
584 1.6 pk def = (definition *) l->val;
585 1.6 pk if (def->def_kind == DEF_PROGRAM) {
586 1.6 pk for (vp = def->def.pr.versions; vp != NULL;
587 1.10 lukem vp = vp->next) {
588 1.6 pk f_print(fout, "%s(void) pmap_unset(%s, %s);\n",
589 1.10 lukem space, def->def_name, vp->vers_name);
590 1.6 pk }
591 1.6 pk }
592 1.6 pk }
593 1.6 pk }
594 1.6 pk
595 1.8 christos static void
596 1.24 dholland print_err_message(const char *space)
597 1.6 pk {
598 1.6 pk if (logflag)
599 1.6 pk f_print(fout, "%ssyslog(LOG_ERR, \"%s\");\n", space, _errbuf);
600 1.6 pk else
601 1.10 lukem if (inetdflag || pmflag)
602 1.10 lukem f_print(fout, "%s_msgout(\"%s\");\n", space, _errbuf);
603 1.10 lukem else
604 1.10 lukem f_print(fout, "%sfprintf(stderr, \"%s\");\n", space, _errbuf);
605 1.6 pk }
606 1.6 pk /*
607 1.6 pk * Write the server auxiliary function ( _msgout, timeout)
608 1.6 pk */
609 1.6 pk void
610 1.24 dholland write_svc_aux(int nomain)
611 1.6 pk {
612 1.6 pk if (!logflag)
613 1.6 pk write_msg_out();
614 1.10 lukem if (!nomain)
615 1.10 lukem write_timeout_func();
616 1.10 lukem if (callerflag) /* EVAS */
617 1.10 lukem write_caller_func(); /* EVAS */
618 1.6 pk }
619 1.6 pk /*
620 1.6 pk * Write the _msgout function
621 1.6 pk */
622 1.8 christos void
623 1.24 dholland write_msg_out(void)
624 1.6 pk {
625 1.6 pk f_print(fout, "\n");
626 1.6 pk f_print(fout, "static\n");
627 1.25 christos f_print(fout, "void _msgout(const char *msg)\n");
628 1.6 pk f_print(fout, "{\n");
629 1.6 pk f_print(fout, "#ifdef RPC_SVC_FG\n");
630 1.6 pk if (inetdflag || pmflag)
631 1.6 pk f_print(fout, "\tif (_rpcpmstart)\n");
632 1.11 is f_print(fout, "\t\tsyslog(LOG_ERR, \"%%s\", msg);\n");
633 1.6 pk f_print(fout, "\telse\n");
634 1.6 pk f_print(fout, "\t\t(void) fprintf(stderr, \"%%s\\n\", msg);\n");
635 1.6 pk f_print(fout, "#else\n");
636 1.11 is f_print(fout, "\tsyslog(LOG_ERR, \"%%s\", msg);\n");
637 1.6 pk f_print(fout, "#endif\n");
638 1.6 pk f_print(fout, "}\n");
639 1.6 pk }
640 1.6 pk /*
641 1.6 pk * Write the timeout function
642 1.6 pk */
643 1.8 christos static void
644 1.24 dholland write_timeout_func(void)
645 1.6 pk {
646 1.6 pk if (!timerflag)
647 1.6 pk return;
648 1.25 christos f_print(fout, "\n");
649 1.25 christos f_print(fout, "static void closedown(void);\n");
650 1.6 pk f_print(fout, "\n");
651 1.6 pk f_print(fout, "static void\n");
652 1.27 christos f_print(fout, "closedown(void)\n");
653 1.6 pk f_print(fout, "{\n");
654 1.6 pk f_print(fout, "\tif (_rpcsvcdirty == 0) {\n");
655 1.6 pk f_print(fout, "\t\textern fd_set svc_fdset;\n");
656 1.6 pk f_print(fout, "\t\tstatic int size;\n");
657 1.6 pk f_print(fout, "\t\tint i, openfd;\n");
658 1.6 pk if (tirpcflag && pmflag) {
659 1.6 pk f_print(fout, "\t\tstruct t_info tinfo;\n\n");
660 1.6 pk f_print(fout, "\t\tif (!t_getinfo(0, &tinfo) && (tinfo.servtype == T_CLTS))\n");
661 1.6 pk } else {
662 1.6 pk f_print(fout, "\n\t\tif (_rpcfdtype == SOCK_DGRAM)\n");
663 1.6 pk }
664 1.6 pk f_print(fout, "\t\t\texit(0);\n");
665 1.6 pk f_print(fout, "\t\tif (size == 0) {\n");
666 1.10 lukem if (tirpcflag) {
667 1.10 lukem f_print(fout, "\t\t\tstruct rlimit rl;\n\n");
668 1.10 lukem f_print(fout, "\t\t\trl.rlim_max = 0;\n");
669 1.27 christos f_print(fout, "\t\t\tif (getrlimit(RLIMIT_NOFILE, &rl) == -1)\n");
670 1.27 christos f_print(fout, "\t\t\t\treturn;\n");
671 1.10 lukem f_print(fout, "\t\t\tif ((size = rl.rlim_max) == 0)\n");
672 1.10 lukem f_print(fout, "\t\t\t\treturn;\n");
673 1.6 pk } else {
674 1.10 lukem f_print(fout, "\t\t\tsize = getdtablesize();\n");
675 1.6 pk }
676 1.6 pk f_print(fout, "\t\t}\n");
677 1.6 pk f_print(fout, "\t\tfor (i = 0, openfd = 0; i < size && openfd < 2; i++)\n");
678 1.6 pk f_print(fout, "\t\t\tif (FD_ISSET(i, &svc_fdset))\n");
679 1.6 pk f_print(fout, "\t\t\t\topenfd++;\n");
680 1.6 pk f_print(fout, "\t\tif (openfd <= (_rpcpmstart?0:1))\n");
681 1.6 pk f_print(fout, "\t\t\texit(0);\n");
682 1.6 pk f_print(fout, "\t}\n");
683 1.6 pk f_print(fout, "\t(void) alarm(_RPCSVC_CLOSEDOWN);\n");
684 1.6 pk f_print(fout, "}\n");
685 1.6 pk }
686 1.6 pk
687 1.8 christos static void
688 1.24 dholland write_caller_func(void)
689 1.10 lukem { /* EVAS */
690 1.6 pk #define P(s) f_print(fout, s);
691 1.6 pk
692 1.10 lukem P("\n");
693 1.10 lukem P("char *svc_caller()\n");
694 1.10 lukem P("{\n");
695 1.10 lukem P(" struct sockaddr_in actual;\n");
696 1.10 lukem P(" struct hostent *hp;\n");
697 1.10 lukem P(" static struct in_addr prev;\n");
698 1.10 lukem P(" static char cname[128];\n\n");
699 1.10 lukem
700 1.10 lukem P(" actual = *svc_getcaller(caller);\n\n");
701 1.10 lukem
702 1.10 lukem P(" if (memcmp((char *)&actual.sin_addr, (char *)&prev,\n");
703 1.10 lukem P(" sizeof(struct in_addr)) == 0)\n");
704 1.10 lukem P(" return (cname);\n\n");
705 1.10 lukem
706 1.10 lukem P(" prev = actual.sin_addr;\n\n");
707 1.10 lukem
708 1.16 christos P(" hp = gethostbyaddr((char *)&actual.sin_addr, sizeof(actual.sin_addr), AF_INET);\n");
709 1.10 lukem P(" if (hp == NULL) { /* dummy one up */\n");
710 1.10 lukem P(" extern char *inet_ntoa();\n");
711 1.20 itojun P(" strlcpy(cname, inet_ntoa(actual.sin_addr), sizeof(cname));\n");
712 1.10 lukem P(" } else {\n");
713 1.20 itojun P(" strlcpy(cname, hp->h_name, sizeof(cname));\n");
714 1.10 lukem P(" }\n\n");
715 1.6 pk
716 1.10 lukem P(" return (cname);\n");
717 1.10 lukem P("}\n");
718 1.6 pk
719 1.6 pk #undef P
720 1.6 pk }
721 1.6 pk /*
722 1.6 pk * Write the most of port monitor support
723 1.6 pk */
724 1.8 christos static void
725 1.24 dholland write_pm_most(char *infile, int netflag)
726 1.6 pk {
727 1.10 lukem list *l;
728 1.6 pk definition *def;
729 1.6 pk version_list *vp;
730 1.6 pk
731 1.6 pk f_print(fout, "\tif (!ioctl(0, I_LOOK, mname) &&\n");
732 1.6 pk f_print(fout, "\t\t(!strcmp(mname, \"sockmod\") ||");
733 1.6 pk f_print(fout, " !strcmp(mname, \"timod\"))) {\n");
734 1.6 pk f_print(fout, "\t\tchar *netid;\n");
735 1.10 lukem if (!netflag) { /* Not included by -n option */
736 1.6 pk f_print(fout, "\t\tstruct netconfig *nconf = NULL;\n");
737 1.6 pk f_print(fout, "\t\tSVCXPRT *%s;\n", TRANSP);
738 1.6 pk }
739 1.10 lukem if (timerflag)
740 1.10 lukem f_print(fout, "\t\tint pmclose;\n");
741 1.6 pk /* not necessary, defined in /usr/include/stdlib */
742 1.6 pk /* f_print(fout, "\t\textern char *getenv();\n");*/
743 1.6 pk f_print(fout, "\n");
744 1.6 pk f_print(fout, "\t\t_rpcpmstart = 1;\n");
745 1.6 pk if (logflag)
746 1.6 pk open_log_file(infile, "\t\t");
747 1.6 pk f_print(fout, "\t\tif ((netid = getenv(\"NLSPROVIDER\")) == NULL) {\n");
748 1.6 pk sprintf(_errbuf, "cannot get transport name");
749 1.6 pk print_err_message("\t\t\t");
750 1.6 pk f_print(fout, "\t\t} else if ((nconf = getnetconfigent(netid)) == NULL) {\n");
751 1.6 pk sprintf(_errbuf, "cannot get transport info");
752 1.6 pk print_err_message("\t\t\t");
753 1.6 pk f_print(fout, "\t\t}\n");
754 1.6 pk /*
755 1.6 pk * A kludgy support for inetd services. Inetd only works with
756 1.6 pk * sockmod, and RPC works only with timod, hence all this jugglery
757 1.6 pk */
758 1.6 pk f_print(fout, "\t\tif (strcmp(mname, \"sockmod\") == 0) {\n");
759 1.6 pk f_print(fout, "\t\t\tif (ioctl(0, I_POP, 0) || ioctl(0, I_PUSH, \"timod\")) {\n");
760 1.6 pk sprintf(_errbuf, "could not get the right module");
761 1.6 pk print_err_message("\t\t\t\t");
762 1.6 pk f_print(fout, "\t\t\t\texit(1);\n");
763 1.6 pk f_print(fout, "\t\t\t}\n");
764 1.6 pk f_print(fout, "\t\t}\n");
765 1.10 lukem if (timerflag)
766 1.10 lukem f_print(fout, "\t\tpmclose = (t_getstate(0) != T_DATAXFER);\n");
767 1.6 pk f_print(fout, "\t\tif ((%s = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) {\n",
768 1.10 lukem TRANSP);
769 1.6 pk sprintf(_errbuf, "cannot create server handle");
770 1.6 pk print_err_message("\t\t\t");
771 1.6 pk f_print(fout, "\t\t\texit(1);\n");
772 1.6 pk f_print(fout, "\t\t}\n");
773 1.6 pk f_print(fout, "\t\tif (nconf)\n");
774 1.6 pk f_print(fout, "\t\t\tfreenetconfigent(nconf);\n");
775 1.6 pk for (l = defined; l != NULL; l = l->next) {
776 1.6 pk def = (definition *) l->val;
777 1.6 pk if (def->def_kind != DEF_PROGRAM) {
778 1.6 pk continue;
779 1.6 pk }
780 1.6 pk for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
781 1.6 pk f_print(fout,
782 1.10 lukem "\t\tif (!svc_reg(%s, %s, %s, ",
783 1.10 lukem TRANSP, def->def_name, vp->vers_name);
784 1.6 pk pvname(def->def_name, vp->vers_num);
785 1.6 pk f_print(fout, ", 0)) {\n");
786 1.6 pk (void) sprintf(_errbuf, "unable to register (%s, %s).",
787 1.10 lukem def->def_name, vp->vers_name);
788 1.6 pk print_err_message("\t\t\t");
789 1.6 pk f_print(fout, "\t\t\texit(1);\n");
790 1.6 pk f_print(fout, "\t\t}\n");
791 1.6 pk }
792 1.6 pk }
793 1.6 pk if (timerflag) {
794 1.6 pk f_print(fout, "\t\tif (pmclose) {\n");
795 1.25 christos f_print(fout, "\t\t\t(void) signal(SIGALRM, (SIGPF)closedown);\n");
796 1.6 pk f_print(fout, "\t\t\t(void) alarm(_RPCSVC_CLOSEDOWN);\n");
797 1.6 pk f_print(fout, "\t\t}\n");
798 1.6 pk }
799 1.6 pk f_print(fout, "\t\tsvc_run();\n");
800 1.6 pk f_print(fout, "\t\texit(1);\n");
801 1.6 pk f_print(fout, "\t\t/* NOTREACHED */\n");
802 1.6 pk f_print(fout, "\t}\n");
803 1.6 pk }
804 1.6 pk /*
805 1.6 pk * Support for backgrounding the server if self started.
806 1.6 pk */
807 1.8 christos static void
808 1.24 dholland write_rpc_svc_fg(char *infile, const char *sp)
809 1.6 pk {
810 1.6 pk f_print(fout, "#ifndef RPC_SVC_FG\n");
811 1.6 pk f_print(fout, "%sint size;\n", sp);
812 1.10 lukem if (tirpcflag)
813 1.10 lukem f_print(fout, "%sstruct rlimit rl;\n", sp);
814 1.6 pk if (inetdflag)
815 1.6 pk f_print(fout, "%sint pid, i;\n\n", sp);
816 1.6 pk f_print(fout, "%spid = fork();\n", sp);
817 1.6 pk f_print(fout, "%sif (pid < 0) {\n", sp);
818 1.29 christos f_print(fout, "%s\terr(EXIT_FAILURE, \"cannot fork\");\n", sp);
819 1.6 pk f_print(fout, "%s}\n", sp);
820 1.6 pk f_print(fout, "%sif (pid)\n", sp);
821 1.6 pk f_print(fout, "%s\texit(0);\n", sp);
822 1.6 pk /* get number of file descriptors */
823 1.10 lukem if (tirpcflag) {
824 1.10 lukem f_print(fout, "%srl.rlim_max = 0;\n", sp);
825 1.29 christos f_print(fout, "%sif (getrlimit(RLIMIT_NOFILE, &rl) == -1)\n", sp);
826 1.29 christos f_print(fout, "%s\terr(EXIT_FAILURE, \"getrlimit(RLIMIT_NOFILE)\");\n", sp);
827 1.10 lukem f_print(fout, "%sif ((size = rl.rlim_max) == 0)\n", sp);
828 1.10 lukem f_print(fout, "%s\texit(1);\n", sp);
829 1.6 pk } else {
830 1.10 lukem f_print(fout, "%ssize = getdtablesize();\n", sp);
831 1.6 pk }
832 1.6 pk
833 1.6 pk f_print(fout, "%sfor (i = 0; i < size; i++)\n", sp);
834 1.6 pk f_print(fout, "%s\t(void) close(i);\n", sp);
835 1.6 pk /* Redirect stderr and stdout to console */
836 1.6 pk f_print(fout, "%si = open(\"/dev/console\", 2);\n", sp);
837 1.6 pk f_print(fout, "%s(void) dup2(i, 1);\n", sp);
838 1.6 pk f_print(fout, "%s(void) dup2(i, 2);\n", sp);
839 1.6 pk /* This removes control of the controlling terminal */
840 1.10 lukem if (tirpcflag)
841 1.10 lukem f_print(fout, "%ssetsid();\n", sp);
842 1.6 pk else {
843 1.10 lukem f_print(fout, "%si = open(\"/dev/tty\", 2);\n", sp);
844 1.10 lukem f_print(fout, "%sif (i >= 0) {\n", sp);
845 1.23 plunky f_print(fout, "%s\t(void) ioctl(i, TIOCNOTTY, NULL);\n", sp);
846 1.10 lukem f_print(fout, "%s\t(void) close(i);\n", sp);
847 1.10 lukem f_print(fout, "%s}\n", sp);
848 1.6 pk }
849 1.6 pk if (!logflag)
850 1.6 pk open_log_file(infile, sp);
851 1.6 pk f_print(fout, "#endif\n");
852 1.6 pk if (logflag)
853 1.6 pk open_log_file(infile, sp);
854 1.6 pk }
855 1.6 pk
856 1.8 christos static void
857 1.24 dholland open_log_file(char *infile, const char *sp)
858 1.6 pk {
859 1.24 dholland char *s, *p;
860 1.6 pk
861 1.6 pk s = strrchr(infile, '.');
862 1.10 lukem if (s)
863 1.6 pk *s = '\0';
864 1.10 lukem p = strrchr(infile, '/');
865 1.10 lukem if (p)
866 1.10 lukem p++;
867 1.10 lukem else
868 1.10 lukem p = infile;
869 1.10 lukem f_print(fout, "%sopenlog(\"%s\", LOG_PID, LOG_DAEMON);\n", sp, p);
870 1.6 pk if (s)
871 1.6 pk *s = '.';
872 1.6 pk }
873 1.6 pk
874 1.6 pk /*
875 1.6 pk * write a registration for the given transport for Inetd
876 1.6 pk */
877 1.6 pk void
878 1.24 dholland write_inetd_register(const char *transp)
879 1.6 pk {
880 1.10 lukem list *l;
881 1.6 pk definition *def;
882 1.6 pk version_list *vp;
883 1.24 dholland const char *sp;
884 1.10 lukem int isudp;
885 1.10 lukem char tmpbuf[32];
886 1.6 pk
887 1.6 pk if (inetdflag)
888 1.6 pk sp = "\t";
889 1.6 pk else
890 1.6 pk sp = "";
891 1.6 pk if (streq(transp, "udp"))
892 1.6 pk isudp = 1;
893 1.6 pk else
894 1.6 pk isudp = 0;
895 1.6 pk f_print(fout, "\n");
896 1.6 pk if (inetdflag) {
897 1.6 pk f_print(fout, "\tif ((_rpcfdtype == 0) || (_rpcfdtype == %s)) {\n",
898 1.10 lukem isudp ? "SOCK_DGRAM" : "SOCK_STREAM");
899 1.6 pk }
900 1.6 pk if (inetdflag && streq(transp, "tcp")) {
901 1.6 pk f_print(fout, "%s\tif (_rpcpmstart)\n", sp);
902 1.6 pk
903 1.6 pk f_print(fout, "%s\t\t%s = svc%s_create(%s",
904 1.10 lukem sp, TRANSP, "fd", inetdflag ? "sock" : "RPC_ANYSOCK");
905 1.6 pk if (!isudp)
906 1.6 pk f_print(fout, ", 0, 0");
907 1.6 pk f_print(fout, ");\n");
908 1.6 pk
909 1.6 pk f_print(fout, "%s\telse\n", sp);
910 1.6 pk
911 1.6 pk f_print(fout, "%s\t\t%s = svc%s_create(%s",
912 1.10 lukem sp, TRANSP, transp, inetdflag ? "sock" : "RPC_ANYSOCK");
913 1.6 pk if (!isudp)
914 1.6 pk f_print(fout, ", 0, 0");
915 1.6 pk f_print(fout, ");\n");
916 1.6 pk
917 1.6 pk } else {
918 1.6 pk f_print(fout, "%s\t%s = svc%s_create(%s",
919 1.10 lukem sp, TRANSP, transp, inetdflag ? "sock" : "RPC_ANYSOCK");
920 1.6 pk if (!isudp)
921 1.6 pk f_print(fout, ", 0, 0");
922 1.6 pk f_print(fout, ");\n");
923 1.6 pk }
924 1.6 pk f_print(fout, "%s\tif (%s == NULL) {\n", sp, TRANSP);
925 1.6 pk (void) sprintf(_errbuf, "cannot create %s service.", transp);
926 1.6 pk (void) sprintf(tmpbuf, "%s\t\t", sp);
927 1.6 pk print_err_message(tmpbuf);
928 1.6 pk f_print(fout, "%s\t\texit(1);\n", sp);
929 1.6 pk f_print(fout, "%s\t}\n", sp);
930 1.6 pk
931 1.6 pk if (inetdflag) {
932 1.6 pk f_print(fout, "%s\tif (!_rpcpmstart)\n\t", sp);
933 1.6 pk f_print(fout, "%s\tproto = IPPROTO_%s;\n",
934 1.10 lukem sp, isudp ? "UDP" : "TCP");
935 1.6 pk }
936 1.6 pk for (l = defined; l != NULL; l = l->next) {
937 1.6 pk def = (definition *) l->val;
938 1.6 pk if (def->def_kind != DEF_PROGRAM) {
939 1.6 pk continue;
940 1.6 pk }
941 1.6 pk for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
942 1.6 pk f_print(fout, "%s\tif (!svc_register(%s, %s, %s, ",
943 1.10 lukem sp, TRANSP, def->def_name, vp->vers_name);
944 1.6 pk pvname(def->def_name, vp->vers_num);
945 1.6 pk if (inetdflag)
946 1.6 pk f_print(fout, ", proto)) {\n");
947 1.10 lukem else
948 1.6 pk f_print(fout, ", IPPROTO_%s)) {\n",
949 1.10 lukem isudp ? "UDP" : "TCP");
950 1.6 pk (void) sprintf(_errbuf, "unable to register (%s, %s, %s).",
951 1.10 lukem def->def_name, vp->vers_name, transp);
952 1.6 pk print_err_message(tmpbuf);
953 1.6 pk f_print(fout, "%s\t\texit(1);\n", sp);
954 1.6 pk f_print(fout, "%s\t}\n", sp);
955 1.6 pk }
956 1.6 pk }
957 1.6 pk if (inetdflag)
958 1.6 pk f_print(fout, "\t}\n");
959 1.14 mycroft }
960 1.14 mycroft
961 1.24 dholland static const char *
962 1.24 dholland aster(const char *type)
963 1.14 mycroft {
964 1.14 mycroft if (isvectordef(type, REL_ALIAS)) {
965 1.14 mycroft return ("");
966 1.14 mycroft } else {
967 1.14 mycroft return ("*");
968 1.14 mycroft }
969 1.1 glass }
970