Changeset 68562 in vbox
- Timestamp:
- Aug 31, 2017 12:10:16 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 117779
- Location:
- trunk/src/VBox/Additions/x11/VBoxClient
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/VBoxClient/VBoxClient.h
r67755 r68562 36 36 37 37 /** Call clean-up for the current service and exit. */ 38 extern void VBClCleanUp( );38 extern void VBClCleanUp(bool fExit = true); 39 39 40 40 /** A simple interface describing a service. VBoxClient will run exactly one -
trunk/src/VBox/Additions/x11/VBoxClient/main.cpp
r67755 r68562 1 1 /* $Id$ */ 2 2 /** @file 3 * 4 * VirtualBox Guest Service: 5 * Linux guest. 3 * VirtualBox Guest Additions - X11 Client. 6 4 */ 7 5 … … 66 64 unsigned cRespawn = 0; 67 65 68 /** Exit with a fatal error. */ 66 /** 67 * Exit with a fatal error. 68 * 69 * This is used by the VBClFatalError macro and thus needs to be external. 70 */ 69 71 void vbclFatalError(char *pszMessage) 70 72 { … … 92 94 } 93 95 } 94 _exit(1); 95 } 96 97 /** Clean up if we get a signal or something. This is extern so that we 98 * can call it from other compilation units. */ 99 void VBClCleanUp() 96 _exit(RTEXITCODE_FAILURE); 97 } 98 99 /** 100 * Clean up if we get a signal or something. 101 * 102 * This is extern so that we can call it from other compilation units. 103 */ 104 void VBClCleanUp(bool fExit /*=true*/) 100 105 { 101 106 /* We never release this, as we end up with a call to exit(3) which is not … … 109 114 if (g_szPidFile[0] && g_hPidFile) 110 115 VbglR3ClosePidFile(g_szPidFile, g_hPidFile); 111 exit(0); 116 if (fExit) 117 exit(RTEXITCODE_SUCCESS); 112 118 } 113 119 … … 173 179 * Print out a usage message and exit with success. 174 180 */ 175 void vboxClientUsage(const char *pcszFileName)181 static void vboxClientUsage(const char *pcszFileName) 176 182 { 177 183 RTPrintf("Usage: %s --clipboard|" … … 198 204 RTPrintf(" --seamless starts the seamless windows service\n"); 199 205 RTPrintf(" --vmsvga starts VMSVGA dynamic resizing for DRM or for X11\n"); 206 RTPrintf(" -f, --foreground run in the foreground (no daemonizing)\n"); 200 207 RTPrintf(" -d, --nodaemon continues running as a system service\n"); 201 208 RTPrintf(" -h, --help shows this help text\n"); 202 209 RTPrintf(" -V, --version shows version information\n"); 203 210 RTPrintf("\n"); 204 exit(0); 211 } 212 213 /** 214 * Complains about seeing more than one service specification. 215 * 216 * @returns RTEXITCODE_SYNTAX. 217 */ 218 static int vbclSyntaxOnlyOneService(void) 219 { 220 RTMsgError("More than one service specified! Only one, please."); 221 return RTEXITCODE_SYNTAX; 205 222 } 206 223 … … 211 228 int main(int argc, char *argv[]) 212 229 { 213 bool fDaemonise = true, fRespawn = true;214 int rc;215 const char *pcszFileName;216 217 230 /* Initialise our runtime before all else. */ 218 rc = RTR3InitExe(argc, &argv, 0);231 int rc = RTR3InitExe(argc, &argv, 0); 219 232 if (RT_FAILURE(rc)) 220 233 return RTMsgInitFailure(rc); 234 221 235 /* This should never be called twice in one process - in fact one Display 222 236 * object should probably never be used from multiple threads anyway. */ 223 237 if (!XInitThreads()) 224 238 VBClFatalError(("Failed to initialize X11 threads\n")); 225 /* Get our file name for error output. */ 226 pcszFileName = RTPathFilename(argv[0]); 239 240 /* Get our file name for usage info and hints. */ 241 const char *pcszFileName = RTPathFilename(argv[0]); 227 242 if (!pcszFileName) 228 243 pcszFileName = "VBoxClient"; … … 230 245 /* Parse our option(s) */ 231 246 /** @todo Use RTGetOpt() if the arguments become more complex. */ 247 bool fDaemonise = true; 248 bool fRespawn = true; 232 249 for (int i = 1; i < argc; ++i) 233 250 { 234 rc = VERR_INVALID_PARAMETER; 235 if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--nodaemon")) 251 if ( !strcmp(argv[i], "-f") 252 || !strcmp(argv[i], "--foreground") 253 || !strcmp(argv[i], "-d") 254 || !strcmp(argv[i], "--nodaemon")) 236 255 { 237 256 /* If the user is running in "no daemon" mode anyway, send critical 238 257 * logging to stdout as well. */ 258 /** @todo r=bird: Since the release logger isn't created until the service 259 * calls VbglR3InitUser or VbglR3Init or RTLogCreate, this whole 260 * exercise is pointless. Added --init-vbgl-user and --init-vbgl-full 261 * for getting some work done. */ 239 262 PRTLOGGER pReleaseLog = RTLogRelGetDefaultInstance(); 240 263 if (pReleaseLog) 241 264 rc = RTLogDestinations(pReleaseLog, "stdout"); 242 265 if (pReleaseLog && RT_FAILURE(rc)) 243 RTPrintf("%s: failed to redivert error output, rc=%Rrc\n",244 pcszFileName, rc); 266 return RTMsgErrorExitFailure("failed to redivert error output, rc=%Rrc", rc); 267 245 268 fDaemonise = false; 269 if ( !strcmp(argv[i], "-f") 270 || !strcmp(argv[i], "--foreground")) 271 fRespawn = false; 246 272 } 247 273 else if (!strcmp(argv[i], "--no-respawn")) … … 252 278 { 253 279 if (g_pService) 254 break;280 return vbclSyntaxOnlyOneService(); 255 281 g_pService = VBClGetClipboardService(); 256 282 } … … 258 284 { 259 285 if (g_pService) 260 break;286 return vbclSyntaxOnlyOneService(); 261 287 g_pService = VBClGetDisplayService(); 262 288 } … … 264 290 { 265 291 if (g_pService) 266 break;292 return vbclSyntaxOnlyOneService(); 267 293 g_pService = VBClGetSeamlessService(); 268 294 } … … 270 296 { 271 297 if (g_pService) 272 break;298 return vbclSyntaxOnlyOneService(); 273 299 g_pService = VBClGetHostVersionService(); 274 300 } … … 277 303 { 278 304 if (g_pService) 279 break;305 return vbclSyntaxOnlyOneService(); 280 306 g_pService = VBClGetDragAndDropService(); 281 307 } … … 284 310 { 285 311 if (g_pService) 286 break;312 return vbclSyntaxOnlyOneService(); 287 313 g_pService = VBClCheck3DService(); 288 314 } … … 290 316 { 291 317 if (g_pService) 292 break;318 return vbclSyntaxOnlyOneService(); 293 319 g_pService = VBClDisplaySVGAService(); 320 } 321 /* bird: this is just a quick hack to get something out of the LogRel statements in the code. */ 322 else if (!strcmp(argv[i], "--init-vbgl-user")) 323 { 324 rc = VbglR3InitUser(); 325 if (RT_FAILURE(rc)) 326 return RTMsgErrorExitFailure("VbglR3InitUser failed: %Rrc", rc); 327 } 328 else if (!strcmp(argv[i], "--init-vbgl-full")) 329 { 330 rc = VbglR3Init(); 331 if (RT_FAILURE(rc)) 332 return RTMsgErrorExitFailure("VbglR3Init failed: %Rrc", rc); 294 333 } 295 334 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) … … 305 344 else 306 345 { 307 RT Printf("%s: unrecognized option `%s'\n", pcszFileName, argv[i]);308 RT Printf("Try `%s --help' for more information\n", pcszFileName);346 RTMsgError("unrecognized option `%s'", argv[i]); 347 RTMsgInfo("Try `%s --help' for more information", pcszFileName); 309 348 return RTEXITCODE_SYNTAX; 310 349 } 311 rc = VINF_SUCCESS; 312 } 313 if (RT_FAILURE(rc) || !g_pService) 314 { 315 vboxClientUsage(pcszFileName); 350 } 351 if (!g_pService) 352 { 353 RTMsgError("No service specified. Quitting because nothing to do!"); 316 354 return RTEXITCODE_SYNTAX; 317 355 } … … 363 401 LogRel2(("Initializing service failed: %Rrc\n", rc)); 364 402 } 365 VBClCleanUp( );403 VBClCleanUp(false /*fExit*/); 366 404 return RTEXITCODE_SUCCESS; 367 405 }
Note:
See TracChangeset
for help on using the changeset viewer.