summaryrefslogtreecommitdiffstats
path: root/sys-utils/rtcwake.c
diff options
context:
space:
mode:
authorJustin Chen2018-11-01 19:10:38 +0100
committerKarel Zak2018-11-06 12:34:02 +0100
commite1686b25acdedb34cc357f08f0dd3ca01c559dfd (patch)
tree456d3bebe5c4a42f7624b4f96b2090136bd785b3 /sys-utils/rtcwake.c
parentbuild-sys: release++ (v2.33) (diff)
downloadkernel-qcow2-util-linux-e1686b25acdedb34cc357f08f0dd3ca01c559dfd.tar.gz
kernel-qcow2-util-linux-e1686b25acdedb34cc357f08f0dd3ca01c559dfd.tar.xz
kernel-qcow2-util-linux-e1686b25acdedb34cc357f08f0dd3ca01c559dfd.zip
rtcwake: use poweroff if shutdown is not found
Some systems do not have the shutdown command. Use poweroff as an alternative. Signed-off-by: Justin Chen <justinpopo6@gmail.com>
Diffstat (limited to 'sys-utils/rtcwake.c')
-rw-r--r--sys-utils/rtcwake.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index b63c64627..029f00f9b 100644
--- a/sys-utils/rtcwake.c
+++ b/sys-utils/rtcwake.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <termios.h>
@@ -582,18 +583,32 @@ int main(int argc, char **argv)
char *arg[5];
int i = 0;
- if (ctl.verbose)
- printf(_("suspend mode: off; executing %s\n"),
- _PATH_SHUTDOWN);
- arg[i++] = _PATH_SHUTDOWN;
- arg[i++] = "-h";
- arg[i++] = "-P";
- arg[i++] = "now";
- arg[i] = NULL;
- if (!ctl.dryrun) {
- execv(arg[0], arg);
- warn(_("failed to execute %s"), _PATH_SHUTDOWN);
- rc = EXIT_FAILURE;
+ if (!access(_PATH_SHUTDOWN, X_OK)) {
+ arg[i++] = _PATH_SHUTDOWN;
+ arg[i++] = "-h";
+ arg[i++] = "-P";
+ arg[i++] = "now";
+ arg[i] = NULL;
+ } else if (!access(_PATH_POWEROFF, X_OK)) {
+ arg[i++] = _PATH_POWEROFF;
+ arg[i] = NULL;
+ } else {
+ arg[i] = NULL;
+ }
+
+ if (arg[0]) {
+ if (ctl.verbose)
+ printf(_("suspend mode: off; executing %s\n"),
+ arg[0]);
+ if (!ctl.dryrun) {
+ execv(arg[0], arg);
+ warn(_("failed to execute %s"), arg[0]);
+ rc = EX_EXEC_ENOENT;
+ }
+ } else {
+ /* Failed to find shutdown command */
+ warn(_("failed to find shutdown command"));
+ rc = EX_EXEC_ENOENT;
}
break;
}