]> andersk Git - moira.git/blobdiff - server/mr_main.c
"swapped" the contact argument in get_host for "network"
[moira.git] / server / mr_main.c
index 0b950667e80b63166f53574f48cec7a28275f558..704a57a7afb73da85acb5dba6d4d2258db26e83e 100644 (file)
@@ -46,8 +46,6 @@ extern char *takedown;
 extern int errno;
 extern FILE *journal;
 
-extern char *malloc();
-extern int free();
 extern char *inet_ntoa();
 extern void mr_com_err();
 extern void do_client();
@@ -59,6 +57,11 @@ void reapchild(), godormant(), gowakeup();
 
 extern time_t now;
 
+#ifdef _DEBUG_MALLOC_INC
+static char *dbg_malloc();
+static int dbg_free();
+#endif
+
 /*
  * Main MOIRA server loop.
  *
@@ -72,8 +75,10 @@ main(argc, argv)
        int argc;
        char **argv;
 {
-       int status;
+       int status, i;
        time_t tardy;
+       char *port;
+       extern char *database;
        struct stat stbuf;
        
        whoami = argv[0];
@@ -82,19 +87,36 @@ main(argc, argv)
         */
        initialize_sms_error_table();
        initialize_krb_error_table();
+       initialize_gdss_error_table();
        set_com_err_hook(mr_com_err);
        setlinebuf(stderr);
        
-       if (argc != 1) {
-               com_err(whoami, 0, "Usage: moirad");
+       database = "moira";
+       port = index(MOIRA_SERVER, ':') + 1;
+
+       for (i = 1; i < argc; i++) {
+           if (!strcmp(argv[i], "-db") && i+1 < argc) {
+               database = argv[i+1];
+               i++;
+           } else if (!strcmp(argv[i], "-p") && i+1 < argc) {
+               port = argv[i+1];
+               i++;
+           } else {
+               com_err(whoami, 0, "Usage: moirad [-db database][-p port]");
                exit(1);
-       }               
+           }
+       }
 
        /* Profiling implies that getting rid of one level of call
         * indirection here wins us maybe 1% on the VAX.
         */
+#ifdef _DEBUG_MALLOC_INC
+       gdb_amv = dbg_malloc;
+       gdb_fmv = dbg_free;
+#else
        gdb_amv = malloc;
-       gdb_fmv = free;
+       gdb_fmv = (int (*)()) free;
+#endif
        
        /*
         * GDB initialization.
@@ -142,7 +164,7 @@ main(argc, argv)
        /*
         * Establish template connection.
         */
-       if ((status = do_listen()) != 0) {
+       if ((status = do_listen(port)) != 0) {
                com_err(whoami, status,
                        " while trying to create listening connection");
                exit(1);
@@ -213,9 +235,11 @@ main(argc, argv)
                                if (errno == EWOULDBLOCK) {
                                        do_reset_listen();
                                } else {
+                                       static int count = 0;
                                        com_err(whoami, errno,
-                                               " error on listen");
-                                       exit(1);
+                                               " error (%d) on listen", count);
+                                       if (count++ > 10)
+                                         exit(1);
                                }
                        } else if ((status = new_connection()) != 0) {
                                com_err(whoami, errno,
@@ -273,11 +297,10 @@ main(argc, argv)
  */
 
 int
-do_listen()
+do_listen(port)
+char *port;
 {
-       char *service = index(MOIRA_SERVER, ':') + 1;
-
-       listencon = create_listening_connection(service);
+       listencon = create_listening_connection(port);
 
        if (listencon == NULL)
                return errno;
@@ -537,3 +560,19 @@ mr_setup_signals()
        exit(1);
     }
 }
+
+#ifdef _DEBUG_MALLOC_INC
+static char *dbg_malloc(size)
+       SIZETYPE        size;
+{
+       return( debug_malloc("somewhere in the gdb code",1,size) );
+}
+
+static int dbg_free(cptr)
+       DATATYPE        *cptr;
+{
+       debug_free((char *)NULL, 0, cptr);
+       return 0;               /* GDB is being stupid */
+}
+#endif
+
This page took 0.039412 seconds and 4 git commands to generate.