0001-rtcwake-use-poweroff-if-shutdown-is-not-found.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. From e1686b25acdedb34cc357f08f0dd3ca01c559dfd Mon Sep 17 00:00:00 2001
  2. From: Justin Chen <justinpopo6@gmail.com>
  3. Date: Thu, 1 Nov 2018 11:10:38 -0700
  4. Subject: [PATCH] rtcwake: use poweroff if shutdown is not found
  5. Some systems do not have the shutdown command. Use poweroff as an
  6. alternative.
  7. Signed-off-by: Justin Chen <justinpopo6@gmail.com>
  8. ---
  9. include/pathnames.h | 1 +
  10. sys-utils/rtcwake.c | 39 +++++++++++++++++++++++++++------------
  11. 2 files changed, 28 insertions(+), 12 deletions(-)
  12. diff --git a/include/pathnames.h b/include/pathnames.h
  13. index 3d5052e6f..ed8ea330d 100644
  14. --- a/include/pathnames.h
  15. +++ b/include/pathnames.h
  16. @@ -53,6 +53,7 @@
  17. # define _PATH_LOGIN "/bin/login"
  18. #endif
  19. #define _PATH_SHUTDOWN "/sbin/shutdown"
  20. +#define _PATH_POWEROFF "/sbin/poweroff"
  21. #define _PATH_TERMCOLORS_DIRNAME "terminal-colors.d"
  22. #define _PATH_TERMCOLORS_DIR "/etc/" _PATH_TERMCOLORS_DIRNAME
  23. diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
  24. index b63c64627..029f00f9b 100644
  25. --- a/sys-utils/rtcwake.c
  26. +++ b/sys-utils/rtcwake.c
  27. @@ -28,6 +28,7 @@
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <sys/ioctl.h>
  31. +#include <sys/stat.h>
  32. #include <sys/time.h>
  33. #include <sys/types.h>
  34. #include <termios.h>
  35. @@ -582,18 +583,32 @@ int main(int argc, char **argv)
  36. char *arg[5];
  37. int i = 0;
  38. - if (ctl.verbose)
  39. - printf(_("suspend mode: off; executing %s\n"),
  40. - _PATH_SHUTDOWN);
  41. - arg[i++] = _PATH_SHUTDOWN;
  42. - arg[i++] = "-h";
  43. - arg[i++] = "-P";
  44. - arg[i++] = "now";
  45. - arg[i] = NULL;
  46. - if (!ctl.dryrun) {
  47. - execv(arg[0], arg);
  48. - warn(_("failed to execute %s"), _PATH_SHUTDOWN);
  49. - rc = EXIT_FAILURE;
  50. + if (!access(_PATH_SHUTDOWN, X_OK)) {
  51. + arg[i++] = _PATH_SHUTDOWN;
  52. + arg[i++] = "-h";
  53. + arg[i++] = "-P";
  54. + arg[i++] = "now";
  55. + arg[i] = NULL;
  56. + } else if (!access(_PATH_POWEROFF, X_OK)) {
  57. + arg[i++] = _PATH_POWEROFF;
  58. + arg[i] = NULL;
  59. + } else {
  60. + arg[i] = NULL;
  61. + }
  62. +
  63. + if (arg[0]) {
  64. + if (ctl.verbose)
  65. + printf(_("suspend mode: off; executing %s\n"),
  66. + arg[0]);
  67. + if (!ctl.dryrun) {
  68. + execv(arg[0], arg);
  69. + warn(_("failed to execute %s"), arg[0]);
  70. + rc = EX_EXEC_ENOENT;
  71. + }
  72. + } else {
  73. + /* Failed to find shutdown command */
  74. + warn(_("failed to find shutdown command"));
  75. + rc = EX_EXEC_ENOENT;
  76. }
  77. break;
  78. }
  79. --
  80. 2.17.1