Skip to content

Commit

Permalink
tools: make the tools exit with exit code 2 on usage issues
Browse files Browse the repository at this point in the history
This makes it easier to test for usage issues

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Nov 7, 2018
1 parent bd52bf5 commit 36af7d3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
12 changes: 6 additions & 6 deletions tools/libinput-debug-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,11 +944,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;
Expand All @@ -973,7 +973,7 @@ main(int argc, char **argv)
default:
if (tools_parse_option(c, optarg, &options) != 0) {
usage();
return 1;
return EXIT_INVALID_USAGE;
}
break;
}
Expand All @@ -982,7 +982,7 @@ main(int argc, char **argv)

if (optind < argc) {
usage();
return 1;
return EXIT_INVALID_USAGE;
}

memset(&act, 0, sizeof(act));
Expand All @@ -997,11 +997,11 @@ main(int argc, char **argv)

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;
}
10 changes: 5 additions & 5 deletions tools/libinput-debug-gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ main(int argc, char **argv)

switch(c) {
case '?':
exit(1);
exit(EXIT_INVALID_USAGE);
break;
case 'h':
usage();
Expand All @@ -991,7 +991,7 @@ main(int argc, char **argv)
default:
if (tools_parse_option(c, optarg, &options) != 0) {
usage();
return 1;
return EXIT_INVALID_USAGE;
}
break;
}
Expand All @@ -1000,12 +1000,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);

Expand All @@ -1019,5 +1019,5 @@ main(int argc, char **argv)
window_cleanup(&w);
libinput_unref(li);

return 0;
return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion tools/libinput-list-devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ main(int argc, char **argv)
return 0;
} else {
usage();
return 1;
return EXIT_INVALID_USAGE;
}
}

Expand Down
4 changes: 2 additions & 2 deletions tools/libinput-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions tools/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 36af7d3

Please sign in to comment.