]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - support/nfs/rpcmisc.c
nfs-utils: Clean up support/nfs/rpcmisc.c:closedown()
[nfs-utils.git] / support / nfs / rpcmisc.c
index eb5629aec07af9297f95385d2f26d1e8a38fe2d5..dab2be8693e58c641e31232e6e1458508c1e348f 100644 (file)
@@ -1,9 +1,8 @@
 /*
- * support/nfs/rpcmisc.c
+ * Miscellaneous functions for RPC service startup and shutdown.
  *
- * Miscellaneous functions for RPC startup and shutdown.
  * This code is partially snarfed from rpcgen -s tcp -s udp,
- * partly written by Mark Shand, Donald Becker, and Rick 
+ * partly written by Mark Shand, Donald Becker, and Rick
  * Sladkey. It was tweaked slightly by Olaf Kirch to be
  * usable by both unfsd and mountd.
  *
@@ -38,7 +37,6 @@
 #define socklen_t int
 #endif
 
-static void    closedown(int sig);
 static int     makesock(int port, int proto);
 
 #define _RPCSVC_CLOSEDOWN      120
@@ -46,6 +44,31 @@ int  _rpcpmstart = 0;
 int    _rpcfdtype = 0;
 int    _rpcsvcdirty = 0;
 
+static void
+closedown(int sig)
+{
+       (void) signal(sig, closedown);
+
+       if (_rpcsvcdirty == 0) {
+               static int size;
+               int i, openfd;
+
+               if (_rpcfdtype == SOCK_DGRAM)
+                       exit(0);
+
+               if (size == 0)
+                       size = getdtablesize();
+
+               for (i = 0, openfd = 0; i < size && openfd < 2; i++)
+                       if (FD_ISSET(i, &svc_fdset))
+                               openfd++;
+               if (openfd <= 1)
+                       exit(0);
+       }
+
+       (void) alarm(_RPCSVC_CLOSEDOWN);
+}
+
 void
 rpc_init(char *name, int prog, int vers,
         void (*dispatch)(struct svc_req *, register SVCXPRT *),
@@ -60,7 +83,7 @@ rpc_init(char *name, int prog, int vers,
        sock = 0;
        if (getsockname(0, (struct sockaddr *) &saddr, &asize) == 0
            && saddr.sin_family == AF_INET) {
-               socklen_t ssize = sizeof (int);
+               socklen_t ssize = sizeof(int);
                int fdtype = 0;
                if (getsockopt(0, SOL_SOCKET, SO_TYPE,
                                (char *)&fdtype, &ssize) == -1)
@@ -80,7 +103,7 @@ rpc_init(char *name, int prog, int vers,
 
        if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) {
                static SVCXPRT *last_transp = NULL;
+
                if (_rpcpmstart == 0) {
                        if (last_transp
                            && (!defport || defport == last_transp->xp_port)) {
@@ -135,33 +158,11 @@ rpc_init(char *name, int prog, int vers,
        }
 
        if (_rpcpmstart) {
-               signal (SIGALRM, closedown);
-               alarm (_RPCSVC_CLOSEDOWN);
+               signal(SIGALRM, closedown);
+               alarm(_RPCSVC_CLOSEDOWN);
        }
 }
 
-static void closedown(sig)
-int sig;
-{
-       (void) signal(sig, closedown);
-       if (_rpcsvcdirty == 0) {
-               static int size;
-               int i, openfd;
-
-               if (_rpcfdtype == SOCK_DGRAM)
-                       exit(0);
-               if (size == 0) {
-                       size = getdtablesize();
-               }
-               for (i = 0, openfd = 0; i < size && openfd < 2; i++)
-                       if (FD_ISSET(i, &svc_fdset))
-                               openfd++;
-               if (openfd <= 1)
-                       exit(0);
-       }
-       (void) alarm(_RPCSVC_CLOSEDOWN);
-}
-
 /*
  * Create listener socket for a given port
  *