Fix to make ulogd daemonize properly with drl.
authorKevin Webb <kcwebb@ucsd.edu>
Tue, 26 Jan 2010 21:40:14 +0000 (21:40 +0000)
committerKevin Webb <kcwebb@ucsd.edu>
Tue, 26 Jan 2010 21:40:14 +0000 (21:40 +0000)
drl/raterouter.h
drl/ulogd_DRL.c
ulogd.c

index 5e89e89..06f8069 100644 (file)
@@ -60,7 +60,7 @@ enum failure_behaviors { PANIC = 1, QUORUM = 2 };
  *
  * This is used for FPS only.  See estimate.c
  */
  *
  * This is used for FPS only.  See estimate.c
  */
-#define FLOW_START_THRESHOLD (6000)
+#define FLOW_START_THRESHOLD (10000)
 
 #define CLOSE_ENOUGH (0.90)
 
 
 #define CLOSE_ENOUGH (0.90)
 
index 97f24bc..170ab43 100644 (file)
@@ -1735,32 +1735,6 @@ static void reconfig() {
     pthread_rwlock_unlock(&limiter.limiter_lock);
 }
 
     pthread_rwlock_unlock(&limiter.limiter_lock);
 }
 
-static ulog_output_t drl_op = {
-    .name = "drl",
-    .output = &_output_drl,
-    .signal = NULL, /* This appears to be broken. Using my own handler. */
-    .init = NULL,
-    .fini = NULL,
-};
-
-/* Tests the amount of time it takes to call reconfig(). */
-static void time_reconfig(int iterations) {
-    struct timeval start, end;
-    int i;
-
-    gettimeofday(&start, NULL);
-    for (i = 0; i < iterations; ++i) {
-        reconfig();
-    }
-    gettimeofday(&end, NULL);
-
-    printf("%d reconfigs() took %d seconds and %d microseconds.\n",
-           iterations, end.tv_sec - start.tv_sec, end.tv_usec - start.tv_usec);
-    exit(0);
-
-    // Seems to take about 85ms / iteration
-}
-
 static int stop_enforcement(drl_instance_t *instance) {
     char cmd[300];
     int i;
 static int stop_enforcement(drl_instance_t *instance) {
     char cmd[300];
     int i;
@@ -1839,13 +1813,9 @@ static void *signal_thread_func(void *args) {
                 break;
         }
     }
                 break;
         }
     }
-
 }
 
 }
 
-/* register output plugin with ulogd */
-static void _drl_reg_op(void)
-{
-    ulog_output_t *op = &drl_op;
+static int drl_plugin_init() {
     sigset_t signal_mask;
 
     sigemptyset(&signal_mask);
     sigset_t signal_mask;
 
     sigemptyset(&signal_mask);
@@ -1868,8 +1838,6 @@ static void _drl_reg_op(void)
         exit(EXIT_FAILURE);
     }
 
         exit(EXIT_FAILURE);
     }
 
-    register_output(op);
-
     /* start up the thread that will periodically estimate the
      * local rate and set the local limits
      * see estimate.c
     /* start up the thread that will periodically estimate the
      * local rate and set the local limits
      * see estimate.c
@@ -1886,6 +1854,43 @@ static void _drl_reg_op(void)
         printlog(LOG_CRITICAL, "--Switching enforcement on.--\n");
         pthread_rwlock_unlock(&limiter.limiter_lock);
     }
         printlog(LOG_CRITICAL, "--Switching enforcement on.--\n");
         pthread_rwlock_unlock(&limiter.limiter_lock);
     }
+
+    return 0;
+}
+
+static ulog_output_t drl_op = {
+    .name = "drl",
+    .output = &_output_drl,
+    .signal = NULL, /* This appears to be broken. Using my own handler. */
+    .init = &drl_plugin_init,
+    .fini = NULL,
+};
+
+#if 0
+/* Tests the amount of time it takes to call reconfig(). */
+static void time_reconfig(int iterations) {
+    struct timeval start, end;
+    int i;
+
+    gettimeofday(&start, NULL);
+    for (i = 0; i < iterations; ++i) {
+        reconfig();
+    }
+    gettimeofday(&end, NULL);
+
+    printf("%d reconfigs() took %d seconds and %d microseconds.\n",
+           iterations, end.tv_sec - start.tv_sec, end.tv_usec - start.tv_usec);
+    exit(0);
+
+    // Seems to take about 85ms / iteration
+}
+#endif
+
+/* register output plugin with ulogd */
+static void _drl_reg_op(void)
+{
+    ulog_output_t *op = &drl_op;
+    register_output(op);
 }
 
 void _init(void)
 }
 
 void _init(void)
diff --git a/ulogd.c b/ulogd.c
index 9b998a9..4553d4d 100644 (file)
--- a/ulogd.c
+++ b/ulogd.c
@@ -769,6 +769,17 @@ int main(int argc, char* argv[])
                }
        }
 
                }
        }
 
+       if (daemonize){
+               if (fork()) {
+                       exit(0);
+               }
+               if (logfile != stdout)
+                       fclose(stdout);
+               fclose(stderr);
+               fclose(stdin);
+               setsid();
+       }
+
        logfile_open(logf_ce.u.string);
 
        for (p = ulogd_outputs; p; p = p->next) {
        logfile_open(logf_ce.u.string);
 
        for (p = ulogd_outputs; p; p = p->next) {
@@ -781,16 +792,6 @@ int main(int argc, char* argv[])
        interh_dump();
        keyh_dump();
 #endif
        interh_dump();
        keyh_dump();
 #endif
-       if (daemonize){
-               if (fork()) {
-                       exit(0);
-               }
-               if (logfile != stdout)
-                       fclose(stdout);
-               fclose(stderr);
-               fclose(stdin);
-               setsid();
-       }
 
        /* send SIGINT to the term handler, since they hit CTRL-C */
        signal(SIGINT, &sigterm_handler);
 
        /* send SIGINT to the term handler, since they hit CTRL-C */
        signal(SIGINT, &sigterm_handler);