* [PATCH] rtcwake: use poweroff if shutdown is not found
@ 2018-11-01 18:10 justinpopo6
2018-11-02 8:32 ` Karel Zak
2018-11-06 11:34 ` Karel Zak
0 siblings, 2 replies; 7+ messages in thread
From: justinpopo6 @ 2018-11-01 18:10 UTC (permalink / raw)
To: util-linux; +Cc: f.fainelli, Justin Chen
From: Justin Chen <justinpopo6@gmail.com>
Some systems do not have the shutdown command. Use poweroff as an
alternative.
Signed-off-by: Justin Chen <justinpopo6@gmail.com>
---
include/pathnames.h | 1 +
sys-utils/rtcwake.c | 39 +++++++++++++++++++++++++++------------
2 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/include/pathnames.h b/include/pathnames.h
index 3d5052e..ed8ea33 100644
--- a/include/pathnames.h
+++ b/include/pathnames.h
@@ -53,6 +53,7 @@
# define _PATH_LOGIN "/bin/login"
#endif
#define _PATH_SHUTDOWN "/sbin/shutdown"
+#define _PATH_POWEROFF "/sbin/poweroff"
#define _PATH_TERMCOLORS_DIRNAME "terminal-colors.d"
#define _PATH_TERMCOLORS_DIR "/etc/" _PATH_TERMCOLORS_DIRNAME
diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index b63c646..029f00f 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;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] rtcwake: use poweroff if shutdown is not found
2018-11-01 18:10 [PATCH] rtcwake: use poweroff if shutdown is not found justinpopo6
@ 2018-11-02 8:32 ` Karel Zak
2018-11-06 11:34 ` Karel Zak
1 sibling, 0 replies; 7+ messages in thread
From: Karel Zak @ 2018-11-02 8:32 UTC (permalink / raw)
To: justinpopo6; +Cc: util-linux, f.fainelli
On Thu, Nov 01, 2018 at 11:10:38AM -0700, justinpopo6@gmail.com wrote:
> include/pathnames.h | 1 +
> sys-utils/rtcwake.c | 39 +++++++++++++++++++++++++++------------
> 2 files changed, 28 insertions(+), 12 deletions(-)
Seems good. I'll merge it after v2.33 release (Mon/Thu next week).
Thanks!
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] rtcwake: use poweroff if shutdown is not found
2018-11-01 18:10 [PATCH] rtcwake: use poweroff if shutdown is not found justinpopo6
2018-11-02 8:32 ` Karel Zak
@ 2018-11-06 11:34 ` Karel Zak
1 sibling, 0 replies; 7+ messages in thread
From: Karel Zak @ 2018-11-06 11:34 UTC (permalink / raw)
To: justinpopo6; +Cc: util-linux, f.fainelli
On Thu, Nov 01, 2018 at 11:10:38AM -0700, justinpopo6@gmail.com wrote:
> include/pathnames.h | 1 +
> sys-utils/rtcwake.c | 39 +++++++++++++++++++++++++++------------
> 2 files changed, 28 insertions(+), 12 deletions(-)
Applied, thanks!
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] rtcwake: use poweroff if shutdown is not found
2018-11-01 10:09 ` Karel Zak
@ 2018-11-01 18:11 ` Justin Chen
0 siblings, 0 replies; 7+ messages in thread
From: Justin Chen @ 2018-11-01 18:11 UTC (permalink / raw)
To: kzak; +Cc: util-linux, Florian Fainelli
v2 sent! Thanks for the review
On Thu, Nov 1, 2018 at 3:09 AM Karel Zak <kzak@redhat.com> wrote:
>
> On Wed, Oct 31, 2018 at 12:25:48PM -0700, justinpopo6@gmail.com wrote:
> > From: Justin Chen <justinpopo6@gmail.com>
> >
> > Some systems do not have the shutdown command. Use poweroff as an
> > alternative.
> >
> > Signed-off-by: Justin Chen <justinpopo6@gmail.com>
> > ---
> > include/pathnames.h | 1 +
> > sys-utils/rtcwake.c | 38 +++++++++++++++++++++++++++-----------
> > 2 files changed, 28 insertions(+), 11 deletions(-)
> >
> > diff --git a/include/pathnames.h b/include/pathnames.h
> > index 3d5052e..ed8ea33 100644
> > --- a/include/pathnames.h
> > +++ b/include/pathnames.h
> > @@ -53,6 +53,7 @@
> > # define _PATH_LOGIN "/bin/login"
> > #endif
> > #define _PATH_SHUTDOWN "/sbin/shutdown"
> > +#define _PATH_POWEROFF "/sbin/poweroff"
> >
> > #define _PATH_TERMCOLORS_DIRNAME "terminal-colors.d"
> > #define _PATH_TERMCOLORS_DIR "/etc/" _PATH_TERMCOLORS_DIRNAME
> > diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
> > index b63c646..b79adbe 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>
> > @@ -579,20 +580,35 @@ int main(int argc, char **argv)
> > break;
> > case OFF_MODE:
> > {
> > + struct stat buf;
> > 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);
> > + if (!stat(_PATH_SHUTDOWN, &buf)) {
> > + arg[i++] = _PATH_SHUTDOWN;
> > + arg[i++] = "-h";
> > + arg[i++] = "-P";
> > + arg[i++] = "now";
> > + arg[i] = NULL;
> > + } else if (!stat(_PATH_POWEROFF, &buf)) {
> > + 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 = EXIT_FAILURE;
> > + }
> > + } else {
> > + /* Failed to find shutdown command */
> > + warn(_("failed to find shutdown command"));
> > rc = EXIT_FAILURE;
>
> maybe we can also change exit code to:
>
> rc = EX_EXEC_ENOENT
>
> to be compatible with another utils.
>
> Karel
>
> > }
> > break;
> > --
> > 2.7.4
> >
>
> --
> Karel Zak <kzak@redhat.com>
> http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] rtcwake: use poweroff if shutdown is not found
2018-10-31 19:25 justinpopo6
2018-11-01 10:06 ` Karel Zak
@ 2018-11-01 10:09 ` Karel Zak
2018-11-01 18:11 ` Justin Chen
1 sibling, 1 reply; 7+ messages in thread
From: Karel Zak @ 2018-11-01 10:09 UTC (permalink / raw)
To: justinpopo6; +Cc: util-linux, f.fainelli
On Wed, Oct 31, 2018 at 12:25:48PM -0700, justinpopo6@gmail.com wrote:
> From: Justin Chen <justinpopo6@gmail.com>
>
> Some systems do not have the shutdown command. Use poweroff as an
> alternative.
>
> Signed-off-by: Justin Chen <justinpopo6@gmail.com>
> ---
> include/pathnames.h | 1 +
> sys-utils/rtcwake.c | 38 +++++++++++++++++++++++++++-----------
> 2 files changed, 28 insertions(+), 11 deletions(-)
>
> diff --git a/include/pathnames.h b/include/pathnames.h
> index 3d5052e..ed8ea33 100644
> --- a/include/pathnames.h
> +++ b/include/pathnames.h
> @@ -53,6 +53,7 @@
> # define _PATH_LOGIN "/bin/login"
> #endif
> #define _PATH_SHUTDOWN "/sbin/shutdown"
> +#define _PATH_POWEROFF "/sbin/poweroff"
>
> #define _PATH_TERMCOLORS_DIRNAME "terminal-colors.d"
> #define _PATH_TERMCOLORS_DIR "/etc/" _PATH_TERMCOLORS_DIRNAME
> diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
> index b63c646..b79adbe 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>
> @@ -579,20 +580,35 @@ int main(int argc, char **argv)
> break;
> case OFF_MODE:
> {
> + struct stat buf;
> 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);
> + if (!stat(_PATH_SHUTDOWN, &buf)) {
> + arg[i++] = _PATH_SHUTDOWN;
> + arg[i++] = "-h";
> + arg[i++] = "-P";
> + arg[i++] = "now";
> + arg[i] = NULL;
> + } else if (!stat(_PATH_POWEROFF, &buf)) {
> + 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 = EXIT_FAILURE;
> + }
> + } else {
> + /* Failed to find shutdown command */
> + warn(_("failed to find shutdown command"));
> rc = EXIT_FAILURE;
maybe we can also change exit code to:
rc = EX_EXEC_ENOENT
to be compatible with another utils.
Karel
> }
> break;
> --
> 2.7.4
>
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] rtcwake: use poweroff if shutdown is not found
2018-10-31 19:25 justinpopo6
@ 2018-11-01 10:06 ` Karel Zak
2018-11-01 10:09 ` Karel Zak
1 sibling, 0 replies; 7+ messages in thread
From: Karel Zak @ 2018-11-01 10:06 UTC (permalink / raw)
To: justinpopo6; +Cc: util-linux, f.fainelli
On Wed, Oct 31, 2018 at 12:25:48PM -0700, justinpopo6@gmail.com wrote:
> From: Justin Chen <justinpopo6@gmail.com>
>
> Some systems do not have the shutdown command. Use poweroff as an
> alternative.
>
> Signed-off-by: Justin Chen <justinpopo6@gmail.com>
> ---
> include/pathnames.h | 1 +
> sys-utils/rtcwake.c | 38 +++++++++++++++++++++++++++-----------
> 2 files changed, 28 insertions(+), 11 deletions(-)
>
> diff --git a/include/pathnames.h b/include/pathnames.h
> index 3d5052e..ed8ea33 100644
> --- a/include/pathnames.h
> +++ b/include/pathnames.h
> @@ -53,6 +53,7 @@
> # define _PATH_LOGIN "/bin/login"
> #endif
> #define _PATH_SHUTDOWN "/sbin/shutdown"
> +#define _PATH_POWEROFF "/sbin/poweroff"
>
> #define _PATH_TERMCOLORS_DIRNAME "terminal-colors.d"
> #define _PATH_TERMCOLORS_DIR "/etc/" _PATH_TERMCOLORS_DIRNAME
> diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
> index b63c646..b79adbe 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>
> @@ -579,20 +580,35 @@ int main(int argc, char **argv)
> break;
> case OFF_MODE:
> {
> + struct stat buf;
> 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);
> + if (!stat(_PATH_SHUTDOWN, &buf)) {
what about if (access(_PATH_SHUTDOWN, X_OK) == 0) to avoid copy
unnecessary struct stat from kernel to userspace? ;-)
Karel
> + arg[i++] = _PATH_SHUTDOWN;
> + arg[i++] = "-h";
> + arg[i++] = "-P";
> + arg[i++] = "now";
> + arg[i] = NULL;
> + } else if (!stat(_PATH_POWEROFF, &buf)) {
> + 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 = EXIT_FAILURE;
> + }
> + } else {
> + /* Failed to find shutdown command */
> + warn(_("failed to find shutdown command"));
> rc = EXIT_FAILURE;
> }
> break;
> --
> 2.7.4
>
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] rtcwake: use poweroff if shutdown is not found
@ 2018-10-31 19:25 justinpopo6
2018-11-01 10:06 ` Karel Zak
2018-11-01 10:09 ` Karel Zak
0 siblings, 2 replies; 7+ messages in thread
From: justinpopo6 @ 2018-10-31 19:25 UTC (permalink / raw)
To: util-linux; +Cc: f.fainelli, Justin Chen
From: Justin Chen <justinpopo6@gmail.com>
Some systems do not have the shutdown command. Use poweroff as an
alternative.
Signed-off-by: Justin Chen <justinpopo6@gmail.com>
---
include/pathnames.h | 1 +
sys-utils/rtcwake.c | 38 +++++++++++++++++++++++++++-----------
2 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/include/pathnames.h b/include/pathnames.h
index 3d5052e..ed8ea33 100644
--- a/include/pathnames.h
+++ b/include/pathnames.h
@@ -53,6 +53,7 @@
# define _PATH_LOGIN "/bin/login"
#endif
#define _PATH_SHUTDOWN "/sbin/shutdown"
+#define _PATH_POWEROFF "/sbin/poweroff"
#define _PATH_TERMCOLORS_DIRNAME "terminal-colors.d"
#define _PATH_TERMCOLORS_DIR "/etc/" _PATH_TERMCOLORS_DIRNAME
diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index b63c646..b79adbe 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>
@@ -579,20 +580,35 @@ int main(int argc, char **argv)
break;
case OFF_MODE:
{
+ struct stat buf;
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);
+ if (!stat(_PATH_SHUTDOWN, &buf)) {
+ arg[i++] = _PATH_SHUTDOWN;
+ arg[i++] = "-h";
+ arg[i++] = "-P";
+ arg[i++] = "now";
+ arg[i] = NULL;
+ } else if (!stat(_PATH_POWEROFF, &buf)) {
+ 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 = EXIT_FAILURE;
+ }
+ } else {
+ /* Failed to find shutdown command */
+ warn(_("failed to find shutdown command"));
rc = EXIT_FAILURE;
}
break;
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-11-06 11:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-01 18:10 [PATCH] rtcwake: use poweroff if shutdown is not found justinpopo6
2018-11-02 8:32 ` Karel Zak
2018-11-06 11:34 ` Karel Zak
-- strict thread matches above, loose matches on Subject: below --
2018-10-31 19:25 justinpopo6
2018-11-01 10:06 ` Karel Zak
2018-11-01 10:09 ` Karel Zak
2018-11-01 18:11 ` Justin Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).