Skip to contentSkip to conversation

xentrace changes

PATCH In review Olaf Hering 2 participants 8 messages May 26, 2023

lore
Share & tools
lore
#0 lore raw

cover xentrace changes

Olaf Hering (3):
xentrace: allow xentrace to write to stdout
xentrace: remove return value from monitor_tbufs
xentrace: close output file in the function which opened it

 tools/xentrace/xentrace.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
#1 lore raw

PATCH 1/3 xentrace: allow xentrace to write to stdout

The output file is optional. In case it is missing, xentrace is supposed to write to stdout - unless it is a tty, which is checked prior using it.

---
 tools/xentrace/xentrace.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
tools/xentrace/xentrace.c +3 -5
index 864e30d50c..b81abe8a51 100644
@@ -1152,11 +1152,9 @@ static void parse_args(int argc, char **argv)
         }
     }
 
-    /* get outfile (required last argument) */
-    if (optind != (argc-1))
-        usage();
-
-    opts.outfile = argv[optind];
+    /* get outfile (optional last argument) */
+    if (argc > optind)
+        opts.outfile = argv[optind];
 }
 
 /* *BSD has no O_LARGEFILE */
#3 lore raw

PATCH 2/3 xentrace: remove return value from monitor_tbufs

In reply to Olaf Hering

The function always returns zero.

---
 tools/xentrace/xentrace.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tools/xentrace/xentrace.c +3 -6
index b81abe8a51..a073cab26d 100644
@@ -668,7 +668,7 @@ static void wait_for_event_or_timeout(unsigned long milliseconds)
  * monitor_tbufs - monitor the contents of tbufs and output to a file
  * @logfile:       the FILE * representing the file to log to
  */
-static int monitor_tbufs(void)
+static void monitor_tbufs(void)
 {
     int i;
 
@@ -795,8 +795,6 @@ static int monitor_tbufs(void)
     free(data);
     /* don't need to munmap - cleanup is automatic */
     close(outfd);
-
-    return 0;
 }
 
 
@@ -1164,7 +1162,6 @@ static void parse_args(int argc, char **argv)
 
 int main(int argc, char **argv)
 {
-    int ret;
     struct sigaction act;
 
     opts.outfile = 0;
@@ -1226,9 +1223,9 @@ int main(int argc, char **argv)
     sigaction(SIGINT,  &act, NULL);
     sigaction(SIGALRM, &act, NULL);
 
-    ret = monitor_tbufs();
+    monitor_tbufs();
 
-    return ret;
+    return 0;
 }
 
 /*
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH v1 2/3] xentrace: remove return value from monitor_tbufs

Quoted 2 lines · Olaf Hering

The function always returns zero.

I think a better argument (which I propose to replace the content of the commit message) would be something like this:

---
The program is structured so that fatal errors cause exit() to be called directly, rather than being passed up the stack; returning a value here may mislead people into believing otherwise.
---

With that change:

If that sounds OK to you I'll modify it on check-in.

-George

#6 lore raw

PATCH 3/3 xentrace: close output file in the function which opened it

In reply to Olaf Hering
---
 tools/xentrace/xentrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/xentrace/xentrace.c +1 -1
index a073cab26d..3548255123 100644
@@ -794,7 +794,6 @@ static void monitor_tbufs(void)
     free(meta);
     free(data);
     /* don't need to munmap - cleanup is automatic */
-    close(outfd);
 }
 
 
@@ -1225,6 +1224,7 @@ int main(int argc, char **argv)
 
     monitor_tbufs();
 
+    close(outfd);
     return 0;
 }