Deleted Added
full compact
statd.c (162263) statd.c (168325)
1/*
2 * Copyright (c) 1995
3 * A.R. Gordon (andrew.gordon@net-tel.co.uk). All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

31 *
32 */
33
34/* main() function for status monitor daemon. Some of the code in this */
35/* file was generated by running rpcgen /usr/include/rpcsvc/sm_inter.x */
36/* The actual program logic is in the file procs.c */
37
38#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1995
3 * A.R. Gordon (andrew.gordon@net-tel.co.uk). All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

31 *
32 */
33
34/* main() function for status monitor daemon. Some of the code in this */
35/* file was generated by running rpcgen /usr/include/rpcsvc/sm_inter.x */
36/* The actual program logic is in the file procs.c */
37
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/usr.sbin/rpc.statd/statd.c 162263 2006-09-13 05:01:25Z charnier $");
39__FBSDID("$FreeBSD: head/usr.sbin/rpc.statd/statd.c 168325 2007-04-03 21:15:00Z matteo $");
40
41#include <err.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <rpc/rpc.h>
45#include <rpc/rpc_com.h>
46#include <string.h>
47#include <syslog.h>
48#include <sys/types.h>
49#include <sys/wait.h>
50#include <signal.h>
51#include <unistd.h>
52#include "statd.h"
53
54int debug = 0; /* Controls syslog() calls for debug messages */
55
56static void handle_sigchld(int sig);
57static void usage(void);
58
40
41#include <err.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <rpc/rpc.h>
45#include <rpc/rpc_com.h>
46#include <string.h>
47#include <syslog.h>
48#include <sys/types.h>
49#include <sys/wait.h>
50#include <signal.h>
51#include <unistd.h>
52#include "statd.h"
53
54int debug = 0; /* Controls syslog() calls for debug messages */
55
56static void handle_sigchld(int sig);
57static void usage(void);
58
59const char *transports[] = { "udp", "tcp", "udp6", "tcp6" };
60
59int
60main(int argc, char **argv)
61{
61int
62main(int argc, char **argv)
63{
64 SVCXPRT *transp;
62 struct sigaction sa;
65 struct sigaction sa;
63 int ch;
66 struct netconfig *nconf;
67 struct sockaddr_in sin;
68 struct sockaddr_in6 sin6;
69 int ch, i, maxindex, r, s, sock;
70 char *endptr;
64 int maxrec = RPC_MAXDATASIZE;
71 int maxrec = RPC_MAXDATASIZE;
72 in_port_t svcport = 0;
65
73
66 while ((ch = getopt(argc, argv, "d")) != -1)
74 while ((ch = getopt(argc, argv, "dp:")) != -1)
67 switch (ch) {
68 case 'd':
69 debug = 1;
70 break;
75 switch (ch) {
76 case 'd':
77 debug = 1;
78 break;
79 case 'p':
80 endptr = NULL;
81 svcport = (in_port_t)strtoul(optarg, &endptr, 10);
82 if (endptr == NULL || *endptr != '\0' || svcport == 0 ||
83 svcport >= IPPORT_MAX)
84 usage();
85 break;
71 default:
72 usage();
73 }
74 argc -= optind;
75 argv += optind;
76
77 (void)rpcb_unset(SM_PROG, SM_VERS, NULL);
78
86 default:
87 usage();
88 }
89 argc -= optind;
90 argv += optind;
91
92 (void)rpcb_unset(SM_PROG, SM_VERS, NULL);
93
94 /*
95 * Check if IPv6 support is present.
96 */
97 s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
98 if (s < 0)
99 maxindex = 2;
100 else {
101 close(s);
102 maxindex = 4;
103 }
104
105 if (svcport != 0) {
106 bzero(&sin, sizeof(struct sockaddr_in));
107 sin.sin_len = sizeof(struct sockaddr_in);
108 sin.sin_family = AF_INET;
109 sin.sin_port = htons(svcport);
110
111 bzero(&sin6, sizeof(struct sockaddr_in6));
112 sin6.sin6_len = sizeof(struct sockaddr_in6);
113 sin6.sin6_family = AF_INET6;
114 sin6.sin6_port = htons(svcport);
115 }
116
79 rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
80
117 rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
118
81 if (!svc_create(sm_prog_1, SM_PROG, SM_VERS, "udp"))
82 errx(1, "cannot create udp service");
83 if (!svc_create(sm_prog_1, SM_PROG, SM_VERS, "tcp"))
84 errx(1, "cannot create tcp service");
85 init_file("/var/db/statd.status");
119 for (i = 0; i < maxindex; i++) {
120 nconf = getnetconfigent(transports[i]);
121 if (nconf == NULL)
122 errx(1, "cannot get %s netconf: %s.", transports[i],
123 nc_sperror());
86
124
125 if (svcport != 0) {
126 if (strcmp(nconf->nc_netid, "udp6") == 0) {
127 sock = socket(AF_INET6, SOCK_DGRAM,
128 IPPROTO_UDP);
129 if (sock != -1) {
130 r = bindresvport_sa(sock,
131 (struct sockaddr *)&sin6);
132 if (r != 0) {
133 syslog(LOG_ERR, "bindresvport: %m");
134 exit(1);
135 }
136 }
137 } else if (strcmp(nconf->nc_netid, "udp") == 0) {
138 sock = socket(AF_INET, SOCK_DGRAM,
139 IPPROTO_UDP);
140 if (sock != -1) {
141 r = bindresvport(sock, &sin);
142 if (r != 0) {
143 syslog(LOG_ERR, "bindresvport: %m");
144 exit(1);
145 }
146 }
147 } else if (strcmp(nconf->nc_netid, "tcp6") == 0) {
148 sock = socket(AF_INET6, SOCK_STREAM,
149 IPPROTO_TCP);
150 if (sock != -1) {
151 r = bindresvport_sa(sock,
152 (struct sockaddr *)&sin6);
153 if (r != 0) {
154 syslog(LOG_ERR, "bindresvport: %m");
155 exit(1);
156 }
157 }
158 } else if (strcmp(nconf->nc_netid, "tcp") == 0) {
159 sock = socket(AF_INET, SOCK_STREAM,
160 IPPROTO_TCP);
161 if (sock != -1) {
162 r = bindresvport(sock, &sin);
163 if (r != 0) {
164 syslog(LOG_ERR, "bindresvport: %m");
165 exit(1);
166 }
167 }
168 }
169
170 transp = svc_tli_create(sock, nconf, NULL,
171 RPC_MAXDATASIZE, RPC_MAXDATASIZE);
172 } else {
173 transp = svc_tli_create(RPC_ANYFD, nconf, NULL,
174 RPC_MAXDATASIZE, RPC_MAXDATASIZE);
175 }
176
177 if (transp == NULL) {
178 errx(1, "cannot create %s service.", transports[i]);
179 /* NOTREACHED */
180 }
181 if (!svc_reg(transp, SM_PROG, SM_VERS, sm_prog_1, nconf)) {
182 errx(1, "unable to register (SM_PROG, NLM_SM, %s)",
183 transports[i]);
184 /* NOTREACHED */
185 }
186 init_file("/var/db/statd.status");
187 freenetconfigent(nconf);
188 }
189
87 /* Note that it is NOT sensible to run this program from inetd - the */
88 /* protocol assumes that it will run immediately at boot time. */
89 daemon(0, 0);
90 openlog("rpc.statd", 0, LOG_DAEMON);
91 if (debug) syslog(LOG_INFO, "Starting - debug enabled");
92 else syslog(LOG_INFO, "Starting");
93
94 /* Install signal handler to collect exit status of child processes */

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

104
105 svc_run(); /* Should never return */
106 exit(1);
107}
108
109static void
110usage()
111{
190 /* Note that it is NOT sensible to run this program from inetd - the */
191 /* protocol assumes that it will run immediately at boot time. */
192 daemon(0, 0);
193 openlog("rpc.statd", 0, LOG_DAEMON);
194 if (debug) syslog(LOG_INFO, "Starting - debug enabled");
195 else syslog(LOG_INFO, "Starting");
196
197 /* Install signal handler to collect exit status of child processes */

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

207
208 svc_run(); /* Should never return */
209 exit(1);
210}
211
212static void
213usage()
214{
112 fprintf(stderr, "usage: rpc.statd [-d]\n");
215 fprintf(stderr, "usage: rpc.statd [-d] [-p <port>]\n");
113 exit(1);
114}
115
116/* handle_sigchld ---------------------------------------------------------- */
117/*
118 Purpose: Catch SIGCHLD and collect process status
119 Retruns: Nothing.
120 Notes: No special action required, other than to collect the

--- 19 unchanged lines hidden ---
216 exit(1);
217}
218
219/* handle_sigchld ---------------------------------------------------------- */
220/*
221 Purpose: Catch SIGCHLD and collect process status
222 Retruns: Nothing.
223 Notes: No special action required, other than to collect the

--- 19 unchanged lines hidden ---