Changeset 99585 in vbox
- Timestamp:
- May 3, 2023 3:12:56 PM (19 months ago)
- Location:
- trunk/src/VBox/Additions/x11/VBoxClient
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/VBoxClient/Makefile.kmk
r99565 r99585 48 48 # 49 49 PROGRAMS.linux += VBoxDRMClient 50 51 # Common Guest / Host sources. 52 VBOX_GH_SOURCES := \ 53 $(PATH_ROOT)/src/VBox/GuestHost/Log.cpp \ 54 $(PATH_ROOT)/src/VBox/GuestHost/SessionType.cpp 50 55 51 56 VBoxClient_TEMPLATE = VBoxGuestR3Exe … … 68 73 main.cpp \ 69 74 logging.cpp 75 VBoxClient_SOURCES += $(VBOX_GH_SOURCES) 70 76 71 77 VBoxDRMClient_TEMPLATE = VBoxGuestR3Exe … … 79 85 display-ipc.cpp \ 80 86 logging.cpp 81 87 VBoxDRMClient_SOURCES += $(VBOX_GH_SOURCES) 82 88 83 89 VBoxClient_SOURCES.linux = \ -
trunk/src/VBox/Additions/x11/VBoxClient/VBoxClient.h
r98474 r99585 37 37 #include <iprt/string.h> 38 38 39 /** Environment variable which is exported when in Wayland Desktop Environment. */ 40 #define VBCL_ENV_WAYLAND_DISPLAY "WAYLAND_DISPLAY" 41 /** Environment variable which contains information about currently running Desktop Environment. */ 42 #define VBCL_ENV_XDG_CURRENT_DESKTOP "XDG_CURRENT_DESKTOP" 43 /** Environment variable which contains information about currently running session (X11, Wayland, etc). */ 44 #define VBCL_ENV_XDG_SESSION_TYPE "XDG_SESSION_TYPE" 39 #include <VBox/GuestHost/Log.h> 40 #include <VBox/GuestHost/SessionType.h> 45 41 46 42 int VBClShowNotify(const char *pszHeader, const char *pszBody); … … 55 51 void VBClLogDestroy(void); 56 52 57 /**58 * Detect if user is running on Wayland by checking corresponding environment variable.59 *60 * @returns True if Wayland has been detected, False otherwise.61 */62 extern bool VBClHasWayland(void);63 64 53 /** Call clean-up for the current service and exit. */ 65 54 extern void VBClShutdown(bool fExit = true); 55 56 extern VBGHSESSIONTYPE VBClGetSessionType(void); 66 57 67 58 /** -
trunk/src/VBox/Additions/x11/VBoxClient/display-helper-gnome3.cpp
r98103 r99585 964 964 static DECLCALLBACK(int) vbcl_hlp_gnome3_probe(void) 965 965 { 966 const char *pszCurrentDesktop = RTEnvGet(VB CL_ENV_XDG_CURRENT_DESKTOP);966 const char *pszCurrentDesktop = RTEnvGet(VBGH_ENV_XDG_CURRENT_DESKTOP); 967 967 968 968 /* GNOME3 identifies itself by XDG_CURRENT_DESKTOP environment variable. … … 982 982 int rc; 983 983 984 if ( !VBClHasWayland())984 if (VBClGetSessionType() == VBGHSESSIONTYPE_X11) 985 985 { 986 986 rc = vbcl_hlp_generic_init(); … … 998 998 int rc; 999 999 1000 if ( !VBClHasWayland())1000 if (VBClGetSessionType() == VBGHSESSIONTYPE_X11) 1001 1001 { 1002 1002 rc = vbcl_hlp_generic_term(); -
trunk/src/VBox/Additions/x11/VBoxClient/display-svga-x11.cpp
r98474 r99585 581 581 } 582 582 583 if (VBCl HasWayland())583 if (VBClGetSessionType() == VBGHSESSIONTYPE_WAYLAND) 584 584 { 585 585 rc = VbglR3DrmClientStart(); -
trunk/src/VBox/Additions/x11/VBoxClient/logging.cpp
r98103 r99585 40 40 #endif 41 41 #include <VBox/VBoxGuestLib.h> 42 43 #include <VBox/GuestHost/Log.h> 42 44 43 45 #include <package-generated.h> … … 219 221 } 220 222 221 222 223 /**224 * Logs a verbose message.225 *226 * @param pszFormat The message text.227 * @param va Format arguments.228 */229 static void vbClLogV(const char *pszFormat, va_list va)230 {231 char *psz = NULL;232 RTStrAPrintfV(&psz, pszFormat, va);233 AssertPtrReturnVoid(psz);234 LogRel(("%s", psz));235 RTStrFree(psz);236 }237 238 223 /** 239 224 * Logs a fatal error, notifies the desktop environment via a message and … … 245 230 void VBClLogFatalError(const char *pszFormat, ...) 246 231 { 247 va_list args; 248 va_start(args, pszFormat); 249 char *psz = NULL; 250 RTStrAPrintfV(&psz, pszFormat, args); 251 va_end(args); 252 253 AssertPtrReturnVoid(psz); 254 LogFunc(("Fatal Error: %s", psz)); 255 LogRel(("Fatal Error: %s", psz)); 256 257 VBClShowNotify("VBoxClient - Fatal Error", psz); 258 259 RTStrFree(psz); 232 va_list va; 233 va_start(va, pszFormat); 234 VBGHLogFatalErrorV(pszFormat, va); 235 va_end(va); 260 236 } 261 237 … … 267 243 void VBClLogError(const char *pszFormat, ...) 268 244 { 269 va_list args; 270 va_start(args, pszFormat); 271 char *psz = NULL; 272 RTStrAPrintfV(&psz, pszFormat, args); 273 va_end(args); 274 275 AssertPtrReturnVoid(psz); 276 LogFunc(("Error: %s", psz)); 277 LogRel(("Error: %s", psz)); 278 279 RTStrFree(psz); 245 va_list va; 246 va_start(va, pszFormat); 247 VBGHLogErrorV(pszFormat, va); 248 va_end(va); 280 249 } 281 250 … … 287 256 void VBClLogInfo(const char *pszFormat, ...) 288 257 { 289 va_list args;290 va_start( args, pszFormat);291 vbClLogV(pszFormat, args);292 va_end( args);258 va_list va; 259 va_start(va, pszFormat); 260 VBGHLogInfoV(pszFormat, va); 261 va_end(va); 293 262 } 294 263 … … 303 272 void VBClLogVerbose(unsigned iLevel, const char *pszFormat, ...) 304 273 { 305 if (iLevel <= g_cVerbosity) 306 { 307 va_list va; 308 va_start(va, pszFormat); 309 vbClLogV(pszFormat, va); 310 va_end(va); 311 } 274 va_list va; 275 va_start(va, pszFormat); 276 VBGHLogVerboseV(iLevel, pszFormat, va); 277 va_end(va); 312 278 } 313 279 -
trunk/src/VBox/Additions/x11/VBoxClient/main.cpp
r98474 r99585 64 64 #define VBOXCLIENT_OPT_VMSVGA_SESSION VBOXCLIENT_OPT_SERVICES + 5 65 65 #define VBOXCLIENT_OPT_DISPLAY VBOXCLIENT_OPT_SERVICES + 6 66 #define VBOXCLIENT_OPT_SESSION_TYPE VBOXCLIENT_OPT_SERVICES + 7 66 67 67 68 … … 95 96 *********************************************************************************************************************************/ 96 97 /** The global service state. */ 97 VBCLSERVICESTATE g_Service = { 0 };98 VBCLSERVICESTATE g_Service = { 0 }; 98 99 99 100 /** Set by the signal handler when being called. */ 100 static volatile bool g_fSignalHandlerCalled = false;101 static volatile bool g_fSignalHandlerCalled = false; 101 102 /** Critical section for the signal handler. */ 102 static RTCRITSECT g_csSignalHandler;103 static RTCRITSECT g_csSignalHandler; 103 104 /** Flag indicating Whether the service starts in daemonized mode or not. */ 104 bool g_fDaemonized = false;105 bool g_fDaemonized = false; 105 106 /** The name of our pidfile. It is global for the benefit of the cleanup 106 107 * routine. */ 107 static char g_szPidFile[RTPATH_MAX] = "";108 static char g_szPidFile[RTPATH_MAX] = ""; 108 109 /** The file handle of our pidfile. It is global for the benefit of the 109 110 * cleanup routine. */ 110 static RTFILE g_hPidFile;111 static RTFILE g_hPidFile; 111 112 /** The name of pidfile for parent (control) process. */ 112 static char g_szControlPidFile[RTPATH_MAX] = "";113 static char g_szControlPidFile[RTPATH_MAX] = ""; 113 114 /** The file handle of parent process pidfile. */ 114 static RTFILE g_hControlPidFile; 115 static RTFILE g_hControlPidFile; 116 /** The session type to use. */ 117 static VBGHSESSIONTYPE g_enmSessionType = VBGHSESSIONTYPE_AUTO; 115 118 116 119 /** Global critical section held during the clean-up routine (to prevent it … … 128 131 static volatile bool g_fProcessReloadRequested = false; 129 132 130 /**131 * Tries to determine if the session parenting this process is of Xwayland.132 * NB: XDG_SESSION_TYPE is a systemd(1) environment variable and is unlikely133 * set in non-systemd environments or remote logins.134 * Therefore we check the Wayland specific display environment variable first.135 */136 bool VBClHasWayland(void)137 {138 const char *const pDisplayType = RTEnvGet(VBCL_ENV_WAYLAND_DISPLAY);139 const char *pSessionType;140 141 if (pDisplayType != NULL)142 return true;143 144 pSessionType = RTEnvGet(VBCL_ENV_XDG_SESSION_TYPE);145 if ((pSessionType != NULL) && (RTStrIStartsWith(pSessionType, "wayland")))146 return true;147 148 return false;149 }150 133 151 134 /** … … 182 165 183 166 /** 167 * Returns the current session type. 168 * 169 * @returns The session type. 170 */ 171 VBGHSESSIONTYPE VBClGetSessionType(void) 172 { 173 return g_enmSessionType; 174 } 175 176 /** 184 177 * Xlib error handler for certain errors that we can't avoid. 185 178 */ … … 189 182 190 183 XGetErrorText(pDisplay, pError->error_code, errorText, sizeof(errorText)); 191 VBClLogError("An X Window protocol error occurred: %s (error code %d). Request code: %d, minor code: %d, serial number: %d\n", errorText, pError->error_code, pError->request_code, pError->minor_code, pError->serial); 184 VBClLogError("An X Window protocol error occurred: %s (error code %d). Request code: %d, minor code: %d, serial number: %d\n", 185 errorText, pError->error_code, pError->request_code, pError->minor_code, pError->serial); 192 186 return 0; 193 187 } … … 332 326 RTPrintf(" --display starts VMSVGA dynamic resizing for legacy guests\n"); 333 327 #endif 328 RTPrintf(" --session-type specifies the session type to use (auto, x11, wayland)\n"); 334 329 RTPrintf(" -f, --foreground run in the foreground (no daemonizing)\n"); 335 330 RTPrintf(" -d, --nodaemon continues running as a system service\n"); … … 506 501 bool fUpdateStarted = false; 507 502 508 /* This should never be called twice in one process - in fact one Display509 * object should probably never be used from multiple threads anyway. */510 if (!XInitThreads())511 return RTMsgErrorExitFailure("Failed to initialize X11 threads\n");512 513 503 /* Get our file name for usage info and hints. */ 514 504 const char *pcszFileName = RTPathFilename(argv[0]); … … 519 509 static const RTGETOPTDEF s_aOptions[] = 520 510 { 521 { "--nodaemon", 'd', 522 { "--foreground", 'f', 523 { "--help", 'h', 524 { "--logfile", 'l', 525 { "--version", 'V', 526 { "--verbose", 'v', 511 { "--nodaemon", 'd', RTGETOPT_REQ_NOTHING }, 512 { "--foreground", 'f', RTGETOPT_REQ_NOTHING }, 513 { "--help", 'h', RTGETOPT_REQ_NOTHING }, 514 { "--logfile", 'l', RTGETOPT_REQ_STRING }, 515 { "--version", 'V', RTGETOPT_REQ_NOTHING }, 516 { "--verbose", 'v', RTGETOPT_REQ_NOTHING }, 527 517 528 518 /* Services */ 529 519 #ifdef VBOX_WITH_GUEST_PROPS 530 { "--checkhostversion", VBOXCLIENT_OPT_CHECKHOSTVERSION, 520 { "--checkhostversion", VBOXCLIENT_OPT_CHECKHOSTVERSION, RTGETOPT_REQ_NOTHING }, 531 521 #endif 532 522 #ifdef VBOX_WITH_SHARED_CLIPBOARD 533 { "--clipboard", VBOXCLIENT_OPT_CLIPBOARD, 523 { "--clipboard", VBOXCLIENT_OPT_CLIPBOARD, RTGETOPT_REQ_NOTHING }, 534 524 #endif 535 525 #ifdef VBOX_WITH_DRAG_AND_DROP 536 { "--draganddrop", VBOXCLIENT_OPT_DRAGANDDROP, 526 { "--draganddrop", VBOXCLIENT_OPT_DRAGANDDROP, RTGETOPT_REQ_NOTHING }, 537 527 #endif 538 528 #ifdef VBOX_WITH_SEAMLESS 539 { "--seamless", VBOXCLIENT_OPT_SEAMLESS, 529 { "--seamless", VBOXCLIENT_OPT_SEAMLESS, RTGETOPT_REQ_NOTHING }, 540 530 #endif 541 531 #ifdef VBOX_WITH_VMSVGA 542 { "--vmsvga", VBOXCLIENT_OPT_VMSVGA, RTGETOPT_REQ_NOTHING }, 543 { "--vmsvga-session", VBOXCLIENT_OPT_VMSVGA_SESSION, RTGETOPT_REQ_NOTHING }, 544 { "--display", VBOXCLIENT_OPT_DISPLAY, RTGETOPT_REQ_NOTHING }, 545 #endif 532 { "--vmsvga", VBOXCLIENT_OPT_VMSVGA, RTGETOPT_REQ_NOTHING }, 533 { "--vmsvga-session", VBOXCLIENT_OPT_VMSVGA_SESSION, RTGETOPT_REQ_NOTHING }, 534 { "--display", VBOXCLIENT_OPT_DISPLAY, RTGETOPT_REQ_NOTHING }, 535 #endif 536 { "--session-type", VBOXCLIENT_OPT_SESSION_TYPE, RTGETOPT_REQ_STRING } 546 537 }; 547 538 … … 674 665 } 675 666 #endif 667 case VBOXCLIENT_OPT_SESSION_TYPE: 668 { 669 if (!RTStrICmp(ValueUnion.psz, "x11")) 670 g_enmSessionType = VBGHSESSIONTYPE_X11; 671 else if (!RTStrICmp(ValueUnion.psz, "wayland")) 672 g_enmSessionType = VBGHSESSIONTYPE_WAYLAND; 673 else if (!RTStrICmp(ValueUnion.psz, "none")) 674 g_enmSessionType = VBGHSESSIONTYPE_NONE; 675 else if (!RTStrICmp(ValueUnion.psz, "auto")) 676 g_enmSessionType = VBGHSESSIONTYPE_AUTO; 677 else 678 { 679 RTMsgError("Session type \"%s\" is invalid; defaulting to \"auto\" instead.\n", ValueUnion.psz); 680 g_enmSessionType = VBGHSESSIONTYPE_AUTO; 681 } 682 break; 683 } 684 676 685 case VINF_GETOPT_NOT_OPTION: 677 686 break; … … 726 735 } 727 736 728 VBClLogInfo("VBoxClient %s r%s started. Verbose level = %d. Wayland environment detected: %s\n", 729 RTBldCfgVersion(), RTBldCfgRevisionStr(), g_cVerbosity, VBClHasWayland() ? "yes" : "no"); 737 VBClLogInfo("VBoxClient %s r%s started. Verbose level = %d\n", 738 RTBldCfgVersion(), RTBldCfgRevisionStr(), g_cVerbosity); 739 740 /* Try to detect the current session type early on, if needed. */ 741 if (g_enmSessionType == VBGHSESSIONTYPE_AUTO) 742 { 743 g_enmSessionType = VBGHSessionTypeDetect(); 744 } 745 else 746 VBClLogInfo("Session type was manually set to: %s\n", VBGHSessionTypeToStr(g_enmSessionType)); 747 748 VBClLogInfo("Session type is: %s\n", VBGHSessionTypeToStr(g_enmSessionType)); 749 730 750 VBClLogInfo("Service: %s\n", g_Service.pDesc->pszDesc); 731 751 … … 774 794 } 775 795 776 #ifndef VBOXCLIENT_WITHOUT_X11 777 /* Set an X11 error handler, so that we don't die when we get unavoidable 778 * errors. */ 779 XSetErrorHandler(vboxClientXLibErrorHandler); 780 /* Set an X11 I/O error handler, so that we can shutdown properly on 781 * fatal errors. */ 782 XSetIOErrorHandler(vboxClientXLibIOErrorHandler); 783 #endif 796 if (g_enmSessionType == VBGHSESSIONTYPE_X11) 797 { 798 /* This should never be called twice in one process - in fact one Display 799 * object should probably never be used from multiple threads anyway. */ 800 if (!XInitThreads()) 801 return RTMsgErrorExitFailure("Failed to initialize X11 threads\n"); 802 /* Set an X11 error handler, so that we don't die when we get unavoidable 803 * errors. */ 804 XSetErrorHandler(vboxClientXLibErrorHandler); 805 /* Set an X11 I/O error handler, so that we can shutdown properly on 806 * fatal errors. */ 807 XSetIOErrorHandler(vboxClientXLibIOErrorHandler); 808 } 784 809 785 810 bool fSignalHandlerInstalled = false;
Note:
See TracChangeset
for help on using the changeset viewer.