VirtualBox

Ignore:
Timestamp:
Feb 3, 2023 6:56:59 PM (2 years ago)
Author:
vboxsync
Message:

Guest Library: Introduce VbglR3DaemonizeEx and VbglR3PidfileWait, bugref:10359.

VbglR3DaemonizeEx is a wrapper function for VbglR3Daemonize. In addition to the
original version it sets pidfile lock for the parent process and notifies caller
when child process terminates with exit status VBGLR3EXITCODERELOAD (currently
equal to 2) indicating that parent process should release its reference to vboxguest
kernel module and wait for SIGUSR2 in order to restart itself. This is a part of
the procedure to install and reload/restart Guest Additions kernel modules and
user services without requiring guest reboot. It is currently only has effect
on X11 guests.

VbglR3PidfileWait is a wrapper function for VbglR3Pidfile. In addition to the
original version, it waits specified amount of time until pidfile lock become
available or fails on timeout.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibPidFile.cpp

    r98103 r98472  
    4343#include <iprt/string.h>
    4444#include <iprt/process.h>
     45#include <iprt/err.h>
    4546#include "VBoxGuestR3LibInternal.h"
     47
     48/* A time to wait before starting the next attempt to check a pidfile. */
     49#define VBGL_PIDFILE_WAIT_RELAX_TIME_MS (250)
    4650
    4751/**
     
    117121}
    118122
     123
     124/**
     125 * Wait for other process to release pidfile.
     126 *
     127 * This function is a wrapper to VbglR3PidFile().
     128 *
     129 * @returns IPRT status code.
     130 * @param   szPidfile       Path to pidfile.
     131 * @param   phPidfile       Handle to pidfile.
     132 * @param   u64TimeoutMs    A timeout value in milliseconds to wait for
     133 *                          other process to release pidfile.
     134 */
     135VBGLR3DECL(int) VbglR3PidfileWait(const char *szPidfile, RTFILE *phPidfile, uint64_t u64TimeoutMs)
     136{
     137    int rc = VERR_FILE_LOCK_VIOLATION;
     138    uint64_t u64Start = RTTimeSystemMilliTS();
     139
     140    AssertPtrReturn(szPidfile, VERR_INVALID_PARAMETER);
     141    AssertPtrReturn(phPidfile, VERR_INVALID_PARAMETER);
     142
     143    while (   !RT_SUCCESS((rc = VbglR3PidFile(szPidfile, phPidfile)))
     144           && (RTTimeSystemMilliTS() - u64Start < u64TimeoutMs))
     145    {
     146        RTThreadSleep(VBGL_PIDFILE_WAIT_RELAX_TIME_MS);
     147    }
     148
     149    return rc;
     150}
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