FBSD: typo fix
[openafs.git] / src / rx / FBSD / rx_knet.c
index c46085f..fef1d4f 100644 (file)
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID
-    ("$Header$");
 
-#ifdef AFS_FBSD40_ENV
 #include <sys/malloc.h>
 #include "rx/rx_kcommon.h"
 
@@ -43,11 +40,7 @@ osi_NetReceive(osi_socket asocket, struct sockaddr_in *addr,
     u.uio_resid = *alength;
     u.uio_segflg = UIO_SYSSPACE;
     u.uio_rw = UIO_READ;
-#ifdef AFS_FBSD50_ENV
     u.uio_td = NULL;
-#else
-    u.uio_procp = NULL;
-#endif
 
     if (haveGlock)
        AFS_GUNLOCK();
@@ -81,19 +74,64 @@ extern int rxk_ListenerPid;
 void
 osi_StopListener(void)
 {
+    struct sockaddr_in taddr;
+    struct iovec dvec;
     struct proc *p;
-
-    soclose(rx_socket);
+    char c;
+    c = '\0';
+
+    /*
+     * Have to drop global lock to safely do this.
+     * soclose() is currently protected by Giant,
+     * but pfind and psignal are MPSAFE.
+     */
+    int haveGlock = ISAFS_GLOCK();
+    if (haveGlock)
+       AFS_GUNLOCK();
+    soshutdown(rx_socket, SHUT_RDWR);
     p = pfind(rxk_ListenerPid);
-    if (p)
+    if (p) {
+       afs_warn("osi_StopListener: rxk_ListenerPid %u\n", rxk_ListenerPid);
+#if (__FreeBSD_version >= 900044)
+       kern_psignal(p, SIGUSR1);
+#else
        psignal(p, SIGUSR1);
+#endif
+       PROC_UNLOCK(p);
+    } else
+       afs_warn("osi_StopListener: rxk_Listener not found (pid %u)\n",
+           rxk_ListenerPid);
+
+    /* Avoid destroying socket until osi_NetReceive has
+    * had a chance to clean up.  Otherwise we can't restart. */
+    bzero(&taddr, sizeof(taddr));
+    taddr.sin_len = sizeof(struct sockaddr_in);
+    taddr.sin_family = AF_INET;
+    taddr.sin_port = rx_port;
+    taddr.sin_addr.s_addr = htonl(0x7f000001); /* no place like localhost */
+    bzero(&dvec, sizeof(dvec));
+    dvec.iov_base = &c;
+    dvec.iov_len = 1;
+    /* afs_osi_Sleep requires the GLOCK */
+    AFS_GLOCK();
+    while(rxk_ListenerPid) {
+       afs_warn("waiting for rxk_ListenerPid to die\n");
+       osi_NetSend(rx_socket, &taddr, &dvec, 1, 1, 0);
+       afs_osi_Sleep(&rxk_ListenerPid);
+    }
+    AFS_GUNLOCK();
+    /* in theory, we are now the only people doing anything with rx_socket */
+    soclose(rx_socket);
+
+    if (haveGlock)
+       AFS_GLOCK();
 }
 
 int
 osi_NetSend(osi_socket asocket, struct sockaddr_in *addr, struct iovec *dvec,
            int nvecs, afs_int32 alength, int istack)
 {
-    register afs_int32 code;
+    afs_int32 code;
     int i;
     struct iovec iov[RX_MAXIOVECS];
     struct uio u;
@@ -112,11 +150,7 @@ osi_NetSend(osi_socket asocket, struct sockaddr_in *addr, struct iovec *dvec,
     u.uio_resid = alength;
     u.uio_segflg = UIO_SYSSPACE;
     u.uio_rw = UIO_WRITE;
-#ifdef AFS_FBSD50_ENV
     u.uio_td = NULL;
-#else
-    u.uio_procp = NULL;
-#endif
 
     addr->sin_len = sizeof(struct sockaddr_in);
 
@@ -125,14 +159,9 @@ osi_NetSend(osi_socket asocket, struct sockaddr_in *addr, struct iovec *dvec,
 #if KNET_DEBUG
     printf("+");
 #endif
-#ifdef AFS_FBSD50_ENV
     code =
        sosend(asocket, (struct sockaddr *)addr, &u, NULL, NULL, 0,
               curthread);
-#else
-    code =
-       sosend(asocket, (struct sockaddr *)addr, &u, NULL, NULL, 0, curproc);
-#endif
 #if KNET_DEBUG
     if (code) {
        if (code == EINVAL)
@@ -154,7 +183,7 @@ static void rxk_fasttimo(void);
 /* start intercepting basic calls */
 rxk_init()
 {
-    register struct protosw *tpro, *last;
+    struct protosw *tpro, *last;
     if (rxk_initDone)
        return 0;
 
@@ -184,12 +213,12 @@ static void
 rxk_input(struct mbuf *am, int iphlen)
 {
     void (*tproc) ();
-    register unsigned short *tsp;
+    unsigned short *tsp;
     int hdr;
     struct udphdr *tu;
-    register struct ip *ti;
+    struct ip *ti;
     struct udpiphdr *tvu;
-    register int i;
+    int i;
     char *phandle;
     afs_int32 code;
     struct sockaddr_in taddr;
@@ -273,7 +302,6 @@ rxk_input(struct mbuf *am, int iphlen)
                 */
                data_len = ntohs(tu->uh_ulen);
                data_len -= 8;
-               AFS_RXGLOCK();
                if (!(*rxk_GetPacketProc) (&phandle, data_len)) {
                    if (rx_mb_to_packet(am, m_freem, 28, data_len, phandle)) {
                        /* XXX should just increment counter here.. */
@@ -284,7 +312,6 @@ rxk_input(struct mbuf *am, int iphlen)
                                                  rxk_portRocks[i], data_len);
                } else
                    m_freem(am);
-               AFS_RXGUNLOCK();
                USERPRI;
                return;
            }
@@ -336,7 +363,7 @@ rxk_fasttimo(void)
  * sometimes */
 static
 trysblock(sb)
-     register struct sockbuf *sb;
+     struct sockbuf *sb;
 {
     AFS_STATCNT(trysblock);
     if (sb->sb_flags & SB_LOCK) {
@@ -352,11 +379,11 @@ int
 osi_NetSend(osi_socket asocket, struct sockaddr_in *addr, struct iovec *dvec,
            int nvec, afs_int32 asize, int istack)
 {
-    register struct mbuf *tm, *um;
-    register afs_int32 code;
+    struct mbuf *tm, *um;
+    afs_int32 code;
     int s;
     struct mbuf *top = 0;
-    register struct mbuf *m, **mp;
+    struct mbuf *m, **mp;
     int len;
     char *tdata;
     caddr_t tpa;
@@ -504,5 +531,3 @@ osi_NetSend(osi_socket asocket, struct sockaddr_in *addr, struct iovec *dvec,
     return code;
 }
 #endif
-
-#endif /* AFS_FBSD40_ENV */