X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvat%2Fmain.c;h=aa990a31d93dd9d7c677d2df6169e7e11219576a;hb=0164a06d8145f416118183bd496124bfbdfcd3f2;hp=e01d15ec0269379fbe3ce718eeaeda6d0c91016e;hpb=7cd468a3d7dee7d6c92f69a0bb7061ae208ec727;p=vpp.git diff --git a/src/vat/main.c b/src/vat/main.c index e01d15ec026..aa990a31d93 100644 --- a/src/vat/main.c +++ b/src/vat/main.c @@ -19,7 +19,6 @@ vat_main_t vat_main; #include -vpe_api_main_t vpe_api_main; void vat_suspend (vlib_main_t * vm, f64 interval) @@ -191,6 +190,17 @@ do_one_file (vat_main_t * vam) vam->regenerate_interface_table = 0; api_sw_interface_dump (vam); } + + /* Hack to pick up new client index after memfd_segment_create pivot */ + if (vam->client_index_invalid) + { + vat_main_t *vam = &vat_main; + api_main_t *am = &api_main; + + vam->vl_input_queue = am->shmem_hdr->vl_input_queue; + vam->my_client_index = am->my_client_index; + vam->client_index_invalid = 0; + } } } @@ -298,6 +308,7 @@ main (int argc, char **argv) u8 *heap; mheap_t *h; int i; + f64 timeout; clib_mem_init (0, 128 << 20); @@ -314,6 +325,8 @@ main (int argc, char **argv) eval_current_line); init_error_string_table (vam); + vec_validate (vam->cmd_reply, 0); + vec_reset_length (vam->cmd_reply); unformat_init_command_line (a, argv); @@ -327,6 +340,12 @@ main (int argc, char **argv) interactive = 0; else if (unformat (a, "json")) json_output = 1; + else if (unformat (a, "socket-name %s", &vam->socket_name)) + ; + else if (unformat (a, "default-socket")) + { + vam->socket_name = format (0, "%s%c", API_SOCKET_FILE, 0); + } else if (unformat (a, "plugin_path %s", (u8 *) & vat_plugin_path)) vec_add1 (vat_plugin_path, 0); else if (unformat (a, "plugin_name_filter %s", @@ -338,8 +357,12 @@ main (int argc, char **argv) } else { - fformat (stderr, - "%s: usage [in ... in ] [out ] [script] [json]\n"); + fformat + (stderr, + "%s: usage [in ... in ] [out ] [script] [json]\n" + "[plugin_path ][default-socket][socket-name ]\n" + "[plugin_name_filter ][chroot prefix ]\n", + argv[0]); exit (1); } } @@ -363,7 +386,11 @@ main (int argc, char **argv) setup_signal_handlers (); - if (connect_to_vpe ("vpp_api_test") < 0) + if (vam->socket_name && vat_socket_connect (vam)) + fformat (stderr, "WARNING: socket connection failed"); + + if (vam->socket_client_main.socket_fd == 0 + && connect_to_vpe ("vpp_api_test") < 0) { svm_region_exit (); fformat (stderr, "Couldn't connect to vpe, exiting...\n"); @@ -373,9 +400,7 @@ main (int argc, char **argv) vam->json_output = json_output; if (!json_output) - { - api_sw_interface_dump (vam); - } + api_sw_interface_dump (vam); vec_validate (vam->inbuf, 4096); @@ -408,6 +433,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); }