vuls: init at 0.27.0 (#348530)
[NixPkgs.git] / pkgs / os-specific / linux / util-linux / rtcwake-search-PATH-for-shutdown.patch
blob52c970a18f3daf5d03e52be016595eb1dd3bdbfa
1 Search $PATH for the shutdown binary instead of hard-coding /sbin/shutdown,
2 which isn't valid on NixOS (and a compatibility link on most other modern
3 distros anyway).
5 --- a/include/pathnames.h
6 +++ b/include/pathnames.h
7 @@ -50,8 +50,8 @@
8 #ifndef _PATH_LOGIN
9 # define _PATH_LOGIN "/bin/login"
10 #endif
11 -#define _PATH_SHUTDOWN "/sbin/shutdown"
12 -#define _PATH_POWEROFF "/sbin/poweroff"
13 +#define _PATH_SHUTDOWN "shutdown"
14 +#define _PATH_POWEROFF "poweroff"
16 #define _PATH_TERMCOLORS_DIRNAME "terminal-colors.d"
17 #define _PATH_TERMCOLORS_DIR "/etc/" _PATH_TERMCOLORS_DIRNAME
18 --- a/sys-utils/rtcwake.c
19 +++ b/sys-utils/rtcwake.c
20 @@ -587,29 +587,29 @@ int main(int argc, char **argv)
21 char *arg[5];
22 int i = 0;
24 - if (!access(_PATH_SHUTDOWN, X_OK)) {
25 - arg[i++] = _PATH_SHUTDOWN;
26 - arg[i++] = "-h";
27 - arg[i++] = "-P";
28 - arg[i++] = "now";
29 - arg[i] = NULL;
30 - } else if (!access(_PATH_POWEROFF, X_OK)) {
31 - arg[i++] = _PATH_POWEROFF;
32 - arg[i] = NULL;
33 - } else {
34 - arg[i] = NULL;
35 - }
36 + arg[i++] = _PATH_SHUTDOWN;
37 + arg[i++] = "-h";
38 + arg[i++] = "-P";
39 + arg[i++] = "now";
40 + arg[i] = NULL;
42 - if (arg[0]) {
43 - if (ctl.verbose)
44 - printf(_("suspend mode: off; executing %s\n"),
45 - arg[0]);
46 - if (!ctl.dryrun) {
47 - execv(arg[0], arg);
48 + if (ctl.verbose)
49 + printf(_("suspend mode: off; executing %s\n"),
50 + arg[0]);
52 + if (!ctl.dryrun) {
53 + execvp(arg[0], arg);
54 + if (ctl.verbose) {
55 warn(_("failed to execute %s"), arg[0]);
56 - rc = EX_EXEC_ENOENT;
57 + // Reuse translations.
58 + printf(_("suspend mode: off; executing %s\n"),
59 + _PATH_POWEROFF);
61 - } else {
63 + i = 0;
64 + arg[i++] = _PATH_POWEROFF;
65 + arg[i] = NULL;
66 + execvp(arg[0], arg);
67 /* Failed to find shutdown command */
68 warn(_("failed to find shutdown command"));
69 rc = EX_EXEC_ENOENT;