Deleted Added
full compact
nfscbd.c (192811) nfscbd.c (193070)
1/*-
2 * Copyright (c) 2009 Rick Macklem, University of Guelph
3 * 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

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

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2009 Rick Macklem, University of Guelph
3 * 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

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

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/usr.sbin/nfscbd/nfscbd.c 192811 2009-05-26 15:19:04Z rmacklem $");
29__FBSDID("$FreeBSD: head/usr.sbin/nfscbd/nfscbd.c 193070 2009-05-29 22:19:45Z delphij $");
30
31#include <sys/param.h>
32#include <sys/ioctl.h>
33#include <sys/linker.h>
34#include <sys/module.h>
35#include <sys/mount.h>
36#include <sys/socket.h>
37#include <sys/socketvar.h>

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

68#define syslog(e, s) fprintf(stderr,(s))
69int debug = 1;
70#else
71int debug = 0;
72#endif
73
74pid_t children;
75
30
31#include <sys/param.h>
32#include <sys/ioctl.h>
33#include <sys/linker.h>
34#include <sys/module.h>
35#include <sys/mount.h>
36#include <sys/socket.h>
37#include <sys/socketvar.h>

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

68#define syslog(e, s) fprintf(stderr,(s))
69int debug = 1;
70#else
71int debug = 0;
72#endif
73
74pid_t children;
75
76void nonfs(int);
77void reapchild(int);
78void usage(void);
79void cleanup(int);
80void child_cleanup(int);
81void nfscbd_exit(int);
82void killchildren(void);
76static void nonfs(int);
77static void reapchild(int);
78static void usage(void);
79static void cleanup(int);
80static void child_cleanup(int);
81static void nfscbd_exit(int);
82static void killchildren(void);
83
84/*
85 * Nfs callback server daemon.
86 *
87 * 1 - do file descriptor and signal cleanup
88 * 2 - fork the nfscbd(s)
89 * 4 - create callback server socket(s)
90 * 5 - set up server socket for rpc
91 *
92 * For connectionless protocols, just pass the socket into the kernel via.
93 * nfssvc().
94 * For connection based sockets, loop doing accepts. When you get a new
95 * socket from accept, pass the msgsock into the kernel via. nfssvc().
96 */
97int
83
84/*
85 * Nfs callback server daemon.
86 *
87 * 1 - do file descriptor and signal cleanup
88 * 2 - fork the nfscbd(s)
89 * 4 - create callback server socket(s)
90 * 5 - set up server socket for rpc
91 *
92 * For connectionless protocols, just pass the socket into the kernel via.
93 * nfssvc().
94 * For connection based sockets, loop doing accepts. When you get a new
95 * socket from accept, pass the msgsock into the kernel via. nfssvc().
96 */
97int
98main(int argc, char *argv[], char **envp)
98main(int argc, char *argv[])
99{
99{
100 struct group *grp;
101 struct nfscbd_args nfscbdargs;
102 struct nfsd_nfscbd_args nfscbdargs2;
100 struct nfscbd_args nfscbdargs;
101 struct nfsd_nfscbd_args nfscbdargs2;
103 struct passwd *pwd;
104 struct ucred *cr;
105 struct sockaddr_in inetaddr, inetpeer;
102 struct sockaddr_in inetaddr, inetpeer;
106 struct timeval ktv;
107 fd_set ready, sockbits;
103 fd_set ready, sockbits;
108 int ch, connect_type_cnt, i, len, maxsock, msgsock, error;
104 int ch, connect_type_cnt, len, maxsock, msgsock, error;
109 int nfssvc_flag, on, sock, tcpsock, ret, mustfreeai = 0;
105 int nfssvc_flag, on, sock, tcpsock, ret, mustfreeai = 0;
110 char *cp, **cpp, princname[128];
106 char *cp, princname[128];
111 char myname[MAXHOSTNAMELEN], *myfqdnname = NULL;
112 struct addrinfo *aip, hints;
113 pid_t pid;
107 char myname[MAXHOSTNAMELEN], *myfqdnname = NULL;
108 struct addrinfo *aip, hints;
109 pid_t pid;
114 sigset_t signew;
115 short myport = NFSV4_CBPORT;
116
117 if (modfind("nfscl") < 0) {
118 /* Not present in kernel, try loading it */
119 if (kldload("nfscl") < 0 ||
120 modfind("nfscl") < 0)
121 errx(1, "nfscl is not available");
122 }

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

315 nfscbdargs.name = (caddr_t)&inetpeer;
316 nfscbdargs.namelen = sizeof(inetpeer);
317 nfssvc(NFSSVC_CBADDSOCK, &nfscbdargs);
318 (void)close(msgsock);
319 }
320 }
321}
322
110 short myport = NFSV4_CBPORT;
111
112 if (modfind("nfscl") < 0) {
113 /* Not present in kernel, try loading it */
114 if (kldload("nfscl") < 0 ||
115 modfind("nfscl") < 0)
116 errx(1, "nfscl is not available");
117 }

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

310 nfscbdargs.name = (caddr_t)&inetpeer;
311 nfscbdargs.namelen = sizeof(inetpeer);
312 nfssvc(NFSSVC_CBADDSOCK, &nfscbdargs);
313 (void)close(msgsock);
314 }
315 }
316}
317
323void
318static void
324usage(void)
325{
326
327 errx(1, "usage: nfscbd %s", USAGE);
328}
329
319usage(void)
320{
321
322 errx(1, "usage: nfscbd %s", USAGE);
323}
324
330void
331nonfs(int signo)
325static void
326nonfs(int signo __unused)
332{
333 syslog(LOG_ERR, "missing system call: NFS not available");
334}
335
327{
328 syslog(LOG_ERR, "missing system call: NFS not available");
329}
330
336void
337reapchild(int signo)
331static void
332reapchild(int signo __unused)
338{
339 pid_t pid;
333{
334 pid_t pid;
340 int i;
341
342 while ((pid = wait3(NULL, WNOHANG, NULL)) > 0) {
343 if (pid == children)
344 children = -1;
345 }
346}
347
335
336 while ((pid = wait3(NULL, WNOHANG, NULL)) > 0) {
337 if (pid == children)
338 children = -1;
339 }
340}
341
348void
342static void
349killchildren(void)
350{
343killchildren(void)
344{
351 int i;
352
353 if (children > 0)
354 kill(children, SIGKILL);
355}
356
357/*
358 * Cleanup master after SIGUSR1.
359 */
345
346 if (children > 0)
347 kill(children, SIGKILL);
348}
349
350/*
351 * Cleanup master after SIGUSR1.
352 */
360void
361cleanup(int signo)
353static void
354cleanup(int signo __unused)
362{
363 nfscbd_exit(0);
364}
365
366/*
367 * Cleanup child after SIGUSR1.
368 */
355{
356 nfscbd_exit(0);
357}
358
359/*
360 * Cleanup child after SIGUSR1.
361 */
369void
370child_cleanup(int signo)
362static void
363child_cleanup(int signo __unused)
371{
372 exit(0);
373}
374
364{
365 exit(0);
366}
367
375void
376nfscbd_exit(int status)
368static void
369nfscbd_exit(int status __unused)
377{
378 killchildren();
379 exit(status);
380}
370{
371 killchildren();
372 exit(status);
373}