VirtualBox

Changeset 99524 in vbox for trunk/src/VBox/Additions/linux


Ignore:
Timestamp:
Apr 24, 2023 4:54:25 PM (22 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
157028
Message:

Additions: Linux: rcvboxadd: improve logging and cleanup when Additions reloading fails, bugref:10359.

Be more granular when reporting failure during kernel modules and user services reloading.
Also terminate leftovers of pending CONTROL VBoxClient processes if SERVICE part
was already terminated, but cannot be restarted due to kernel modules loading failure.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/linux/installer/vboxadd.sh

    r99512 r99524  
    6767OLDMODULES="vboxguest vboxadd vboxsf vboxvfs vboxvideo"
    6868SERVICE="VirtualBox Guest Additions"
     69VBOXSERVICE_PIDFILE="/var/run/vboxadd-service.sh"
    6970## systemd logs information about service status, otherwise do that ourselves.
    7071QUIET=
     
    120121{
    121122    log "${1}"
    122     echo "$1" >&2
     123    echo "${SERVICE}: $1" >&2
    123124    echo "The log file $LOG may contain further information." >&2
    124125    exit 1
     
    962963check_pid()
    963964{
    964     pid=$1
     965    pid="$1"
    965966
    966967    test -n "$pid" -a -d "/proc/$pid"
     
    10081009check_status_user()
    10091010{
    1010     check_pid "$(cat /var/run/vboxadd-service.sh)" >/dev/null 2>&1
    1011 }
    1012 
    1013 send_sig_usr1_by_pidfile()
    1014 {
    1015     pidfile=$1
     1011    [ -r "$VBOXSERVICE_PIDFILE" ] && check_pid "$(cat $VBOXSERVICE_PIDFILE)" >/dev/null 2>&1
     1012}
     1013
     1014send_signal_by_pidfile()
     1015{
     1016    sig="$1"
     1017    pidfile="$2"
    10161018
    10171019    if [ -f "$pidfile" ]; then
    10181020        check_pid $(cat "$pidfile")
    10191021        if [ $? -eq 0 ]; then
    1020             kill -USR1 $(cat "$pidfile") >/dev/null 2>&1
     1022            kill "$sig" $(cat "$pidfile") >/dev/null 2>&1
    10211023        else
    10221024            # Do not spoil $?.
     
    10321034# update is started or kernel modules are going to be reloaded,
    10331035# so VBoxClient can release vboxguest.ko resources and then restart itself.
    1034 send_sig_usr1()
    1035 {
     1036send_signal()
     1037{
     1038    sig="$1"
    10361039    # Specify whether we sending signal to VBoxClient parent (control)
    10371040    # process or a child (actual service) process.
    1038     process_type="$1"
     1041    process_type="$2"
    10391042
    10401043    pidfile_postfix=""
     
    10531056                [ -z "$process_type" -a -n "$(echo "$pid_file" | grep "service")" ] && continue
    10541057
    1055                 send_sig_usr1_by_pidfile "$pid_file"
     1058                send_signal_by_pidfile -USR1 "$pid_file"
    10561059            done
    10571060
    10581061        fi
    10591062    done
     1063}
     1064
     1065# Helper function which executes a command, prints error message if command fails,
     1066# and preserves command execution status for further processing.
     1067try_load_preserve_rc()
     1068{
     1069    cmd="$1"
     1070    msg="$2"
     1071
     1072    $cmd >/dev/null 2>&1
     1073
     1074    rc=$?
     1075    [ $rc -eq 0 ] || info "$msg"
     1076
     1077    return $rc
    10601078}
    10611079
     
    10711089
    10721090    # Unmount Shared Folders.
    1073     umount -a -t vboxsf >/dev/null 2>&1 || fail "unable to unmount shared folders"
     1091    umount -a -t vboxsf >/dev/null 2>&1 || fail "unable to unmount shared folders, mount point(s) might be still in use"
    10741092
    10751093    # Stop VBoxDRMClient.
    1076     send_sig_usr1_by_pidfile "/var/run/VBoxDRMClient" || fail "unable to stop VBoxDRMClient"
     1094    send_signal_by_pidfile "-USR1" "/var/run/VBoxDRMClient" || fail "unable to stop VBoxDRMClient"
    10771095
    10781096    if [ $? -eq 0 ]; then
    10791097        # Tell legacy VBoxClient processes to release vboxguest.ko references.
    1080         send_sig_usr1 ""
     1098        send_signal "-USR1" ""
    10811099
    10821100        # Tell compatible VBoxClient processes to release vboxguest.ko references.
    1083         send_sig_usr1 "service"
     1101        send_signal "-USR1" "service"
    10841102
    10851103        # Try unload.
     
    11071125        running_vboxguest
    11081126        if [ $? -eq 0 ]; then
    1109             fail "Cannot reload kernel modules: one or more module(s) is still in use"
     1127            info "cannot reload kernel modules: one or more module(s) is still in use"
     1128            false
    11101129        else
    11111130            # Do not spoil $?.
     
    11141133
    11151134        # Load drivers (skip vboxvideo since it is not loaded for very old guests).
    1116         [ $? -eq 0 ] && modprobe vboxguest >/dev/null 2>&1
    1117         [ $? -eq 0 ] && modprobe vboxsf >/dev/null 2>&1
     1135        [ $? -eq 0 ] && try_load_preserve_rc "modprobe vboxguest" "unable to load vboxguest kernel module, see dmesg"
     1136        [ $? -eq 0 ] && try_load_preserve_rc "modprobe vboxsf" "unable to load vboxsf kernel module, see dmesg"
    11181137
    11191138        # Start VBoxService and VBoxDRMClient.
    1120         [ $? -eq 0 ] && $VBOX_SERVICE_SCRIPT start >/dev/null 2>&1
     1139        [ $? -eq 0 ] && try_load_preserve_rc "$VBOX_SERVICE_SCRIPT start" "unable to start VBoxService"
    11211140
    11221141        # Reload VBoxClient processes.
    1123         [ $? -eq 0 ] && send_sig_usr1 "control"
     1142        [ $? -eq 0 ] && try_load_preserve_rc "send_signal "-USR1" control" "unable to reload user session services"
    11241143
    11251144        if [ $? -eq 0 ]; then
     
    11351154            info "NOTE: you may still consider to re-login if some user session specific services (Shared Clipboard, Drag and Drop, Seamless or Guest Screen Resize) were not restarted automatically"
    11361155        else
    1137             fail "cannot verify if kernel modules and services were reloaded"
     1156            # In case of failure, sent SIGTERM to abandoned control processes to remove leftovers from failed reloading.
     1157            send_signal "-TERM" "control"
     1158
     1159            fail "kernel modules and services were not reloaded"
    11381160        fi
    11391161    else
     
    12181240        info "User-land services are running"
    12191241    else
    1220         fail "User-land services are not running"
     1242        info "User-land services are not running"
     1243        false
    12211244    fi
    12221245    ;;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette