VirtualBox

Ignore:
Timestamp:
May 8, 2023 9:35:54 AM (23 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
157187
Message:

Guest Additions/VBoxClient: Added "--session-detect" command to only perform a display server detection (w/ exit code set). Useful for (user) diagnosis + testcase. bugref:10427

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

Legend:

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

    r99620 r99658  
    4848
    4949int VBClLogCreate(const char *pszLogFile);
     50int VBClLogCreateEx(const char *pszLogFile, bool fPrintHeader);
    5051void VBClLogSetLogPrefix(const char *pszPrefix);
    5152void VBClLogDestroy(void);
  • trunk/src/VBox/Additions/x11/VBoxClient/logging.cpp

    r99585 r99658  
    3232#include <iprt/buildconfig.h>
    3333#include <iprt/file.h>
     34#include <iprt/message.h>
    3435#include <iprt/process.h>
    3536#include <iprt/stream.h>
     
    365366
    366367/**
    367  * Creates the default release logger outputting to the specified file.
    368  *
    369  * Pass NULL to disabled logging.
     368 * Creates the default release logger outputting to the specified file, extended version.
    370369 *
    371370 * @return  IPRT status code.
    372  * @param   pszLogFile      Filename for log output.  NULL disables custom handling.
    373  */
    374 int VBClLogCreate(const char *pszLogFile)
     371 * @param   pszLogFile      Filename for log output. Empty filename allowed.
     372 * @param   fPrintHeader    Whether to print the VBoxClient logging header or not.
     373 */
     374int VBClLogCreateEx(const char *pszLogFile, bool fPrintHeader)
    375375{
    376376    if (!pszLogFile)
     
    386386                           RT_ELEMENTS(s_apszGroups), s_apszGroups, UINT32_MAX /*cMaxEntriesPerGroup*/,
    387387                           0 /*cBufDescs*/, NULL /*paBufDescs*/, RTLOGDEST_STDOUT | RTLOGDEST_USER,
    388                            vbClLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime,
     388                           fPrintHeader ? vbClLogHeaderFooter : NULL, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime,
    389389                           NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/,
    390390                           NULL /*pErrInfo*/, "%s", pszLogFile ? pszLogFile : "");
     
    396396        rc = RTLogSetCustomPrefixCallback(g_pLoggerRelease, vbClLogPrefixCb, NULL);
    397397        if (RT_FAILURE(rc))
    398             VBClLogError("unable to register custom log prefix callback\n");
     398            RTMsgError("unable to register custom log prefix callback\n");
    399399
    400400        /* Explicitly flush the log in case of VBOXSERVICE_RELEASE_LOG=buffered. */
    401401        RTLogFlush(g_pLoggerRelease);
    402402    }
     403    else
     404        RTMsgError("Failed to create release log '%s', rc=%Rrc\n", pszLogFile, rc);
    403405
    404406    return rc;
     
    406408
    407409/**
     410 * Creates the default release logger outputting to the specified file.
     411 *
     412 * @return  IPRT status code.
     413 * @param   pszLogFile      Filename for log output. Empty filename allowed.
     414 */
     415int VBClLogCreate(const char *pszLogFile)
     416{
     417    return VBClLogCreateEx(pszLogFile, true /* fPrintHeader */);
     418}
     419
     420/**
    408421 * Set custom log prefix.
    409422 *
  • trunk/src/VBox/Additions/x11/VBoxClient/main.cpp

    r99620 r99658  
    6464#define VBOXCLIENT_OPT_VMSVGA_SESSION       VBOXCLIENT_OPT_SERVICES + 5
    6565#define VBOXCLIENT_OPT_DISPLAY              VBOXCLIENT_OPT_SERVICES + 6
    66 #define VBOXCLIENT_OPT_SESSION_TYPE         VBOXCLIENT_OPT_SERVICES + 7
     66#define VBOXCLIENT_OPT_SESSION_DETECT       VBOXCLIENT_OPT_SERVICES + 7
     67#define VBOXCLIENT_OPT_SESSION_TYPE         VBOXCLIENT_OPT_SERVICES + 8
    6768
    6869
     
    327328#endif
    328329    RTPrintf("  --session-type       specifies the session type to use (auto, x11, wayland)\n");
     330    RTPrintf("  --session-detect     detects and prints the current session type\n"
     331             "                       (exit code 0 if detection succeeded)\n");
    329332    RTPrintf("  -f, --foreground     run in the foreground (no daemonizing)\n");
    330333    RTPrintf("  -d, --nodaemon       continues running as a system service\n");
     
    534537        { "--display",                      VBOXCLIENT_OPT_DISPLAY,             RTGETOPT_REQ_NOTHING },
    535538#endif
     539        { "--session-detect",               VBOXCLIENT_OPT_SESSION_DETECT,      RTGETOPT_REQ_NOTHING },
    536540        { "--session-type",                 VBOXCLIENT_OPT_SESSION_TYPE,        RTGETOPT_REQ_STRING }
    537541    };
     
    665669            }
    666670#endif
     671            case VBOXCLIENT_OPT_SESSION_DETECT:
     672            {
     673                rc = VBClLogCreateEx("" /* No file logging */, false /* No header */);
     674                if (RT_SUCCESS(rc))
     675                {
     676                    VBGHLogVerbositySet(2);
     677                    VBGHDISPLAYSERVERTYPE const enmType = VBGHDisplayServerTypeDetect();
     678                    VBClLogInfo("Detected session: %s\n", VBGHDisplayServerTypeToStr(enmType));
     679                    return enmType != VBGHDISPLAYSERVERTYPE_NONE ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     680                }
     681
     682                return RTEXITCODE_FAILURE;
     683            }
     684
    667685            case VBOXCLIENT_OPT_SESSION_TYPE:
    668686            {
     
    720738    rc = VBClLogCreate(g_szLogFile[0] ? g_szLogFile : "");
    721739    if (RT_FAILURE(rc))
    722         return RTMsgErrorExitFailure("Failed to create release log '%s', rc=%Rrc\n",
    723                               g_szLogFile[0] ? g_szLogFile : "<None>", rc);
     740        return RTEXITCODE_FAILURE; /* Error message already printed in VBClLogCreateEx(). */
    724741
    725742    if (!fDaemonise)
Note: See TracChangeset for help on using the changeset viewer.

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