/bin/shutdown exits non-zero, even when successful

The /bin/shutdown binary exits with a non-zero status, even though it is able to power off the system. This ordinarily doesn’t affect most users, however this breaks automated components like SSH commands and Vagrant boxes, which treat non-zero status to indicate an error. In the future, /bin/shutdown should really return a zero exit status unless there is a privilege issue or such preventing the command from operating normally.

In alpha 4, I was able to work around this by moving the ordinary /bin/shutdown binary to /bin/shutdown-actual and placing a shell script shim at /bin/shutdown, that invokes /bin/shutdown-actual with any passed in arguments and then exits zero. However, in Haiku nightly, this file path is no longer modifiable. I’m thinking of further workarounds so that vagrant halt can work correctly with Haiku nightly guests. There is also the possibility of patching the Haiku guest plugin for Vagrant to ignore the exit status, though accepting and releasing that change would take some time.

I’d post this in Trac, but I haven’t received email verification for my account yet.

what you can do is to shadow /bin/shutdown by placing your custom one in /boot/system/non-packaged/bin/ (don’t forget executable bit)

and about Trac there you may login and go to http://dev.haiku-os.org/verify_email and request a new email.

1 Like

Good catch!
Fixed in hrev51912.

1 Like

That’s so cool! I wished for a shadowing ability for /bin and lo, Haiku doth offer it!

I don’t see hrev51912 posted just yet, so I’ll lean on shadowing for now and consider revisiting my Packer source later.

Update

Unfortunately, the Vagrant Haiku guest plugin hardcodes the absolute path /bin/shutdown, so the shutdown command I placed in /boot/system/non-packaged/bin is not invoked when “/bin/shutdown” is called. Sad panda.

your last chance is to unpack /system/packages/haiku-r1~.......hpkg, customize shutdown, repack and replace package with the custom one.

the tool used for this is package

edit: looking in docs it looks like you can use package to modify a file without extracting first

Managed to work around this while waiting for hrev51912 x86_64 to publish, by:

  • Shadowing native /bin/shutdown with a slapdash wrapper in /boot/system/non-packaged/bin, that exits status zero.
  • Reference the Linux Vagrant guest plugin rather than the old Haiku Vagrant guest plugin, so that the command is invoked as shutdown (shadowable) instead of /bin/shutdown (not shadowable).
  • Workaround further issues created by using the Linux Vagrant guest plugin for a Haiku VM, such as shimming references to sudo. Since su is broken and we’re running in single-user mode anyway, a sudo shell script shadow with contents "$@" is often sufficient, assuming no flags are specified to sudo.

I’ll be publishing my Haiku nightly Vagrant box soon along with its Packer source, just need to separate out the x86_64 vs x86 editions.