[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1] xentrace: adjust exit code for --help option


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Olaf Hering <olaf@xxxxxxxxx>
  • Date: Thu, 1 Jun 2023 10:08:33 +0200
  • Arc-authentication-results: i=1; strato.com; arc=none; dkim=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1685606917; s=strato-dkim-0002; d=strato.com; h=Message-Id:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=1hod7D64Ri1wR1/q1jhkmlIlhHTQvlzAxtaOmwee5GI=; b=VN88hp29lRstD101Sdc2zvLzOdFi7QbGT1qUTjRy3/PKSEOaBN5V1t8my1FBoEwBFu EdxVbOToUlQMWBhzGIdXHcHY/PM1igWUYHnZnUo1mYo5LlxY+SKIiFK1ZA7FYjE0TWh4 y5iKIk1MJ2z9MzJYKrSnFFGuQG0dL5F345sIywYBJN4FMFZObtbGveiFAThAVutq7ATi XveN5s/Ry+Rm8l/owfmr+iLliq9YvhflIVQdH0m+CfqQnJ0LXhPmgOCfSaGFSyKN5/kC xLKePV+1pux+hxOHoWksCJdfHlh5UyvBm4pUdjm0wRKaOoJn8x+VK94Bv4a9x5ZzZk3W Hbpw==
  • Arc-seal: i=1; a=rsa-sha256; t=1685606917; cv=none; d=strato.com; s=strato-dkim-0002; b=sp8O3BnmaZ3Rvm+SUtXK2EJ6sNfFwqEUcdTDLZ/tXDWjJARWMiBemnNhfM6m0NPoXU +WDeYlRt1EPNXdBAEXiQ+MLxH1RrGpSJosyugdI0v1i2cRZncwwWK7SNo1+hDIvxFgaw nnoD99GYMngrboIzZEPa7a+G0OsZGKzNyXdngkVWLJqqZNjLWmzHWPt6OOlk2Tx1T8tR yInQ0VvMa4fmmQkFyn+RoT9NmAwfyVwafbh0bPpp2O93DPqsihfhvq5y41zbuZw8P9vD CSPNOkgTFbJi9srG7KuUohE5Mlx8fbfDjlteAlo+5gdkteoVYjcN1qGTq8szIf7yrNzZ rg+w==
  • Cc: George Dunlap <george.dunlap@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Delivery-date: Thu, 01 Jun 2023 08:09:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Invoking the --help option of any tool should not return with an error,
if that tool does indeed have a documented and implemented help option.

Adjust the usage() function to exit with either error or success.
Handle the existing entry in the option table to call usage accordingly.

Adjust the getopt value for help. The char '?' is returned for unknown
options. Returning 'h' instead of '?' makes it allows to handle --help.

Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
---
 tools/xentrace/xentrace.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/tools/xentrace/xentrace.c b/tools/xentrace/xentrace.c
index 3548255123..be6226f088 100644
--- a/tools/xentrace/xentrace.c
+++ b/tools/xentrace/xentrace.c
@@ -807,7 +807,7 @@ static void monitor_tbufs(void)
 const char *program_version     = "xentrace v1.2";
 const char *program_bug_address = "<mark.a.williamson@xxxxxxxxx>";
 
-static void usage(void)
+static void usage(int status)
 {
 #define USAGE_STR \
 "Usage: xentrace [OPTION...] [output file]\n" \
@@ -854,7 +854,7 @@ static void usage(void)
     printf(USAGE_STR);
     printf("\nReport bugs to %s\n", program_bug_address);
 
-    exit(EXIT_FAILURE);
+    exit(status);
 }
 
 /* convert the argument string pointed to by arg to a long int representation,
@@ -873,7 +873,7 @@ long sargtol(const char *restrict arg, int base)
     {
         fprintf(stderr, "Invalid option argument: %s\n", arg);
         fprintf(stderr, "Error: %s\n\n", strerror(errno));
-        usage();
+        usage(EXIT_FAILURE);
     }
     else if (endp == arg)
     {
@@ -901,7 +901,7 @@ long sargtol(const char *restrict arg, int base)
 
 invalid:
     fprintf(stderr, "Invalid option argument: %s\n\n", arg);
-    usage();
+    usage(EXIT_FAILURE);
     return 0; /* not actually reached */
 }
 
@@ -917,10 +917,10 @@ static long argtol(const char *restrict arg, int base)
     if (errno != 0) {
         fprintf(stderr, "Invalid option argument: %s\n", arg);
         fprintf(stderr, "Error: %s\n\n", strerror(errno));
-        usage();
+        usage(EXIT_FAILURE);
     } else if (endp == arg || *endp != '\0') {
         fprintf(stderr, "Invalid option argument: %s\n\n", arg);
-        usage();
+        usage(EXIT_FAILURE);
     }
 
     return val;
@@ -1090,7 +1090,7 @@ static void parse_args(int argc, char **argv)
         { "discard-buffers", no_argument,      0, 'D' },
         { "dont-disable-tracing", no_argument, 0, 'x' },
         { "start-disabled", no_argument,       0, 'X' },
-        { "help",           no_argument,       0, '?' },
+        { "help",           no_argument,       0, 'h' },
         { "version",        no_argument,       0, 'V' },
         { 0, 0, 0, 0 }
     };
@@ -1144,8 +1144,12 @@ static void parse_args(int argc, char **argv)
             opts.memory_buffer = sargtol(optarg, 0);
             break;
 
+        case 'h':
+            usage(EXIT_SUCCESS);
+            break;
+
         default:
-            usage();
+            usage(EXIT_FAILURE);
         }
     }
 



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.