X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvat%2Fmain.c;h=a5421140fb33dd30a14da9ed3ce97088b68697fd;hb=fa0ac2c56;hp=e2c9b70889a0fecef81105045862172bfbaf0abb;hpb=59b2565cd91a67ced650739f36129650830211ac;p=vpp.git diff --git a/src/vat/main.c b/src/vat/main.c index e2c9b70889a..a5421140fb3 100644 --- a/src/vat/main.c +++ b/src/vat/main.c @@ -15,6 +15,7 @@ #include "vat.h" #include "plugin.h" #include +#include vat_main_t vat_main; @@ -26,17 +27,6 @@ vat_suspend (vlib_main_t * vm, f64 interval) /* do nothing in the standalone version, just return */ } -void -fformat_append_cr (FILE * ofp, const char *fmt, ...) -{ - va_list va; - - va_start (va, fmt); - (void) va_fformat (ofp, (char *) fmt, &va); - va_end (va); - fformat (ofp, "\n"); -} - int connect_to_vpe (char *name) { @@ -117,7 +107,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) @@ -264,7 +254,7 @@ setup_signal_handlers (void) for (i = 1; i < 32; i++) { - memset (&sa, 0, sizeof (sa)); + clib_memset (&sa, 0, sizeof (sa)); sa.sa_sigaction = (void *) signal_handler; sa.sa_flags = SA_SIGINFO; @@ -294,6 +284,37 @@ setup_signal_handlers (void) } } +static void +vat_find_plugin_path () +{ + extern char *vat_plugin_path; + char *p, path[PATH_MAX]; + int rv; + u8 *s; + + /* find executable path */ + if ((rv = readlink ("/proc/self/exe", path, PATH_MAX - 1)) == -1) + return; + + /* readlink doesn't provide null termination */ + path[rv] = 0; + + /* strip filename */ + if ((p = strrchr (path, '/')) == 0) + return; + *p = 0; + + /* strip bin/ */ + if ((p = strrchr (path, '/')) == 0) + return; + *p = 0; + + s = format (0, "%s/lib/" CLIB_TARGET_TRIPLET "/vpp_api_test_plugins:" + "%s/lib/vpp_api_test_plugins", path, path); + vec_add1 (s, 0); + vat_plugin_path = (char *) s; +} + int main (int argc, char **argv) { @@ -305,17 +326,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", @@ -327,6 +341,8 @@ main (int argc, char **argv) vec_validate (vam->cmd_reply, 0); vec_reset_length (vam->cmd_reply); + vat_find_plugin_path (); + unformat_init_command_line (a, argv); while (unformat_check_input (a) != UNFORMAT_END_OF_INPUT) @@ -388,7 +404,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 +448,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); }