Add config option to use dlmalloc instead of mheap
[vpp.git] / src / vat / main.c
index e2c9b70..c34ec94 100644 (file)
@@ -117,7 +117,7 @@ do_one_file (vat_main_t * vam)
       vec_free (this_cmd);
 
       this_cmd =
-       (u8 *) clib_macro_eval (&vam->macro_main, (char *) vam->inbuf,
+       (u8 *) clib_macro_eval (&vam->macro_main, (i8 *) vam->inbuf,
                                1 /* complain */ );
 
       if (vam->exec_mode == 0)
@@ -305,17 +305,10 @@ main (int argc, char **argv)
   u8 *this_input_file;
   u8 interactive = 1;
   u8 json_output = 0;
-  u8 *heap;
-  mheap_t *h;
   int i;
+  f64 timeout;
 
-  clib_mem_init (0, 128 << 20);
-
-  heap = clib_mem_get_per_cpu_heap ();
-  h = mheap_header (heap);
-
-  /* make the main heap thread-safe */
-  h->flags |= MHEAP_FLAG_THREAD_SAFE;
+  clib_mem_init_thread_safe (0, 128 << 20);
 
   clib_macro_init (&vam->macro_main);
   clib_macro_add_builtin (&vam->macro_main, "current_file",
@@ -388,7 +381,7 @@ main (int argc, char **argv)
   if (vam->socket_name && vat_socket_connect (vam))
     fformat (stderr, "WARNING: socket connection failed");
 
-  if (vam->socket_client_main.socket_fd == 0
+  if ((!vam->socket_client_main || vam->socket_client_main->socket_fd == 0)
       && connect_to_vpe ("vpp_api_test") < 0)
     {
       svm_region_exit ();
@@ -432,6 +425,18 @@ main (int argc, char **argv)
       fclose (vam->ifp);
     }
 
+  /*
+   * Particularly when running a script, don't be in a hurry to leave.
+   * A reply message queued to this process will end up constipating
+   * the allocation rings.
+   */
+  timeout = vat_time_now (vam) + 2.0;
+  while (vam->result_ready == 0 && vat_time_now (vam) < timeout)
+    ;
+
+  if (vat_time_now (vam) > timeout)
+    clib_warning ("BUG: message reply spin-wait timeout");
+
   vl_client_disconnect_from_vlib ();
   exit (0);
 }