VirtualBox

Changeset 81052 in vbox for trunk/src/VBox/Additions/x11


Ignore:
Timestamp:
Sep 27, 2019 12:44:45 PM (5 years ago)
Author:
vboxsync
Message:

Additions/VBoxClient: Added proper logfile handling (and rotation support, like for VBoxService), together with additional information. Uses VBOXCLIENT_ log prefix, e.g. VBOXCLIENT_[RELEASE_]LOG.

Location:
trunk/src/VBox/Additions/x11/VBoxClient
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/Makefile.kmk

    r80862 r81052  
    2626VBoxClient_TEMPLATE = NewVBoxGuestR3Exe
    2727VBoxClient_DEFS += VBOX_X11_CLIPBOARD VBOX_WITH_HGCM
     28VBoxClient_DEFS += VBOX_BUILD_TARGET=\"$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)\"
    2829ifdef VBOX_WITH_DBUS
    2930 VBoxClient_DEFS += VBOX_WITH_DBUS
  • trunk/src/VBox/Additions/x11/VBoxClient/VBoxClient.h

    r81042 r81052  
    3838struct VBCLSERVICE
    3939{
     40    /** Returns the (friendly) name of the service. */
     41    const char *(*getName)(void);
    4042    /** Get the services default path to pidfile, relative to $HOME */
    4143    /** @todo Should this also have a component relative to the X server number?
  • trunk/src/VBox/Additions/x11/VBoxClient/clipboard.cpp

    r81044 r81052  
    285285}
    286286
     287static const char *getName()
     288{
     289    return "Shared Clipboard";
     290}
     291
    287292static const char *getPidFilePath()
    288293{
     
    314319struct VBCLSERVICE vbclClipboardInterface =
    315320{
     321    getName,
    316322    getPidFilePath,
    317323    VBClServiceDefaultHandler, /* init */
  • trunk/src/VBox/Additions/x11/VBoxClient/display-svga-x11.cpp

    r81040 r81052  
    223223    if (!_XReply(pContext->pDisplay, (xReply *)&repGetScreen, 0, xTrue))
    224224        VBClLogFatalError("%s failed to set resolution\n", __func__);
     225}
     226
     227static const char *getName()
     228{
     229    return "Display SVGA X11";
    225230}
    226231
     
    295300static struct VBCLSERVICE interface =
    296301{
     302    getName,
    297303    getPidFilePath,
    298304    VBClServiceDefaultHandler, /* Init */
  • trunk/src/VBox/Additions/x11/VBoxClient/display-svga.cpp

    r81040 r81052  
    165165    if (RT_FAILURE(rc) && rc != VERR_INVALID_PARAMETER)
    166166        VBClLogFatalError("Failure updating layout, rc=%Rrc\n", rc);
     167}
     168
     169static const char *getName()
     170{
     171    return "Display SVGA";
    167172}
    168173
     
    239244static struct VBCLSERVICE interface =
    240245{
     246    getName,
    241247    getPidFilePath,
    242248    VBClServiceDefaultHandler, /* Init */
  • trunk/src/VBox/Additions/x11/VBoxClient/display.cpp

    r81040 r81052  
    222222}
    223223
     224static const char *getName()
     225{
     226    return "Display";
     227}
     228
    224229static const char *getPidFilePath()
    225230{
     
    263268struct VBCLSERVICE vbclDisplayInterface =
    264269{
     270    getName,
    265271    getPidFilePath,
    266272    init,
  • trunk/src/VBox/Additions/x11/VBoxClient/draganddrop.cpp

    r81042 r81052  
    34793479};
    34803480
     3481static const char *getName()
     3482{
     3483    return "Drag and Drop (DnD)";
     3484}
     3485
    34813486static const char *getPidFilePath()
    34823487{
     
    35133518struct VBCLSERVICE vbclDragAndDropInterface =
    35143519{
     3520    getName,
    35153521    getPidFilePath,
    35163522    init,
  • trunk/src/VBox/Additions/x11/VBoxClient/hostversion.cpp

    r81042 r81052  
    3434#include "VBoxClient.h"
    3535
     36static const char *getName()
     37{
     38    return "Host Version Check";
     39}
     40
    3641static const char *getPidFilePath()
    3742{
     
    200205struct VBCLSERVICE vbclHostVersionInterface =
    201206{
     207    getName,
    202208    getPidFilePath,
    203209    VBClServiceDefaultHandler, /* init */
  • trunk/src/VBox/Additions/x11/VBoxClient/main.cpp

    r81040 r81052  
    3333#include <X11/Xatom.h>
    3434
     35#include <package-generated.h>
     36#include "product-generated.h"
     37
    3538#include <iprt/buildconfig.h>
    3639#include <iprt/critsect.h>
     
    4144#include <iprt/path.h>
    4245#include <iprt/param.h>
     46#include <iprt/process.h>
    4347#include <iprt/stream.h>
    4448#include <iprt/string.h>
     49#include <iprt/system.h>
    4550#include <iprt/types.h>
    4651#include <VBox/VBoxGuestLib.h>
     
    6166/** The name of our pidfile.  It is global for the benefit of the cleanup
    6267 * routine. */
    63 static char g_szPidFile[RTPATH_MAX] = "";
     68static char          g_szPidFile[RTPATH_MAX] = "";
    6469/** The file handle of our pidfile.  It is global for the benefit of the
    6570 * cleanup routine. */
    66 static RTFILE g_hPidFile;
     71static RTFILE        g_hPidFile;
    6772/** Global critical section held during the clean-up routine (to prevent it
    6873 * being called on multiple threads at once) or things which may not happen
    6974 * during clean-up (e.g. pausing and resuming the service).
    7075 */
    71 RTCRITSECT g_critSect;
     76static RTCRITSECT    g_critSect;
    7277/** Counter of how often our daemon has been respawned. */
    73 unsigned g_cRespawn = 0;
     78static unsigned      g_cRespawn = 0;
    7479/** Logging verbosity level. */
    75 unsigned g_cVerbosity = 0;
     80static unsigned      g_cVerbosity = 0;
     81static char          g_szLogFile[RTPATH_MAX + 128] = "";
     82/** Logging parameters. */
     83/** @todo Make this configurable later. */
     84static PRTLOGGER     g_pLoggerRelease = NULL;
     85static uint32_t      g_cHistory = 10;                   /* Enable log rotation, 10 files. */
     86static uint32_t      g_uHistoryFileTime = RT_SEC_1DAY;  /* Max 1 day per file. */
     87static uint64_t      g_uHistoryFileSize = 100 * _1M;    /* Max 100MB per file. */
    7688
    7789/**
     
    179191    AssertPtr(psz);
    180192    LogFlowFunc(("%s", psz));
    181     LogRel2(("%s", psz));
     193    LogRel(("%s", psz));
    182194
    183195    RTStrFree(psz);
     196}
     197
     198/**
     199 * @callback_method_impl{FNRTLOGPHASE, Release logger callback}
     200 */
     201static DECLCALLBACK(void) vbClLogHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog)
     202{
     203    /* Some introductory information. */
     204    static RTTIMESPEC s_TimeSpec;
     205    char szTmp[256];
     206    if (enmPhase == RTLOGPHASE_BEGIN)
     207        RTTimeNow(&s_TimeSpec);
     208    RTTimeSpecToString(&s_TimeSpec, szTmp, sizeof(szTmp));
     209
     210    switch (enmPhase)
     211    {
     212        case RTLOGPHASE_BEGIN:
     213        {
     214            pfnLog(pLoggerRelease,
     215                   "VBoxClient %s r%s (verbosity: %u) %s (%s %s) release log\n"
     216                   "Log opened %s\n",
     217                   RTBldCfgVersion(), RTBldCfgRevisionStr(), g_cVerbosity, VBOX_BUILD_TARGET,
     218                   __DATE__, __TIME__, szTmp);
     219
     220            int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
     221            if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
     222                pfnLog(pLoggerRelease, "OS Product: %s\n", szTmp);
     223            vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
     224            if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
     225                pfnLog(pLoggerRelease, "OS Release: %s\n", szTmp);
     226            vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
     227            if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
     228                pfnLog(pLoggerRelease, "OS Version: %s\n", szTmp);
     229            vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof(szTmp));
     230            if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
     231                pfnLog(pLoggerRelease, "OS Service Pack: %s\n", szTmp);
     232
     233            /* the package type is interesting for Linux distributions */
     234            char szExecName[RTPATH_MAX];
     235            char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName));
     236            pfnLog(pLoggerRelease,
     237                   "Executable: %s\n"
     238                   "Process ID: %u\n"
     239                   "Package type: %s"
     240#ifdef VBOX_OSE
     241                   " (OSE)"
     242#endif
     243                   "\n",
     244                   pszExecName ? pszExecName : "unknown",
     245                   RTProcSelf(),
     246                   VBOX_PACKAGE_STRING);
     247            break;
     248        }
     249
     250        case RTLOGPHASE_PREROTATE:
     251            pfnLog(pLoggerRelease, "Log rotated - Log started %s\n", szTmp);
     252            break;
     253
     254        case RTLOGPHASE_POSTROTATE:
     255            pfnLog(pLoggerRelease, "Log continuation - Log started %s\n", szTmp);
     256            break;
     257
     258        case RTLOGPHASE_END:
     259            pfnLog(pLoggerRelease, "End of log file - Log started %s\n", szTmp);
     260            break;
     261
     262        default:
     263            /* nothing */
     264            break;
     265    }
     266}
     267
     268/**
     269 * Creates the default release logger outputting to the specified file.
     270 *
     271 * Pass NULL to disabled logging.
     272 *
     273 * @return  IPRT status code.
     274 * @param   pszLogFile      Filename for log output.  NULL disables logging
     275 *                          (r=bird: No, it doesn't!).
     276 */
     277int VBClLogCreate(const char *pszLogFile)
     278{
     279    /* Create release logger (stdout + file). */
     280    static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
     281    RTUINT fFlags = RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME;
     282#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
     283    fFlags |= RTLOGFLAGS_USECRLF;
     284#endif
     285    int rc = RTLogCreateEx(&g_pLoggerRelease, fFlags, "all",
     286#ifdef DEBUG
     287                           "VBOXCLIENT_LOG",
     288#else
     289                           "VBOXCLIENT_RELEASE_LOG",
     290#endif
     291                           RT_ELEMENTS(s_apszGroups), s_apszGroups, UINT32_MAX /*cMaxEntriesPerGroup*/,
     292                           RTLOGDEST_STDOUT | RTLOGDEST_USER,
     293                           vbClLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime,
     294                           NULL /*pErrInfo*/, "%s", pszLogFile ? pszLogFile : "");
     295    if (RT_SUCCESS(rc))
     296    {
     297        /* register this logger as the release logger */
     298        RTLogRelSetDefaultInstance(g_pLoggerRelease);
     299
     300        /* Explicitly flush the log in case of VBOXSERVICE_RELEASE_LOG=buffered. */
     301        RTLogFlush(g_pLoggerRelease);
     302    }
     303
     304    return rc;
     305}
     306
     307/**
     308 * Destroys the currently active logging instance.
     309 */
     310void VBClLogDestroy(void)
     311{
     312    RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
    184313}
    185314
     
    201330    if (g_szPidFile[0] && g_hPidFile)
    202331        VbglR3ClosePidFile(g_szPidFile, g_hPidFile);
     332
     333    VBClLogDestroy();
     334
    203335    if (fExit)
    204336        exit(RTEXITCODE_SUCCESS);
     
    434566    if (RT_FAILURE(rc))
    435567        VBClLogFatalError("VbglR3InitUser failed: %Rrc", rc);
     568
     569    rc = VBClLogCreate(g_szLogFile[0] ? g_szLogFile : NULL);
     570    if (RT_FAILURE(rc))
     571        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to create release log '%s', rc=%Rrc\n",
     572                              g_szLogFile[0] ? g_szLogFile : "<None>", rc);
     573
     574    LogRel(("Service: %s\n", (*g_pService)->getName()));
    436575
    437576    if (!fDaemonise)
  • trunk/src/VBox/Additions/x11/VBoxClient/seamless.cpp

    r81042 r81052  
    267267};
    268268
     269static const char *getName()
     270{
     271    return "Seamless";
     272}
     273
    269274static const char *getPidFilePath(void)
    270275{
     
    318323struct VBCLSERVICE vbclSeamlessInterface =
    319324{
     325    getName,
    320326    getPidFilePath,
    321327    init,
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