diff options
author | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2023-05-08 09:35:54 +0000 |
---|---|---|
committer | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2023-05-08 09:35:54 +0000 |
commit | 82f6bddc57e95cb6214889fd19119f9607eda926 (patch) | |
tree | 08110066ae1bb56299456d31ab74c7451bf768b0 /src | |
parent | 6f2f71390e2f005290ba28e5b6a101e2a3b13996 (diff) | |
download | VirtualBox-svn-82f6bddc57e95cb6214889fd19119f9607eda926.tar.gz |
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
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@99658 cfe28804-0f27-0410-a406-dd0f0b0b656f
Diffstat (limited to 'src')
-rw-r--r-- | src/VBox/Additions/x11/VBoxClient/VBoxClient.h | 1 | ||||
-rw-r--r-- | src/VBox/Additions/x11/VBoxClient/logging.cpp | 27 | ||||
-rw-r--r-- | src/VBox/Additions/x11/VBoxClient/main.cpp | 23 |
3 files changed, 41 insertions, 10 deletions
diff --git a/src/VBox/Additions/x11/VBoxClient/VBoxClient.h b/src/VBox/Additions/x11/VBoxClient/VBoxClient.h index 01ffe91aa50..1edf2f6d3a4 100644 --- a/src/VBox/Additions/x11/VBoxClient/VBoxClient.h +++ b/src/VBox/Additions/x11/VBoxClient/VBoxClient.h @@ -47,6 +47,7 @@ void VBClLogFatalError(const char *pszFormat, ...); void VBClLogVerbose(unsigned iLevel, const char *pszFormat, ...); int VBClLogCreate(const char *pszLogFile); +int VBClLogCreateEx(const char *pszLogFile, bool fPrintHeader); void VBClLogSetLogPrefix(const char *pszPrefix); void VBClLogDestroy(void); diff --git a/src/VBox/Additions/x11/VBoxClient/logging.cpp b/src/VBox/Additions/x11/VBoxClient/logging.cpp index 1ac1413ae52..ebd8cd13ba8 100644 --- a/src/VBox/Additions/x11/VBoxClient/logging.cpp +++ b/src/VBox/Additions/x11/VBoxClient/logging.cpp @@ -31,6 +31,7 @@ #include <iprt/buildconfig.h> #include <iprt/file.h> +#include <iprt/message.h> #include <iprt/process.h> #include <iprt/stream.h> #include <iprt/system.h> @@ -364,14 +365,13 @@ static DECLCALLBACK(size_t) vbClLogPrefixCb(PRTLOGGER pLogger, char *pchBuf, siz } /** - * Creates the default release logger outputting to the specified file. - * - * Pass NULL to disabled logging. + * Creates the default release logger outputting to the specified file, extended version. * * @return IPRT status code. - * @param pszLogFile Filename for log output. NULL disables custom handling. + * @param pszLogFile Filename for log output. Empty filename allowed. + * @param fPrintHeader Whether to print the VBoxClient logging header or not. */ -int VBClLogCreate(const char *pszLogFile) +int VBClLogCreateEx(const char *pszLogFile, bool fPrintHeader) { if (!pszLogFile) return VINF_SUCCESS; @@ -385,7 +385,7 @@ int VBClLogCreate(const char *pszLogFile) int rc = RTLogCreateEx(&g_pLoggerRelease, "VBOXCLIENT_RELEASE_LOG", fFlags, "all", RT_ELEMENTS(s_apszGroups), s_apszGroups, UINT32_MAX /*cMaxEntriesPerGroup*/, 0 /*cBufDescs*/, NULL /*paBufDescs*/, RTLOGDEST_STDOUT | RTLOGDEST_USER, - vbClLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime, + fPrintHeader ? vbClLogHeaderFooter : NULL, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime, NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/, NULL /*pErrInfo*/, "%s", pszLogFile ? pszLogFile : ""); if (RT_SUCCESS(rc)) @@ -395,16 +395,29 @@ int VBClLogCreate(const char *pszLogFile) rc = RTLogSetCustomPrefixCallback(g_pLoggerRelease, vbClLogPrefixCb, NULL); if (RT_FAILURE(rc)) - VBClLogError("unable to register custom log prefix callback\n"); + RTMsgError("unable to register custom log prefix callback\n"); /* Explicitly flush the log in case of VBOXSERVICE_RELEASE_LOG=buffered. */ RTLogFlush(g_pLoggerRelease); } + else + RTMsgError("Failed to create release log '%s', rc=%Rrc\n", pszLogFile, rc); return rc; } /** + * Creates the default release logger outputting to the specified file. + * + * @return IPRT status code. + * @param pszLogFile Filename for log output. Empty filename allowed. + */ +int VBClLogCreate(const char *pszLogFile) +{ + return VBClLogCreateEx(pszLogFile, true /* fPrintHeader */); +} + +/** * Set custom log prefix. * * @param pszPrefix Custom log prefix string. diff --git a/src/VBox/Additions/x11/VBoxClient/main.cpp b/src/VBox/Additions/x11/VBoxClient/main.cpp index a53ffb096a6..5d3b3e05dae 100644 --- a/src/VBox/Additions/x11/VBoxClient/main.cpp +++ b/src/VBox/Additions/x11/VBoxClient/main.cpp @@ -63,7 +63,8 @@ #define VBOXCLIENT_OPT_VMSVGA VBOXCLIENT_OPT_SERVICES + 4 #define VBOXCLIENT_OPT_VMSVGA_SESSION VBOXCLIENT_OPT_SERVICES + 5 #define VBOXCLIENT_OPT_DISPLAY VBOXCLIENT_OPT_SERVICES + 6 -#define VBOXCLIENT_OPT_SESSION_TYPE VBOXCLIENT_OPT_SERVICES + 7 +#define VBOXCLIENT_OPT_SESSION_DETECT VBOXCLIENT_OPT_SERVICES + 7 +#define VBOXCLIENT_OPT_SESSION_TYPE VBOXCLIENT_OPT_SERVICES + 8 /********************************************************************************************************************************* @@ -326,6 +327,8 @@ static void vboxClientUsage(const char *pcszFileName) RTPrintf(" --display starts VMSVGA dynamic resizing for legacy guests\n"); #endif RTPrintf(" --session-type specifies the session type to use (auto, x11, wayland)\n"); + RTPrintf(" --session-detect detects and prints the current session type\n" + " (exit code 0 if detection succeeded)\n"); RTPrintf(" -f, --foreground run in the foreground (no daemonizing)\n"); RTPrintf(" -d, --nodaemon continues running as a system service\n"); RTPrintf(" -h, --help shows this help text\n"); @@ -533,6 +536,7 @@ int main(int argc, char *argv[]) { "--vmsvga-session", VBOXCLIENT_OPT_VMSVGA_SESSION, RTGETOPT_REQ_NOTHING }, { "--display", VBOXCLIENT_OPT_DISPLAY, RTGETOPT_REQ_NOTHING }, #endif + { "--session-detect", VBOXCLIENT_OPT_SESSION_DETECT, RTGETOPT_REQ_NOTHING }, { "--session-type", VBOXCLIENT_OPT_SESSION_TYPE, RTGETOPT_REQ_STRING } }; @@ -664,6 +668,20 @@ int main(int argc, char *argv[]) break; } #endif + case VBOXCLIENT_OPT_SESSION_DETECT: + { + rc = VBClLogCreateEx("" /* No file logging */, false /* No header */); + if (RT_SUCCESS(rc)) + { + VBGHLogVerbositySet(2); + VBGHDISPLAYSERVERTYPE const enmType = VBGHDisplayServerTypeDetect(); + VBClLogInfo("Detected session: %s\n", VBGHDisplayServerTypeToStr(enmType)); + return enmType != VBGHDISPLAYSERVERTYPE_NONE ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; + } + + return RTEXITCODE_FAILURE; + } + case VBOXCLIENT_OPT_SESSION_TYPE: { if (!RTStrICmp(ValueUnion.psz, "x11")) @@ -719,8 +737,7 @@ int main(int argc, char *argv[]) rc = VBClLogCreate(g_szLogFile[0] ? g_szLogFile : ""); if (RT_FAILURE(rc)) - return RTMsgErrorExitFailure("Failed to create release log '%s', rc=%Rrc\n", - g_szLogFile[0] ? g_szLogFile : "<None>", rc); + return RTEXITCODE_FAILURE; /* Error message already printed in VBClLogCreateEx(). */ if (!fDaemonise) { |