[vbox-dev] Fix for "VirtualBox auto-starts VMs at boot only for one user"

Steffen Dettmer steffen.dettmer+vbox at gmail.com
Thu May 4 16:11:12 GMT 2023


Hi,

I had the issue that on bootup VMs for only one user are started, and
on the internet I found several others with the same issue. The
proposed workaround essentially was to start by an own script, but I
took a look.

I think I found the cause:

The script /usr/lib/virtualbox/vboxautostart-service.sh uses
"start-stop-daemon" when it exists:

  start-stop-daemon --chuid $usr --start --exec $bin -- $@

unfortunately it is called via function start_daemon() as:

  start_daemon "$user" "$binary" $PARAMS > /dev/null 2>&1

which is bad because it discards error messages (so systemd just tells
"terminated by exit 1" or alike). The error from start-stop-daemon I
saw after removing the redirection was:

  /usr/lib/virtualbox/VBoxAutostart already running.

but it terminates milliseconds after, so it is not easy to see. The
reason is that the process is started with --background and remains
running under first user (for a little moment). For the second user it
is started instantly too, but start-stop-daemon still sees the first
process and does not start the second.

As solution I think adding a user check to start-stop-deamon is sufficient:

       -u, --user username|uid
           Check for processes owned by the user specified by username or uid.

(and as said and I also propose to remove the redirection), so here is a patch:

--------------------------------------------
# diff -u /usr/lib/virtualbox/vboxautostart-service.sh.dist
/usr/lib/virtualbox/vboxautostart-service.sh
--- /usr/lib/virtualbox/vboxautostart-service.sh.dist   2023-04-13
13:18:58.000000000 +0200
+++ /usr/lib/virtualbox/vboxautostart-service.sh        2023-05-04
18:02:06.896185893 +0200
@@ -80,7 +80,7 @@
         shift
         bin="$1"
         shift
-        start-stop-daemon --chuid $usr --start --exec $bin -- $@
+        start-stop-daemon --chuid $usr --user $usr --start --exec $bin -- $@
     }
 fi

@@ -132,7 +132,7 @@
         [ "$user" = "*" ] && break
         valid_db_entry "$entry" "$user" || continue

-        start_daemon "$user" "$binary" $PARAMS > /dev/null 2>&1
+        start_daemon "$user" "$binary" $PARAMS
     done

     return $RETVAL
--------------------------------------------

NB; Due to the trivial kind of this change no license / CA / prop
release is possible or needed, it is free to use in any way, because
trivial bug fixes are not copyrightable at all, since they are way
below the threshold of originality needed for copyrights.

Regards,
Steffen



More information about the vbox-dev mailing list