Call rx_InitHost once during daemon startup
[openafs.git] / src / bozo / bosserver.c
index 76f866a..df38bd4 100644 (file)
@@ -74,6 +74,7 @@ const char *DoPidFiles = NULL;
 #ifndef AFS_NT40_ENV
 int DoSyslogFacility = LOG_DAEMON;
 #endif
+int DoTransarcLogs = 0;
 static afs_int32 nextRestart;
 static afs_int32 nextDay;
 
@@ -632,7 +633,7 @@ BozoDaemon(void *unused)
            bnode_ApplyInstance(bdrestart, 0);
        }
     }
-    return NULL;
+    AFS_UNREACHED(return(NULL));
 }
 
 #ifdef AFS_AIX32_ENV
@@ -857,9 +858,9 @@ main(int argc, char **argv, char **envp)
     afs_int32 numClasses;
     int DoPeerRPCStats = 0;
     int DoProcessRPCStats = 0;
+    struct stat sb;
 #ifndef AFS_NT40_ENV
     int nofork = 0;
-    struct stat sb;
 #endif
 #ifdef AFS_AIX32_ENV
     struct sigaction nsa;
@@ -995,10 +996,19 @@ main(int argc, char **argv, char **envp)
            DoPidFiles = (argv[code]+10);
        } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
            DoPidFiles = AFSDIR_LOCAL_DIR;
+       } else if (strcmp(argv[code], "-transarc-logs") == 0) {
+           DoTransarcLogs = 1;
        }
        else {
 
            /* hack to support help flag */
+           int ec;
+           if (strcmp(argv[code], "-help") == 0 || strcmp(argv[code], "-h") == 0)
+               ec = 0; /* It is not an error to ask for usage. */
+           else {
+               printf("Unrecognized option: %s\n", argv[code]);
+               ec = 1;
+           }
 
 #ifndef AFS_NT40_ENV
            printf("Usage: bosserver [-noauth] [-log] "
@@ -1010,6 +1020,7 @@ main(int argc, char **argv, char **envp)
                   "[-enable_peer_stats] [-enable_process_stats] "
                   "[-cores=<none|path>] \n"
                   "[-pidfiles[=path]] "
+                  "[-transarc-logs] "
                   "[-nofork] " "[-help]\n");
 #else
            printf("Usage: bosserver [-noauth] [-log] "
@@ -1024,7 +1035,7 @@ main(int argc, char **argv, char **envp)
 #endif
            fflush(stdout);
 
-           exit(0);
+           exit(ec);
        }
     }
     if (auditFileName) {
@@ -1045,18 +1056,18 @@ main(int argc, char **argv, char **envp)
        exit(1);
     }
 
-    if ((!DoSyslog)
-#ifndef AFS_NT40_ENV
-       && ((lstat(AFSDIR_SERVER_BOZLOG_FILEPATH, &sb) == 0) &&
-       !(S_ISFIFO(sb.st_mode)))
-#endif
-       ) {
-       if (asprintf(&oldlog, "%s.old", AFSDIR_SERVER_BOZLOG_FILEPATH) < 0) {
-           printf("bosserver: out of memory\n");
-           exit(1);
+    if (!DoSyslog) {
+       /* Support logging to named pipes by not renaming. */
+       if (DoTransarcLogs
+           && (lstat(AFSDIR_SERVER_BOZLOG_FILEPATH, &sb) == 0)
+           && !(S_ISFIFO(sb.st_mode))) {
+           if (asprintf(&oldlog, "%s.old", AFSDIR_SERVER_BOZLOG_FILEPATH) < 0) {
+               printf("bosserver: out of memory\n");
+               exit(1);
+           }
+           rk_rename(AFSDIR_SERVER_BOZLOG_FILEPATH, oldlog);
+           free(oldlog);
        }
-       rk_rename(AFSDIR_SERVER_BOZLOG_FILEPATH, oldlog);       /* try rename first */
-       free(oldlog);
        bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
        if (!bozo_logFile) {
            printf("bosserver: can't initialize log file (%s).\n",
@@ -1142,11 +1153,7 @@ main(int argc, char **argv, char **envp)
        host = GetRxBindAddress();
     }
     for (i = 0; i < 10; i++) {
-       if (rxBind) {
-           code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
-       } else {
-           code = rx_Init(htons(AFSCONF_NANNYPORT));
-       }
+       code = rx_InitHost(host, htons(AFSCONF_NANNYPORT));
        if (code) {
            bozo_Log("can't initialize rx: code=%d\n", code);
            sleep(3);
@@ -1251,4 +1258,5 @@ bozo_Log(const char *format, ...)
            fclose(bozo_logFile);
        }
     }
+    va_end(ap);
 }