libinput/SOURCES/0001-tools-make-the-tools-exit-with-exit-code-2-on-usage-.patch
2021-09-09 20:23:05 +00:00

173 lines
4.0 KiB
Diff

From 04a2e338707ec96bfdc9ee0dd8dc50b52991bafd Mon Sep 17 00:00:00 2001
From: Peter Hutterer <peter.hutterer@who-t.net>
Date: Thu, 1 Nov 2018 09:39:49 +1000
Subject: [PATCH libinput] tools: make the tools exit with exit code 2 on usage
issues
This makes it easier to test for usage issues
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 36af7d312b5b10790bd19e3066eb1cd4e4e5f6d4)
---
tools/libinput-debug-events.c | 12 ++++++------
tools/libinput-debug-gui.c | 10 +++++-----
tools/libinput-list-devices.c | 2 +-
tools/libinput-tool.c | 4 ++--
tools/shared.c | 2 +-
tools/shared.h | 2 ++
6 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/tools/libinput-debug-events.c b/tools/libinput-debug-events.c
index 87c31690f..0996a9495 100644
--- a/tools/libinput-debug-events.c
+++ b/tools/libinput-debug-events.c
@@ -954,11 +954,11 @@ main(int argc, char **argv)
switch(c) {
case '?':
- exit(1);
+ exit(EXIT_INVALID_USAGE);
break;
case 'h':
usage();
- exit(0);
+ exit(EXIT_SUCCESS);
break;
case OPT_SHOW_KEYCODES:
show_keycodes = true;
@@ -983,7 +983,7 @@ main(int argc, char **argv)
default:
if (tools_parse_option(c, optarg, &options) != 0) {
usage();
- return 1;
+ return EXIT_INVALID_USAGE;
}
break;
}
@@ -992,16 +992,16 @@ main(int argc, char **argv)
if (optind < argc) {
usage();
- return 1;
+ return EXIT_INVALID_USAGE;
}
li = tools_open_backend(backend, seat_or_device, verbose, &grab);
if (!li)
- return 1;
+ return EXIT_FAILURE;
mainloop(li);
libinput_unref(li);
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c
index 06ea0b819..b1c73ac39 100644
--- a/tools/libinput-debug-gui.c
+++ b/tools/libinput-debug-gui.c
@@ -957,7 +957,7 @@ main(int argc, char **argv)
switch(c) {
case '?':
- exit(1);
+ exit(EXIT_INVALID_USAGE);
break;
case 'h':
usage();
@@ -980,7 +980,7 @@ main(int argc, char **argv)
default:
if (tools_parse_option(c, optarg, &options) != 0) {
usage();
- return 1;
+ return EXIT_INVALID_USAGE;
}
break;
}
@@ -989,12 +989,12 @@ main(int argc, char **argv)
if (optind < argc) {
usage();
- return 1;
+ return EXIT_INVALID_USAGE;
}
li = tools_open_backend(backend, seat_or_device, verbose, &w.grab);
if (!li)
- return 1;
+ return EXIT_FAILURE;
libinput_set_user_data(li, &w);
@@ -1008,5 +1008,5 @@ main(int argc, char **argv)
window_cleanup(&w);
libinput_unref(li);
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c
index 5fa178854..4b06452ed 100644
--- a/tools/libinput-list-devices.c
+++ b/tools/libinput-list-devices.c
@@ -388,7 +388,7 @@ main(int argc, char **argv)
return 0;
} else {
usage();
- return 1;
+ return EXIT_INVALID_USAGE;
}
}
diff --git a/tools/libinput-tool.c b/tools/libinput-tool.c
index 30a64c270..7195de049 100644
--- a/tools/libinput-tool.c
+++ b/tools/libinput-tool.c
@@ -98,13 +98,13 @@ main(int argc, char **argv)
return EXIT_SUCCESS;
default:
usage();
- return EXIT_FAILURE;
+ return EXIT_INVALID_USAGE;
}
}
if (optind >= argc) {
usage();
- return EXIT_FAILURE;
+ return EXIT_INVALID_USAGE;
}
argv += optind;
diff --git a/tools/shared.c b/tools/shared.c
index e3bc0287e..812870f68 100644
--- a/tools/shared.c
+++ b/tools/shared.c
@@ -576,7 +576,7 @@ tools_exec_command(const char *prefix, int real_argc, char **real_argv)
"libinput: %s is not a libinput command or not installed. "
"See 'libinput --help'\n",
command);
-
+ return EXIT_INVALID_USAGE;
} else {
fprintf(stderr,
"Failed to execute '%s' (%s)\n",
diff --git a/tools/shared.h b/tools/shared.h
index 7888d265a..4e363e227 100644
--- a/tools/shared.h
+++ b/tools/shared.h
@@ -30,6 +30,8 @@
#include <quirks.h>
#include <libinput.h>
+#define EXIT_INVALID_USAGE 2
+
enum configuration_options {
OPT_TAP_ENABLE = 256,
OPT_TAP_DISABLE,
--
2.19.1