summaryrefslogtreecommitdiffstats
path: root/sys-utils/ctrlaltdel.c
diff options
context:
space:
mode:
authorSami Kerola2011-08-31 20:52:01 +0200
committerSami Kerola2011-09-17 14:25:20 +0200
commit028f7ed83f92105b39ee0c8e3ffdb89157c182de (patch)
tree62e929415e812321dedb359a58d3556c7dbf3b99 /sys-utils/ctrlaltdel.c
parentdocs: mention long options in pivot_root.8 (diff)
downloadkernel-qcow2-util-linux-028f7ed83f92105b39ee0c8e3ffdb89157c182de.tar.gz
kernel-qcow2-util-linux-028f7ed83f92105b39ee0c8e3ffdb89157c182de.tar.xz
kernel-qcow2-util-linux-028f7ed83f92105b39ee0c8e3ffdb89157c182de.zip
ctrlaltdel: add version & help options
Including other necessary changes to usage(). Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/ctrlaltdel.c')
-rw-r--r--sys-utils/ctrlaltdel.c39
1 files changed, 35 insertions, 4 deletions
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 <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -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 <hard|soft>\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;
}