From 028f7ed83f92105b39ee0c8e3ffdb89157c182de Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Wed, 31 Aug 2011 20:52:01 +0200 Subject: ctrlaltdel: add version & help options Including other necessary changes to usage(). Signed-off-by: Sami Kerola --- sys-utils/ctrlaltdel.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'sys-utils/ctrlaltdel.c') diff --git a/sys-utils/ctrlaltdel.c b/sys-utils/ctrlaltdel.c index d6c83b42f..8805435d4 100644 --- a/sys-utils/ctrlaltdel.c +++ b/sys-utils/ctrlaltdel.c @@ -5,6 +5,7 @@ * - added Native Language Support */ +#include #include #include #include @@ -13,12 +14,42 @@ #include "nls.h" #include "c.h" -int main(int argc, char *argv[]) +static void __attribute__ ((__noreturn__)) usage(FILE * out) { + fprintf(out, USAGE_HEADER); + fprintf(out, _(" %s \n"), program_invocation_short_name); + fprintf(out, USAGE_OPTIONS); + fprintf(out, USAGE_HELP); + fprintf(out, USAGE_VERSION); + fprintf(out, USAGE_BEGIN_TAIL); + fprintf(out, USAGE_MAN_TAIL, "ctrlaltdel(8)"); + exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); +} + +int main(int argc, char **argv) +{ + int ch; + static const struct option longopts[] = { + {"version", no_argument, NULL, 'V'}, + {"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0} + }; + setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) + switch (ch) { + case 'V': + printf(UTIL_LINUX_VERSION); + return EXIT_SUCCESS; + case 'h': + usage(stdout); + default: + usage(stderr); + } + if (geteuid()) errx(EXIT_FAILURE, _("You must be root to set the Ctrl-Alt-Del behaviour")); @@ -29,9 +60,9 @@ int main(int argc, char *argv[]) } else if (argc == 2 && !strcmp("soft", argv[1])) { if (my_reboot(LINUX_REBOOT_CMD_CAD_OFF) < 0) err(EXIT_FAILURE, "reboot"); - } else - errx(EXIT_FAILURE, _("Usage: %s hard|soft"), - program_invocation_short_name); + } else { + usage(stderr); + } return EXIT_SUCCESS; } -- cgit v1.2.3-55-g7522