Skip to contentSkip to conversation

dumpcap: fix pathname for output file

PATCH Superseded Stephen Hemminger 2 participants 4 messages Oct 19, 2022 – Oct 21, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dumpcap: fix pathname for output file

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")
---
 app/dumpcap/main.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
app/dumpcap/main.c +8 -1
index e0a3477d912f..9f716b1fbe43 100644
@@ -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,14 @@ 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;
+	printf("progname = '%s'\n", progname);
 
 	parse_opts(argc, argv);
 	dpdk_init();
Signature · 1 line
2.35.1
#1 lore raw

PATCH v2 1/1 dumpcap: fix pathname for output file

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")

---
v2 - get rid of debug printf

 app/dumpcap/main.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
app/dumpcap/main.c +8 -1
index e0a3477d912f..9f716b1fbe43 100644
@@ -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,14 @@ 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;
+	printf("progname = '%s'\n", progname);
 
 	parse_opts(argc, argv);
 	dpdk_init();
Signature · 1 line
2.35.1
#2 lore raw

PATCH v3 1/1 dumpcap: fix pathname for output file

In reply to Stephen Hemminger

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")

---
v3 - get rid of printf

 app/dumpcap/main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
app/dumpcap/main.c +7 -1
index e0a3477d912f..32d97df3aafa 100644
@@ -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();
Signature · 1 line
2.35.1
#3 lore raw
Quoted 8 lines · Stephen Hemminger

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")
Quoted 1 line

Applied, thanks.

Signature · 1 line
David Marchand