<div dir="ltr">Kaur,<div><br></div><div>I believe parse_opts() should be called before dpdk_init() now see <a href="https://patches.dpdk.org/project/dpdk/patch/20220125032545.7704-1-koncept1@gmail.com/">https://patches.dpdk.org/project/dpdk/patch/20220125032545.7704-1-koncept1@gmail.com/</a></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 16, 2022 at 4:19 AM Kaur, Arshdeep <<a href="mailto:arshdeep.kaur@intel.com">arshdeep.kaur@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
> -----Original Message-----<br>
> From: Stephen Hemminger <<a href="mailto:stephen@networkplumber.org" target="_blank">stephen@networkplumber.org</a>><br>
> Sent: Tuesday, September 13, 2022 12:34 AM<br>
> To: <a href="mailto:dev@dpdk.org" target="_blank">dev@dpdk.org</a><br>
> Cc: Stephen Hemminger <<a href="mailto:stephen@networkplumber.org" target="_blank">stephen@networkplumber.org</a>>; Kaur, Arshdeep<br>
> <<a href="mailto:arshdeep.kaur@intel.com" target="_blank">arshdeep.kaur@intel.com</a>><br>
> Subject: [RFT] dumpcap: add file-prefix option<br>
> <br>
> When using dumpcap in container environment or with multiple DPDK<br>
> processes, it is useful to be able to specify file prefix.<br>
> <br>
> This version only accepts the long format option used by other commands.<br>
> If no prefix is specified then the default is used.<br>
> <br>
> Suggested-by: Arshdeep Kaur <<a href="mailto:arshdeep.kaur@intel.com" target="_blank">arshdeep.kaur@intel.com</a>><br>
> Signed-off-by: Stephen Hemminger <<a href="mailto:stephen@networkplumber.org" target="_blank">stephen@networkplumber.org</a>><br>
> ---<br>
> Did basic command line test, but still needs testing with a prefix being used<br>
> (ie multiple apps).<br>
> <br>
> app/dumpcap/main.c | 24 ++++++++++++++++++------<br>
> 1 file changed, 18 insertions(+), 6 deletions(-)<br>
> <br>
> diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index<br>
> a6041d4ff495..bdeef96d9c0b 100644<br>
> --- a/app/dumpcap/main.c<br>
> +++ b/app/dumpcap/main.c<br>
> @@ -61,6 +61,7 @@ static char *output_name; static const char<br>
> *filter_str; static unsigned int ring_size = 2048; static const char<br>
> *capture_comment;<br>
> +static const char *file_prefix;<br>
> static uint32_t snaplen = RTE_MBUF_DEFAULT_BUF_SIZE; static bool<br>
> dump_bpf; static struct { @@ -122,6 +123,7 @@ static void usage(void)<br>
> " add a capture comment to the output file\n"<br>
> "\n"<br>
> "Miscellaneous:\n"<br>
> + " --file-prefix=<prefix> prefix to use for multi-process\n"<br>
> " -q don't report packet capture counts\n"<br>
> " -v, --version print version information and exit\n"<br>
> " -h, --help display this help and exit\n"<br>
> @@ -310,6 +312,7 @@ static void parse_opts(int argc, char **argv)<br>
> static const struct option long_options[] = {<br>
> { "autostop", required_argument, NULL, 'a' },<br>
> { "capture-comment", required_argument, NULL, 0 },<br>
> + { "file-prefix", required_argument, NULL, 0 },<br>
> { "help", no_argument, NULL, 'h' },<br>
> { "interface", required_argument, NULL, 'i' },<br>
> { "list-interfaces", no_argument, NULL, 'D' },<br>
> @@ -330,11 +333,13 @@ static void parse_opts(int argc, char **argv)<br>
> <br>
> switch (c) {<br>
> case 0:<br>
> - switch (option_index) {<br>
> - case 0:<br>
> + if (!strcmp(long_options[option_index].name,<br>
> + "capture-comment")) {<br>
> capture_comment = optarg;<br>
> - break;<br>
> - default:<br>
> + } else if (!strcmp(long_options[option_index].name,<br>
> + "file-prefix")) {<br>
> + file_prefix = optarg;<br>
> + } else {<br>
> usage();<br>
> exit(1);<br>
> }<br>
<br>
parse_opts() is called after dpdk_init(). So whatever file-prefix we provide, for eal init, it remains NULL.<br>
Please let me know your thoughts about it.<br>
<br>
> @@ -512,12 +517,14 @@ static void dpdk_init(void)<br>
> static const char * const args[] = {<br>
> "dumpcap", "--proc-type", "secondary",<br>
> "--log-level", "notice"<br>
> -<br>
> };<br>
> - const int eal_argc = RTE_DIM(args);<br>
> + int eal_argc = RTE_DIM(args);<br>
> char **eal_argv;<br>
> unsigned int i;<br>
> <br>
> + if (file_prefix != NULL)<br>
> + eal_argc += 2;<br>
> +<br>
> /* DPDK API requires mutable versions of command line arguments.<br>
> */<br>
> eal_argv = calloc(eal_argc + 1, sizeof(char *));<br>
> if (eal_argv == NULL)<br>
> @@ -527,6 +534,11 @@ static void dpdk_init(void)<br>
> for (i = 1; i < RTE_DIM(args); i++)<br>
> eal_argv[i] = strdup(args[i]);<br>
> <br>
> + if (file_prefix != NULL) {<br>
> + eal_argv[i++] = strdup("--file-prefix");<br>
> + eal_argv[i++] = strdup(file_prefix);<br>
> + }<br>
> +<br>
> if (rte_eal_init(eal_argc, eal_argv) < 0)<br>
> rte_exit(EXIT_FAILURE, "EAL init failed: is primary process<br>
> running?\n");<br>
> <br>
> --<br>
> 2.35.1<br>
<br>
</blockquote></div>