xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] xentrace: adjust exit code for --help option
@ 2023-05-26 12:38 Olaf Hering
  2023-07-28 20:53 ` George Dunlap
  0 siblings, 1 reply; 5+ messages in thread
From: Olaf Hering @ 2023-05-26 12:38 UTC (permalink / raw)
  To: xen-devel; +Cc: George Dunlap, Wei Liu, Anthony PERARD

Invoking the --help option of any tool should not return with an error,
if that tool does 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 '?' allows to handle --help.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 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@intel.com>";
 
-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);
         }
     }
 


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] xentrace: adjust exit code for --help option
  2023-05-26 12:38 [PATCH v1] xentrace: adjust exit code for --help option Olaf Hering
@ 2023-07-28 20:53 ` George Dunlap
  0 siblings, 0 replies; 5+ messages in thread
From: George Dunlap @ 2023-07-28 20:53 UTC (permalink / raw)
  To: Olaf Hering; +Cc: xen-devel, George Dunlap, Wei Liu, Anthony PERARD

[-- Attachment #1: Type: text/plain, Size: 616 bytes --]

On Fri, May 26, 2023 at 1:38 PM Olaf Hering <olaf@aepfle.de> wrote:

> Invoking the --help option of any tool should not return with an error,
> if that tool does 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 '?' allows to handle --help.
>
> Signed-off-by: Olaf Hering <olaf@aepfle.de>
>

Reviewed-by: George Dunlap <george.dunlap@cloud.com>

[-- Attachment #2: Type: text/html, Size: 1088 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] xentrace: adjust exit code for --help option
  2023-06-01  8:17 ` Jan Beulich
@ 2023-06-01  8:20   ` Olaf Hering
  0 siblings, 0 replies; 5+ messages in thread
From: Olaf Hering @ 2023-06-01  8:20 UTC (permalink / raw)
  To: Jan Beulich; +Cc: George Dunlap, Wei Liu, Anthony PERARD, xen-devel

[-- Attachment #1: Type: text/plain, Size: 265 bytes --]

Thu, 1 Jun 2023 10:17:17 +0200 Jan Beulich <jbeulich@suse.com>:

> Is this any different from the v1 sent on May 26th?

Yeah, this one still has the bogus commit message.
I forgot that this patch was already sent earlier.

Please ignore this one.


Olaf

[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] xentrace: adjust exit code for --help option
  2023-06-01  8:08 Olaf Hering
@ 2023-06-01  8:17 ` Jan Beulich
  2023-06-01  8:20   ` Olaf Hering
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Beulich @ 2023-06-01  8:17 UTC (permalink / raw)
  To: Olaf Hering; +Cc: George Dunlap, Wei Liu, Anthony PERARD, xen-devel

On 01.06.2023 10:08, Olaf Hering wrote:
> 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@aepfle.de>

Is this any different from the v1 sent on May 26th?

Jan

> --- 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@intel.com>";
>  
> -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);
>          }
>      }
>  
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v1] xentrace: adjust exit code for --help option
@ 2023-06-01  8:08 Olaf Hering
  2023-06-01  8:17 ` Jan Beulich
  0 siblings, 1 reply; 5+ messages in thread
From: Olaf Hering @ 2023-06-01  8:08 UTC (permalink / raw)
  To: xen-devel; +Cc: George Dunlap, Wei Liu, Anthony PERARD

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@aepfle.de>
---
 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@intel.com>";
 
-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);
         }
     }
 


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-28 20:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-26 12:38 [PATCH v1] xentrace: adjust exit code for --help option Olaf Hering
2023-07-28 20:53 ` George Dunlap
2023-06-01  8:08 Olaf Hering
2023-06-01  8:17 ` Jan Beulich
2023-06-01  8:20   ` Olaf Hering

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).