VirtualBox

Ignore:
Timestamp:
Feb 3, 2023 7:20:53 PM (22 months ago)
Author:
vboxsync
Message:

Additions: X11: Add possibility restart VBoxClient processes during Guest Additions update, bugref:10359.

This commit makes VBoxClient processes to temporary release reference to vboxguest kernel module and then
restart itself. So module can be reloaded and newly started VBoxClient instance will utilize updated module.

When VBoxClient starts in demonized mode, it forks a child process which represents actual service. Parent
process continues to run and its main function is to restart child when it crashes or terminates with exit
status != 0. This commit makes child process to catch SIGUSR1 and terminate with exit
status VBGLR3EXITCODERELOAD (currently equal to 2). Parent process will detect this and in turn will release
its reference to vboxguest kernel module, allowing to reload it. The parent process will then wait for SIGUSR1
itself. Once received, it will restart itself (loading new, updated VBoxClient process image). This is a part
of the procedure to install and reload/restart Guest Additions kernel modules and user services without
requiring guest reboot.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/display-svga-session.cpp

    r98103 r98474  
    4646 *
    4747 * Multiple instances of this daemon are allowed to run in parallel
    48  * with the following limitations (see also vbclSVGASessionPidFileLock()).
     48 * with the following limitations.
    4949 * A single user cannot run multiple daemon instances per single TTY device,
    5050 * however, multiple instances are allowed for the user on different
     
    6767#include <iprt/linux/sysfs.h>
    6868
    69 /** Lock file handle. */
    70 static RTFILE g_hPidFile;
    71 /** Full path to PID lock file. */
    72 static char g_szPidFilePath[RTPATH_MAX];
    7369
    7470/** Handle to IPC client connection. */
     
    117113
    118114/**
    119  * Prevent multiple instances of the service from start.
    120  *
    121  * @returns IPRT status code.
    122  */
    123 static int vbclSVGASessionPidFileLock(void)
    124 {
    125     int rc;
    126 
    127     /* Allow parallel running instances of the service for processes
    128      * which are running in separate X11/Wayland sessions. Compose
    129      * custom PID file name based on currently active TTY device. */
    130 
    131     char *pszPidFileName = RTStrAlloc(RTPATH_MAX);
    132     if (pszPidFileName)
    133     {
    134         rc = RTPathUserHome(g_szPidFilePath, sizeof(g_szPidFilePath));
    135         if (RT_SUCCESS(rc))
    136         {
    137             char pszActiveTTY[128];
    138             size_t cchRead;
    139 
    140             RT_ZERO(pszActiveTTY);
    141 
    142             RTStrAAppend(&pszPidFileName, ".vboxclient-vmsvga-session");
    143 
    144             rc = RTLinuxSysFsReadStrFile(pszActiveTTY, sizeof(pszActiveTTY) - 1 /* reserve last byte for string termination */,
    145                                          &cchRead, "class/tty/tty0/active");
    146             if (RT_SUCCESS(rc))
    147             {
    148                 RTStrAAppend(&pszPidFileName, "-");
    149                 RTStrAAppend(&pszPidFileName, pszActiveTTY);
    150             }
    151             else
    152                 VBClLogInfo("cannot detect currently active tty device, "
    153                             "multiple service instances for a single user will not be allowed, rc=%Rrc", rc);
    154 
    155             RTStrAAppend(&pszPidFileName, ".pid");
    156 
    157             RTPathAppend(g_szPidFilePath, sizeof(g_szPidFilePath), pszPidFileName);
    158 
    159             VBClLogVerbose(1, "lock file path: %s\n", g_szPidFilePath);
    160             rc = VbglR3PidFile(g_szPidFilePath, &g_hPidFile);
    161         }
    162         else
    163             VBClLogError("unable to get user home directory, rc=%Rrc\n", rc);
    164 
    165         RTStrFree(pszPidFileName);
    166     }
    167     else
    168         rc = VERR_NO_MEMORY;
    169 
    170     return rc;
    171 }
    172 
    173 /**
    174  * Release lock file.
    175  */
    176 static void vbclSVGASessionPidFileRelease(void)
    177 {
    178     VbglR3ClosePidFile(g_szPidFilePath, g_hPidFile);
    179 }
    180 
    181 /**
    182115 * @interface_method_impl{VBCLSERVICE,pfnInit}
    183116 */
     
    192125
    193126    VBClLogSetLogPrefix(pszLogPrefix);
    194 
    195     rc = vbclSVGASessionPidFileLock();
    196     if (RT_FAILURE(rc))
    197     {
    198         VBClLogVerbose(1, "cannot acquire pid lock, rc=%Rrc\n", rc);
    199         return rc;
    200     }
    201127
    202128    rc = RTCritSectInit(&g_hClientCritSect);
     
    517443    }
    518444
    519     vbclSVGASessionPidFileRelease();
    520 
    521445    return VINF_SUCCESS;
    522446}
     
    526450    "vmsvga-session",                   /* szName */
    527451    "VMSVGA display assistant",         /* pszDescription */
    528     NULL,                               /* pszPidFilePath (no pid file lock) */
     452    ".vboxclient-vmsvga-session",       /* pszPidFilePathTemplate */
    529453    NULL,                               /* pszUsage */
    530454    NULL,                               /* pszOptions */
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