Changeset 102047 in vbox for trunk/src/libs/xpcom18a4/ipc/ipcd/daemon/src/ipcdUnix.cpp
- Timestamp:
- Nov 9, 2023 6:27:01 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/ipc/ipcd/daemon/src/ipcdUnix.cpp
r101982 r102047 50 50 #endif 51 51 52 #i fdef VBOX53 # include <iprt/initterm.h>54 # endif52 #include <iprt/initterm.h> 53 #include <iprt/getopt.h> 54 #include <iprt/message.h> 55 55 56 56 #include "prio.h" … … 458 458 PRNetAddr addr; 459 459 460 #ifdef VBOX461 460 /* Set up the runtime without loading the support driver. */ 462 RTR3InitExe(argc, &argv, 0); 463 #endif 461 int vrc = RTR3InitExe(argc, &argv, 0); 462 if (RT_FAILURE(vrc)) 463 return RTMsgInitFailure(vrc); 464 465 /* 466 * Parse the command line. 467 */ 468 static RTGETOPTDEF const s_aOptions[] = 469 { 470 { "--inherit-startup-pipe", 'f', RTGETOPT_REQ_UINT32 }, 471 { "--socket-path", 'p', RTGETOPT_REQ_STRING }, 472 }; 473 474 RTGETOPTSTATE State; 475 vrc = RTGetOptInit(&State, argc, argv, &s_aOptions[0], RT_ELEMENTS(s_aOptions), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST); 476 if (RT_FAILURE(vrc)) 477 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTGetOptInit failed: %Rrc", vrc); 478 479 uint32_t uStartupPipeFd = UINT32_MAX; 480 const char *pszSocketPath = NULL; 481 RTGETOPTUNION ValueUnion; 482 int chOpt; 483 while ((chOpt = RTGetOpt(&State, &ValueUnion)) != 0) 484 { 485 switch (chOpt) 486 { 487 case 'f': 488 uStartupPipeFd = ValueUnion.u32; 489 break; 490 case 'p': 491 pszSocketPath = ValueUnion.psz; 492 break; 493 default: 494 return RTGetOptPrintError(chOpt, &ValueUnion); 495 } 496 } 464 497 465 498 // … … 482 515 // set socket address 483 516 addr.local.family = PR_AF_LOCAL; 484 if ( argc < 2)517 if (!pszSocketPath) 485 518 IPC_GetDefaultSocketPath(addr.local.path, sizeof(addr.local.path)); 486 519 else 487 PL_strncpyz(addr.local.path, argv[1], sizeof(addr.local.path));520 PL_strncpyz(addr.local.path, pszSocketPath, sizeof(addr.local.path)); 488 521 489 522 #ifdef IPC_USE_FILE_LOCK … … 493 526 LOG(("Another daemon is already running, exiting.\n")); 494 527 // send a signal to the blocked parent to indicate success 495 IPC_NotifyParent( );528 IPC_NotifyParent(uStartupPipeFd); 496 529 return 0; 497 530 } … … 500 533 // don't notify the parent to cause it to fail in PR_Read() after 501 534 // we terminate 502 #ifdef VBOX503 535 if (status != ELockFileOwner) 504 536 printf("Cannot create a lock file for '%s'.\n" 505 537 "Check permissions.\n", addr.local.path); 506 #endif507 538 return 0; 508 539 } … … 518 549 } 519 550 else { 520 #ifdef VBOX521 551 // Use large backlog, as otherwise local sockets can reject connection 522 552 // attempts. Usually harmless, but causes an unnecessary start attempt … … 524 554 // usually succeeds. But better avoid unnecessary activities. 525 555 if (PR_Listen(listenFD, 128) != PR_SUCCESS) { 526 #else /* !VBOX */527 if (PR_Listen(listenFD, 5) != PR_SUCCESS) {528 #endif /* !VBOX */529 556 LOG(("PR_Listen failed [%d]\n", PR_GetError())); 530 557 } 531 558 else { 532 #ifndef VBOX 533 // redirect all standard file descriptors to /dev/null for 534 // proper daemonizing 535 PR_Close(PR_STDIN); 536 PR_Open("/dev/null", O_RDONLY, 0); 537 PR_Close(PR_STDOUT); 538 PR_Open("/dev/null", O_WRONLY, 0); 539 PR_Close(PR_STDERR); 540 PR_Open("/dev/null", O_WRONLY, 0); 541 #endif 542 543 IPC_NotifyParent(); 559 560 IPC_NotifyParent(uStartupPipeFd); 544 561 545 562 #if defined(VBOX) && !defined(XP_OS2)
Note:
See TracChangeset
for help on using the changeset viewer.