summaryrefslogtreecommitdiffstats
path: root/sys-utils
diff options
context:
space:
mode:
authorSami Kerola2015-10-13 12:52:55 +0200
committerSami Kerola2015-10-18 19:03:57 +0200
commit82cac348896156ae081f9e99fafa28f393fa9115 (patch)
tree8613bf039e5b49cda0660c6b2b33f123f671a315 /sys-utils
parentdocs: update ctrlaltdel.8 man page (diff)
downloadkernel-qcow2-util-linux-82cac348896156ae081f9e99fafa28f393fa9115.tar.gz
kernel-qcow2-util-linux-82cac348896156ae081f9e99fafa28f393fa9115.tar.xz
kernel-qcow2-util-linux-82cac348896156ae081f9e99fafa28f393fa9115.zip
ctrlaltdel: display setting when ran without arguments
This is more useful than printing an error. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils')
-rw-r--r--sys-utils/ctrlaltdel.85
-rw-r--r--sys-utils/ctrlaltdel.c70
2 files changed, 59 insertions, 16 deletions
diff --git a/sys-utils/ctrlaltdel.8 b/sys-utils/ctrlaltdel.8
index 4be651372..170597f09 100644
--- a/sys-utils/ctrlaltdel.8
+++ b/sys-utils/ctrlaltdel.8
@@ -27,8 +27,11 @@ program must support this feature. Since there are now several
programs in the Linux community, please consult the documentation for the
version that you are currently using.
.PP
+When command is ran without arguments it will display current function in
+use.
+.PP
.B ctrlaltdel
-is usually used in the
+function is usually set in the
.I /etc/rc.local
file.
.SH OPTIONS
diff --git a/sys-utils/ctrlaltdel.c b/sys-utils/ctrlaltdel.c
index 64de94f79..ffdad6a8a 100644
--- a/sys-utils/ctrlaltdel.c
+++ b/sys-utils/ctrlaltdel.c
@@ -14,6 +14,7 @@
#include "nls.h"
#include "c.h"
#include "closestream.h"
+#include "pathnames.h"
static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
@@ -30,10 +31,59 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-int main(int argc, char **argv)
+static int get_cad(void)
+{
+ FILE *fp;
+ int val;
+
+ if (!(fp = fopen(_PATH_PROC_CTRL_ALT_DEL, "r"))) {
+ warn("%s", _PATH_PROC_CTRL_ALT_DEL);
+ return EXIT_FAILURE;
+ }
+ if (fscanf(fp, "%d", &val) != 1)
+ val = -1;
+ fclose(fp);
+ switch (val) {
+ case 0:
+ fputs("soft\n", stdout);
+ break;
+ case 1:
+ fputs("hard\n", stdout);
+ break;
+ default:
+ printf("%s hard\n", _("implicit"));
+ warnx(_("unexpected value in %s: %d"), _PATH_PROC_CTRL_ALT_DEL, val);
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+}
+
+static int set_cad(const char *arg)
{
- int ch;
unsigned int cmd;
+
+ if (geteuid()) {
+ warnx(_("You must be root to set the Ctrl-Alt-Del behavior"));
+ return EXIT_FAILURE;
+ }
+ if (!strcmp("hard", arg))
+ cmd = LINUX_REBOOT_CMD_CAD_ON;
+ else if (!strcmp("soft", arg))
+ cmd = LINUX_REBOOT_CMD_CAD_OFF;
+ else {
+ warnx(_("unknown argument: %s"), arg);
+ return EXIT_FAILURE;
+ }
+ if (my_reboot(cmd) < 0) {
+ warnx("reboot");
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+}
+
+int main(int argc, char **argv)
+{
+ int ch, ret;
static const struct option longopts[] = {
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
@@ -56,19 +106,9 @@ int main(int argc, char **argv)
usage(stderr);
}
- if (geteuid())
- errx(EXIT_FAILURE,
- _("You must be root to set the Ctrl-Alt-Del behavior"));
-
if (argc < 2)
- errx(EXIT_FAILURE, _("not enough arguments"));
- if (!strcmp("hard", argv[1]))
- cmd = LINUX_REBOOT_CMD_CAD_ON;
- else if (!strcmp("soft", argv[1]))
- cmd = LINUX_REBOOT_CMD_CAD_OFF;
+ ret = get_cad();
else
- errx(EXIT_FAILURE, _("unknown argument: %s"), argv[1]);
- if (my_reboot(cmd) < 0)
- err(EXIT_FAILURE, "reboot");
- return EXIT_SUCCESS;
+ ret = set_cad(argv[1]);
+ return ret;
}