Always verify that the client is fully reachable before talking
[openafs.git] / src / viced / viced.c
index 06bfa9f..69299df 100644 (file)
 /*                                                                      */
 /* ********************************************************************** */
 
+#include <afsconfig.h>
 #include <afs/param.h>
+
+RCSID("$Header$");
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -252,7 +256,7 @@ static int get_key(arock, akvno, akey)
     code = afsconf_GetKey(confDir, akvno, tkey.key);
     if (code)
        return code;
-    bcopy(tkey.key, akey, sizeof(tkey.key));
+    memcpy(akey, tkey.key, sizeof(tkey.key));
     return 0;
 
 } /*get_key*/
@@ -345,6 +349,11 @@ main(argc, argv)
     }
 #endif
     confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
+    if (!confDir) {
+       fprintf(stderr, "Unable to open config directory %s\n",
+               AFSDIR_SERVER_ETC_DIRPATH);
+       exit(-1);
+    }
 
     NewParms(1);
 
@@ -479,6 +488,7 @@ main(argc, argv)
     rx_SetDestroyConnProc(tservice, (char (*)()) h_FreeConnection);
     rx_SetMinProcs(tservice, 3);
     rx_SetMaxProcs(tservice, lwps);
+    rx_SetCheckReach(tservice, 1);
 
     tservice = rx_NewService(0,  RX_STATS_SERVICE_ID, "rpcstats", sc, 4, RXSTATS_ExecuteRequest);
     if (!tservice) {
@@ -599,10 +609,12 @@ main(argc, argv)
        ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
     }
     else {
-      bcopy(he->h_addr, &FS_HostAddr_NBO, 4);
-      FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
-      ViceLog(0,("FileServer %s has address 0x%x (0x%x in host byte order)\n",
-                FS_HostName, FS_HostAddr_NBO, FS_HostAddr_HBO));
+       char hoststr[16];
+       memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
+       afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
+       FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
+       ViceLog(0,("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
+                  FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
     }
 
     /* Install handler to catch the shutdown signal */
@@ -646,15 +658,17 @@ static FiveMinuteCheckLWP()
        ViceLog(2, ("Set disk usage statistics\n"));
        VSetDiskUsage();
        if (FS_registered == 1) Do_VLRegisterRPC();
-#ifndef AFS_QUIETFS_ENV
        if(printBanner && (++msg&1)) { /* Every 10 minutes */
            time_t now = FT_ApproxTime();
            if (console != NULL) {
+#ifndef AFS_QUIETFS_ENV
                fprintf(console,"File server is running at %s\r",
                        afs_ctime(&now, tbuffer, sizeof(tbuffer)));
+#endif /* AFS_QUIETFS_ENV */
+               ViceLog(2, ("File server is running at %s\n",
+                       afs_ctime(&now, tbuffer, sizeof(tbuffer))));
            }
        }
-#endif /* AFS_QUIETFS_ENV */
     }
 } /*FiveMinuteCheckLWP*/
 
@@ -734,9 +748,9 @@ static void ClearXStatValues()
     /*
      * Zero all xstat-related structures.
      */
-    bzero((char *)(&afs_perfstats), sizeof(struct afs_PerfStats));
+    memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
 #if FS_STATS_DETAILED
-    bzero((char *)(&afs_FullPerfStats), sizeof(struct fs_stats_FullPerfStats));
+    memset((char *)(&afs_FullPerfStats), 0, sizeof(struct fs_stats_FullPerfStats));
 
     /*
      * That's not enough.  We have to set reasonable minima for
@@ -857,17 +871,24 @@ int dopanic;
        rx_PrintStats(debugFile);
        fflush(debugFile);
     }
-#ifndef AFS_QUIETFS_ENV
     if (console != NULL) {
        now = time(0);
-       if (dopanic)
+       if (dopanic) {
+#ifndef AFS_QUIETFS_ENV
            fprintf(console, "File server has terminated abnormally at %s\r",
                    afs_ctime(&now, tbuffer, sizeof(tbuffer)));
-       else 
+#endif
+           ViceLog(0, ("File server has terminated abnormally at %s\n",
+               afs_ctime(&now, tbuffer, sizeof(tbuffer))));
+       } else {
+#ifndef AFS_QUIETFS_ENV
            fprintf(console, "File server has terminated normally at %s\r",
                    afs_ctime(&now, tbuffer, sizeof(tbuffer)));
-    }
 #endif
+           ViceLog(0, ("File server has terminated normally at %s\n",
+               afs_ctime(&now, tbuffer, sizeof(tbuffer))));
+       }
+    }
 
     exit(0);
 
@@ -1576,7 +1597,7 @@ InitVL() {
                                 AFSDIR_SERVER_NETINFO_FILEPATH,
                                 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
       if (code < 0) {
-       ViceLog(0,("Can' register any valid addresses:%s\n",reason));
+       ViceLog(0,("Can't register any valid addresses: %s\n",reason));
        exit(1);
       }
       FS_HostAddr_cnt = (afs_uint32) code;