[v3] dumpcap: fix pathname for output file

Message ID 20221020172846.109011-1-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [v3] dumpcap: fix pathname for output file |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/intel-Testing success Testing PASS

Commit Message

Stephen Hemminger Oct. 20, 2022, 5:28 p.m. UTC
  When dumpcap is run with a longer path name such as when
testing, the file prefix would be computed incorrectly.

Also, print out the resulting filename which is what
similar wireshark program does.

Fixes: cbb44143be74 ("app/dumpcap: add new packet capture application")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
v3 - get rid of printf

 app/dumpcap/main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
  

Comments

David Marchand Oct. 21, 2022, 1:07 p.m. UTC | #1
On Thu, Oct 20, 2022 at 7:29 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> When dumpcap is run with a longer path name such as when
> testing, the file prefix would be computed incorrectly.
>
> Also, print out the resulting filename which is what
> similar wireshark program does.
>
> Fixes: cbb44143be74 ("app/dumpcap: add new packet capture application")
Cc: stable@dpdk.org

> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Applied, thanks.
  

Patch

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index e0a3477d912f..32d97df3aafa 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -637,6 +637,7 @@  static dumpcap_out_t create_output(void)
 	else {
 		mode_t mode = group_read ? 0640 : 0600;
 
+		fprintf(stderr, "File: %s\n", output_name);
 		fd = open(output_name, O_WRONLY | O_CREAT, mode);
 		if (fd < 0)
 			rte_exit(EXIT_FAILURE, "Can not open \"%s\": %s\n",
@@ -784,8 +785,13 @@  int main(int argc, char **argv)
 	struct rte_ring *r;
 	struct rte_mempool *mp;
 	dumpcap_out_t out;
+	char *p;
 
-	progname = argv[0];
+	p = strrchr(argv[0], '/');
+	if (p == NULL)
+		progname = argv[0];
+	else
+		progname = p + 1;
 
 	parse_opts(argc, argv);
 	dpdk_init();