Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support halt/poweroff/reboot binaries for System_Shutdown() #235

Open
Hackebein opened this issue Mar 3, 2018 · 8 comments · May be fixed by #556
Open

Support halt/poweroff/reboot binaries for System_Shutdown() #235

Hackebein opened this issue Mar 3, 2018 · 8 comments · May be fixed by #556

Comments

@Hackebein
Copy link

Some systems based on buildroot (ex. RancherOS) and alpine linux have no binary like /sbin/shutdown, instead they use /sbin/halt (shutdown), /sbin/poweroff (shutdown with ACPI) and /sbin/reboot (reboot).
I prefere to add a case to switch to the USERWORLD binaries without add the complete USERWORLD cases.

@oliverkurth
Copy link
Contributor

Thanks for your input. I don't quite understand what you mean with

I prefere to add a case to switch to the USERWORLD binaries without add the complete USERWORLD cases

Can you elaborate? What do you mean with "USERWORLD binaries"?

@Hackebein
Copy link
Author

Hackebein commented Mar 3, 2018

Thanks for your fast answer.

I talking about this function: lib/system/systemLinux.c#L379 System_Shutdown()

I can switch to the /sbin/halt and /sbin/reboot binaries if i define USERWORLD, but that activate all USERWORLD cases. Based on this post it seems to be a bad idea.

ravindravmw (Contributor) on 29 Jan 2016
USERWORLD define is used by other VMware products that use this code. This is not relevant when one is building open-vm-tools. I'm sure you would get lots of compilation errors when you use that define. You should not need to use that define for building open-vm-tools.

@oliverkurth
Copy link
Contributor

Oh, I understand. I agree with @ravindravmw , defining USERWORLD is a very bad idea.

I filed an internal bug for this. I think a good solution would be to make this configurable. Right now you would need to patch the code here:

cmd = "/sbin/shutdown -r now";

@Hackebein
Copy link
Author

Is there any further information about the current status?

@oliverkurth
Copy link
Contributor

Hello @Hackebein ,

we do have this issue in our queue, but I am sorry, it's probably not going to be addressed any time. soon. There are no other requests to change this. So my suggestion is to work around this for now, either by patching as suggested above, or provide a script called /sbin/shutdown that does the desired action.

@oliverkurth
Copy link
Contributor

Btw, if you want you can also provide a patch via a pull request to fix this, for example by making this configurable.

@lflare
Copy link

lflare commented Oct 30, 2018

It should be a fairly easy switch to excute /sbin/halt if it detects buildroot.

@ncopa
Copy link

ncopa commented Nov 17, 2021

Something like this?

diff --git a/open-vm-tools/configure.ac b/open-vm-tools/configure.ac
index dba033b1..3aa6a87f 100644
--- a/open-vm-tools/configure.ac
+++ b/open-vm-tools/configure.ac
@@ -1460,6 +1460,15 @@ else
     UDEVRULESDIR=""
 fi
 
+AC_ARG_WITH([shutdown-command],
+            [AS_HELP_STRING([--with-shutdown-command=COMMAND],
+                            [command to perform shutdown])],
+            [AC_DEFINE_UNQUOTED([SHUTDOWN_COMMAND], ["$withval"], [])])
+AC_ARG_WITH([reboot-command],
+            [AS_HELP_STRING([--with-reboot-command=COMMAND],
+                            [command to perform reboot])],
+            [AC_DEFINE_UNQUOTED([REBOOT_COMMAND], ["$withval"], [])])
+
 if test "x$enable_resolutionkms" = "xauto"; then
    enable_resolutionkms="no"
 fi
diff --git a/open-vm-tools/lib/system/systemLinux.c b/open-vm-tools/lib/system/systemLinux.c
index a688ab25..67100a1a 100644
--- a/open-vm-tools/lib/system/systemLinux.c
+++ b/open-vm-tools/lib/system/systemLinux.c
@@ -307,7 +307,9 @@ System_Shutdown(Bool reboot)  // IN: "reboot or shutdown" flag
    char *cmd;
 
    if (reboot) {
-#if defined(sun)
+#if defined(REBOOT_COMMAND)
+      cmd = REBOOT_COMMAND;
+#elif defined(sun)
       cmd = "/usr/sbin/shutdown -g 0 -i 6 -y";
 #elif defined(USERWORLD)
       cmd = "/bin/reboot";
@@ -315,7 +317,9 @@ System_Shutdown(Bool reboot)  // IN: "reboot or shutdown" flag
       cmd = "/sbin/shutdown -r now";
 #endif
    } else {
-#if __FreeBSD__
+#if defined(SHUTDOWN_COMMAND)
+      cmd = SHUTDOWN_COMMAND;
+#elif __FreeBSD__
       cmd = "/sbin/shutdown -p now";
 #elif defined(sun)
       cmd = "/usr/sbin/shutdown -g 0 -i 5 -y";

ncopa added a commit to ncopa/open-vm-tools that referenced this issue Nov 17, 2021
Some systems, like Alpine Linux, may not use /sbin/shutdown to power off
or reboot. Add configure option so user can set the correct commands.

Fixes vmware#235

Signed-off-by: Natanael Copa <[email protected]>
@ncopa ncopa linked a pull request Nov 17, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants