Changeset 98474 in vbox for trunk/src/VBox/Additions/x11/VBoxClient/display-svga-session.cpp
- Timestamp:
- Feb 3, 2023 7:20:53 PM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/VBoxClient/display-svga-session.cpp
r98103 r98474 46 46 * 47 47 * Multiple instances of this daemon are allowed to run in parallel 48 * with the following limitations (see also vbclSVGASessionPidFileLock()).48 * with the following limitations. 49 49 * A single user cannot run multiple daemon instances per single TTY device, 50 50 * however, multiple instances are allowed for the user on different … … 67 67 #include <iprt/linux/sysfs.h> 68 68 69 /** Lock file handle. */70 static RTFILE g_hPidFile;71 /** Full path to PID lock file. */72 static char g_szPidFilePath[RTPATH_MAX];73 69 74 70 /** Handle to IPC client connection. */ … … 117 113 118 114 /** 119 * Prevent multiple instances of the service from start.120 *121 * @returns IPRT status code.122 */123 static int vbclSVGASessionPidFileLock(void)124 {125 int rc;126 127 /* Allow parallel running instances of the service for processes128 * which are running in separate X11/Wayland sessions. Compose129 * custom PID file name based on currently active TTY device. */130 131 char *pszPidFileName = RTStrAlloc(RTPATH_MAX);132 if (pszPidFileName)133 {134 rc = RTPathUserHome(g_szPidFilePath, sizeof(g_szPidFilePath));135 if (RT_SUCCESS(rc))136 {137 char pszActiveTTY[128];138 size_t cchRead;139 140 RT_ZERO(pszActiveTTY);141 142 RTStrAAppend(&pszPidFileName, ".vboxclient-vmsvga-session");143 144 rc = RTLinuxSysFsReadStrFile(pszActiveTTY, sizeof(pszActiveTTY) - 1 /* reserve last byte for string termination */,145 &cchRead, "class/tty/tty0/active");146 if (RT_SUCCESS(rc))147 {148 RTStrAAppend(&pszPidFileName, "-");149 RTStrAAppend(&pszPidFileName, pszActiveTTY);150 }151 else152 VBClLogInfo("cannot detect currently active tty device, "153 "multiple service instances for a single user will not be allowed, rc=%Rrc", rc);154 155 RTStrAAppend(&pszPidFileName, ".pid");156 157 RTPathAppend(g_szPidFilePath, sizeof(g_szPidFilePath), pszPidFileName);158 159 VBClLogVerbose(1, "lock file path: %s\n", g_szPidFilePath);160 rc = VbglR3PidFile(g_szPidFilePath, &g_hPidFile);161 }162 else163 VBClLogError("unable to get user home directory, rc=%Rrc\n", rc);164 165 RTStrFree(pszPidFileName);166 }167 else168 rc = VERR_NO_MEMORY;169 170 return rc;171 }172 173 /**174 * Release lock file.175 */176 static void vbclSVGASessionPidFileRelease(void)177 {178 VbglR3ClosePidFile(g_szPidFilePath, g_hPidFile);179 }180 181 /**182 115 * @interface_method_impl{VBCLSERVICE,pfnInit} 183 116 */ … … 192 125 193 126 VBClLogSetLogPrefix(pszLogPrefix); 194 195 rc = vbclSVGASessionPidFileLock();196 if (RT_FAILURE(rc))197 {198 VBClLogVerbose(1, "cannot acquire pid lock, rc=%Rrc\n", rc);199 return rc;200 }201 127 202 128 rc = RTCritSectInit(&g_hClientCritSect); … … 517 443 } 518 444 519 vbclSVGASessionPidFileRelease();520 521 445 return VINF_SUCCESS; 522 446 } … … 526 450 "vmsvga-session", /* szName */ 527 451 "VMSVGA display assistant", /* pszDescription */ 528 NULL, /* pszPidFilePath (no pid file lock)*/452 ".vboxclient-vmsvga-session", /* pszPidFilePathTemplate */ 529 453 NULL, /* pszUsage */ 530 454 NULL, /* pszOptions */
Note:
See TracChangeset
for help on using the changeset viewer.