hs-test: fix TCP with loss test
[vpp.git] / src / vlib / unix / main.c
index 0ebda24..38eef41 100644 (file)
@@ -71,12 +71,10 @@ unix_main_init (vlib_main_t * vm)
   return 0;
 }
 
-/* *INDENT-OFF* */
 VLIB_INIT_FUNCTION (unix_main_init) =
 {
   .runs_before = VLIB_INITS ("unix_input_init"),
 };
-/* *INDENT-ON* */
 
 static int
 unsetup_signal_handlers (int sig)
@@ -145,17 +143,6 @@ unix_signal_handler (int signum, siginfo_t * si, ucontext_t * uc)
       break;
     }
 
-#ifdef CLIB_GCOV
-  /*
-   * Test framework sends SIGTERM, so we need to flush the
-   * code coverage stats here.
-   */
-  {
-    void __gcov_flush (void);
-    __gcov_flush ();
-  }
-#endif
-
   /* Null terminate. */
   vec_add1 (syslog_msg, 0);
 
@@ -273,98 +260,34 @@ startup_config_process (vlib_main_t * vm,
                        vlib_node_runtime_t * rt, vlib_frame_t * f)
 {
   unix_main_t *um = &unix_main;
-  u8 *buf = 0;
-  uword l, n = 1;
+  unformat_input_t in;
 
   vlib_process_suspend (vm, 2.0);
 
   while (um->unix_config_complete == 0)
     vlib_process_suspend (vm, 0.1);
 
-  if (um->startup_config_filename)
+  if (!um->startup_config_filename)
     {
-      unformat_input_t sub_input;
-      int fd;
-      struct stat s;
-      char *fn = (char *) um->startup_config_filename;
-
-      fd = open (fn, O_RDONLY);
-      if (fd < 0)
-       {
-         clib_warning ("failed to open `%s'", fn);
-         return 0;
-       }
+      return 0;
+    }
 
-      if (fstat (fd, &s) < 0)
-       {
-         clib_warning ("failed to stat `%s'", fn);
-       bail:
-         close (fd);
-         return 0;
-       }
+  unformat_init_vector (&in,
+                       format (0, "exec %s", um->startup_config_filename));
 
-      if (!(S_ISREG (s.st_mode) || S_ISLNK (s.st_mode)))
-       {
-         clib_warning ("not a regular file: `%s'", fn);
-         goto bail;
-       }
+  vlib_cli_input (vm, &in, 0, 0);
 
-      while (n > 0)
-       {
-         l = vec_len (buf);
-         vec_resize (buf, 4096);
-         n = read (fd, buf + l, 4096);
-         if (n > 0)
-           {
-             _vec_len (buf) = l + n;
-             if (n < 4096)
-               break;
-           }
-         else
-           break;
-       }
-      if (um->log_fd && vec_len (buf))
-       {
-         u8 *lv = 0;
-         lv = format (lv, "%U: ***** Startup Config *****\n%v",
-                      format_timeval, 0 /* current bat-time */ ,
-                      0 /* current bat-format */ ,
-                      buf);
-         {
-           int rv __attribute__ ((unused)) =
-             write (um->log_fd, lv, vec_len (lv));
-         }
-         vec_reset_length (lv);
-         lv = format (lv, "%U: ***** End Startup Config *****\n",
-                      format_timeval, 0 /* current bat-time */ ,
-                      0 /* current bat-format */ );
-         {
-           int rv __attribute__ ((unused)) =
-             write (um->log_fd, lv, vec_len (lv));
-         }
-         vec_free (lv);
-       }
+  unformat_free (&in);
 
-      if (vec_len (buf))
-       {
-         unformat_init_vector (&sub_input, buf);
-         vlib_cli_input (vm, &sub_input, 0, 0);
-         /* frees buf for us */
-         unformat_free (&sub_input);
-       }
-      close (fd);
-    }
   return 0;
 }
 
-/* *INDENT-OFF* */
 VLIB_REGISTER_NODE (startup_config_node,static) = {
     .function = startup_config_process,
     .type = VLIB_NODE_TYPE_PROCESS,
     .name = "startup-config-process",
     .process_log2_n_stack_bytes = 18,
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 unix_config (vlib_main_t * vm, unformat_input_t * input)
@@ -465,9 +388,8 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
            {
              u8 *lv = 0;
              lv = format (0, "%U: ***** Start: PID %d *****\n",
-                          format_timeval, 0 /* current bat-time */ ,
-                          0 /* current bat-format */ ,
-                          getpid ());
+                          format_timeval, NULL /* current bat-format */,
+                          0 /* current bat-time */, getpid ());
              {
                int rv __attribute__ ((unused)) =
                  write (um->log_fd, lv, vec_len (lv));
@@ -503,6 +425,9 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
   if (error)
     return error;
 
+  if (chdir ((char *) um->runtime_dir) < 0)
+    return clib_error_return_unix (0, "chdir('%s')", um->runtime_dir);
+
   error = setup_signal_handlers (um);
   if (error)
     return error;
@@ -708,10 +633,6 @@ vlib_unix_main (int argc, char *argv[])
     vgm->exec_path = vgm->name = argv[0];
 
   vgm->argv = (u8 **) argv;
-  vm->heap_base = clib_mem_get_heap ();
-  vm->heap_aligned_base =
-    (void *) (((uword) vm->heap_base) & ~(CLIB_CACHE_LINE_BYTES - 1));
-  ASSERT (vm->heap_base);
 
   clib_time_init (&vm->clib_time);