Deleted Added
sdiff udiff text old ( 149733 ) new ( 152398 )
full compact
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *

--- 21 unchanged lines hidden (view full) ---

30#if 0
31#ifndef lint
32#ident "@(#)rpc_svcout.c 1.4 90/04/13 SMI"
33static char sccsid[] = "@(#)rpc_svcout.c 1.29 89/03/30 (C) 1987 SMI";
34#endif
35#endif
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_svcout.c 152398 2005-11-13 21:17:24Z dwmalone $");
39
40/*
41 * rpc_svcout.c, Server-skeleton outputter for the RPC protocol compiler
42 * Copyright (C) 1987, Sun Microsystems, Inc.
43 */
44#include <stdio.h>
45#include <string.h>
46#include "rpc_parse.h"
47#include "rpc_scan.h"
48#include "rpc_util.h"
49
50static char RQSTP[] = "rqstp";
51static char TRANSP[] = "transp";
52static char ARG[] = "argument";
53static char RESULT[] = "result";
54static char ROUTINE[] = "local";
55static char RETVAL[] = "retval";
56
57char _errbuf[256]; /* For all messages */
58
59void internal_proctype( proc_list * );
60static void write_real_program( definition * );
61static void write_program(definition *, const char *);
62static void printerr(const char *, const char *);
63static void printif(const char *, const char *, const char *, const char *);
64static void write_inetmost(const char *);
65static void print_return(const char *);
66static void print_pmapunset(const char *);
67static void print_err_message(const char *);
68static void write_timeout_func( void );
69static void write_pm_most(const char *, int);
70static void write_rpc_svc_fg(const char *, const char *);
71static void open_log_file(const char *, const char *);
72static void write_msg_out( void );
73
74
75static void
76p_xdrfunc(const char *rname, const char *typename)
77{
78 f_print(fout, "\t\txdr_%s = (xdrproc_t) xdr_%s;\n",
79 rname, stringfix(typename));
80}
81
82void
83internal_proctype(proc_list *plist)
84{
85 f_print(fout, "static ");
86 ptype(plist->res_prefix, plist->res_type, 1);
87 f_print(fout, "*");
88}
89
90
91/*
92 * write most of the service, that is, everything but the registrations.
93 */
94void
95write_most(const char *infile, int netflag, int nomain)
96{
97 if (inetdflag || pmflag) {
98 const char *var_type;
99 var_type = (nomain? "extern" : "static");
100 f_print(fout, "%s int _rpcpmstart;", var_type);
101 f_print(fout, "\t\t/* Started by a port monitor ? */\n");
102 if (!tirpcflag || tirpc_socket) {
103 f_print(fout, "%s int _rpcfdtype;", var_type);
104 f_print(fout, "\n\t\t /* Whether Stream or \
105Datagram ? */\n");
106 }

--- 74 unchanged lines hidden (view full) ---

181 open_log_file(infile, "\t");
182 }
183}
184
185/*
186 * write a registration for the given transport
187 */
188void
189write_netid_register(const char *transp)
190{
191 list *l;
192 definition *def;
193 version_list *vp;
194 const char *sp;
195 char tmpbuf[32];
196
197 sp = "";
198 f_print(fout, "\n");
199 f_print(fout, "%s\tnconf = getnetconfigent(\"%s\");\n", sp, transp);
200 f_print(fout, "%s\tif (nconf == NULL) {\n", sp);
201 (void) sprintf(_errbuf, "cannot find %s netid.", transp);
202 sprintf(tmpbuf, "%s\t\t", sp);

--- 39 unchanged lines hidden (view full) ---

242 }
243 f_print(fout, "%s\tfreenetconfigent(nconf);\n", sp);
244}
245
246/*
247 * write a registration for the given transport for TLI
248 */
249void
250write_nettype_register(const char *transp)
251{
252 list *l;
253 definition *def;
254 version_list *vp;
255
256 for (l = defined; l != NULL; l = l->next) {
257 def = (definition *) l->val;
258 if (def->def_kind != DEF_PROGRAM) {

--- 17 unchanged lines hidden (view full) ---

276 }
277 }
278}
279
280/*
281 * write the rest of the service
282 */
283void
284write_rest(void)
285{
286 f_print(fout, "\n");
287 if (inetdflag) {
288 f_print(fout, "\tif (%s == (SVCXPRT *)NULL) {\n", TRANSP);
289 (void) sprintf(_errbuf, "could not create a handle");
290 print_err_message("\t\t");
291 f_print(fout, "\t\texit(1);\n");
292 f_print(fout, "\t}\n");

--- 10 unchanged lines hidden (view full) ---

303 (void) sprintf(_errbuf, "svc_run returned");
304 print_err_message("\t");
305 f_print(fout, "\texit(1);\n");
306 f_print(fout, "\t/* NOTREACHED */\n");
307 f_print(fout, "}\n");
308}
309
310void
311write_programs(const char *storage)
312{
313 list *l;
314 definition *def;
315
316 /* write out stubs for procedure definitions */
317 for (l = defined; l != NULL; l = l->next) {
318 def = (definition *) l->val;
319 if (def->def_kind == DEF_PROGRAM) {

--- 14 unchanged lines hidden (view full) ---

334
335/*
336 * write out definition of internal function (e.g. _printmsg_1(...))
337 * which calls server's defintion of actual function (e.g. printmsg_1(...)).
338 * Unpacks single user argument of printmsg_1 to call-by-value format
339 * expected by printmsg_1.
340 */
341static void
342write_real_program(definition *def)
343{
344 version_list *vp;
345 proc_list *proc;
346 decl_list *l;
347
348 if (!newstyle) return; /* not needed for old style */
349 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
350 for (proc = vp->procs; proc != NULL; proc = proc->next) {

--- 37 unchanged lines hidden (view full) ---

388 if (mtflag)
389 f_print(fout, "%s, ",RESULT);
390 f_print(fout, "%s));\n}\n", RQSTP);
391 }
392 }
393}
394
395static void
396write_program(definition *def, const char *storage)
397{
398 version_list *vp;
399 proc_list *proc;
400 int filled;
401
402 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
403 f_print(fout, "\n");
404 if (storage != NULL) {

--- 154 unchanged lines hidden (view full) ---

559 f_print(fout, "\n");
560 };
561 print_return("\t");
562 f_print(fout, "}\n");
563 }
564}
565
566static void
567printerr(const char *err, const char *transp)
568{
569 f_print(fout, "\t\tsvcerr_%s(%s);\n", err, transp);
570}
571
572static void
573printif(const char *proc, const char *transp, const char *prefix,
574 const char *arg)
575{
576 f_print(fout, "\tif (!svc_%s(%s, xdr_%s, (char *)%s%s)) {\n",
577 proc, transp, arg, prefix, arg);
578}
579
580int
581nullproc(proc_list *proc)
582{
583 for (; proc != NULL; proc = proc->next) {
584 if (streq(proc->proc_num, "0")) {
585 return (1);
586 }
587 }
588 return (0);
589}
590
591static void
592write_inetmost(const char *infile)
593{
594 f_print(fout, "\tregister SVCXPRT *%s;\n", TRANSP);
595 f_print(fout, "\tint sock;\n");
596 f_print(fout, "\tint proto;\n");
597 f_print(fout, "\tstruct sockaddr_in saddr;\n");
598 f_print(fout, "\tsocklen_t asize = sizeof (saddr);\n");
599 f_print(fout, "\n");
600 f_print(fout,

--- 11 unchanged lines hidden (view full) ---

612 f_print(fout, "\t} else {\n");
613 write_rpc_svc_fg(infile, "\t\t");
614 f_print(fout, "\t\tsock = RPC_ANYSOCK;\n");
615 print_pmapunset("\t\t");
616 f_print(fout, "\t}\n");
617}
618
619static void
620print_return(const char *space)
621{
622 if (exitnow)
623 f_print(fout, "%sexit(0);\n", space);
624 else {
625 if (timerflag) {
626 if (mtflag)
627 f_print(fout, "%smutex_lock(&_svcstate_lock);\n", space);
628 f_print(fout, "%s_rpcsvcstate = _SERVED;\n", space);
629 if (mtflag)
630 f_print(fout, "%smutex_unlock(&_svcstate_lock);\n", space);
631 }
632 f_print(fout, "%sreturn;\n", space);
633 }
634}
635
636static void
637print_pmapunset(const char *space)
638{
639 list *l;
640 definition *def;
641 version_list *vp;
642
643 for (l = defined; l != NULL; l = l->next) {
644 def = (definition *) l->val;
645 if (def->def_kind == DEF_PROGRAM) {
646 for (vp = def->def.pr.versions; vp != NULL;
647 vp = vp->next) {
648 f_print(fout, "%s(void) pmap_unset(%s, %s);\n",
649 space, def->def_name, vp->vers_name);
650 }
651 }
652 }
653}
654
655static void
656print_err_message(const char *space)
657{
658 if (logflag)
659 f_print(fout, "%ssyslog(LOG_ERR, \"%s\");\n", space, _errbuf);
660 else if (inetdflag || pmflag)
661 f_print(fout, "%s_msgout(\"%s\");\n", space, _errbuf);
662 else
663 f_print(fout, "%sfprintf(stderr, \"%s\");\n", space, _errbuf);
664}
665
666/*
667 * Write the server auxiliary function (_msgout, timeout)
668 */
669void
670write_svc_aux(int nomain)
671{
672 if (!logflag)
673 write_msg_out();
674 if (!nomain)
675 write_timeout_func();
676}
677
678/*

--- 83 unchanged lines hidden (view full) ---

762 f_print(fout, "}\n");
763
764}
765
766/*
767 * Write the most of port monitor support
768 */
769static void
770write_pm_most(const char *infile, int netflag)
771{
772 list *l;
773 definition *def;
774 version_list *vp;
775
776 if (tirpc_socket) {
777 f_print(fout,
778 "\tif (getsockname(0, (struct sockaddr *)&saddr, &asize) == 0) {\n");

--- 106 unchanged lines hidden (view full) ---

885 f_print(fout, "\t\t/* NOTREACHED */\n");
886 f_print(fout, "\t}");
887}
888
889/*
890 * Support for backgrounding the server if self started.
891 */
892static void
893write_rpc_svc_fg(const char *infile, const char *sp)
894{
895 f_print(fout, "#ifndef RPC_SVC_FG\n");
896 f_print(fout, "%sint size;\n", sp);
897 if (tirpcflag)
898 f_print(fout, "%sstruct rlimit rl;\n", sp);
899 if (inetdflag)
900 f_print(fout, "%sint pid, i;\n\n", sp);
901 f_print(fout, "%spid = fork();\n", sp);

--- 33 unchanged lines hidden (view full) ---

935 if (!logflag)
936 open_log_file(infile, sp);
937 f_print(fout, "#endif\n");
938 if (logflag)
939 open_log_file(infile, sp);
940}
941
942static void
943open_log_file(const char *infile, const char *sp)
944{
945 char *s;
946
947 s = strrchr(infile, '.');
948 if (s)
949 *s = '\0';
950 f_print(fout, "%sopenlog(\"%s\", LOG_PID, LOG_DAEMON);\n", sp, infile);
951 if (s)
952 *s = '.';
953}
954
955
956
957
958/*
959 * write a registration for the given transport for Inetd
960 */
961void
962write_inetd_register(const char *transp)
963{
964 list *l;
965 definition *def;
966 version_list *vp;
967 const char *sp;
968 int isudp;
969 char tmpbuf[32];
970
971 if (inetdflag)
972 sp = "\t";
973 else
974 sp = "";
975 if (streq(transp, "udp"))

--- 53 unchanged lines hidden ---