Changeset 5688 in vbox for trunk/src/VBox/Main
- Timestamp:
- Nov 11, 2007 5:22:14 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/linux/server.cpp
r5504 r5688 759 759 { "daemonize", no_argument, NULL, 'd' }, 760 760 { "pidfile", required_argument, NULL, 'p' }, 761 #ifdef RT_OS_DARWIN 762 { "pipe", required_argument, NULL, 'P' }, 763 #endif 761 764 { NULL, 0, NULL, 0 } 762 765 }; … … 764 767 765 768 bool fDaemonize = false; 769 #ifndef RT_OS_OS2 770 static int daemon_pipe_fds[2] = {-1, -1}; 771 #endif 766 772 767 773 for (;;) … … 794 800 } 795 801 802 #ifdef RT_OS_DARWIN 803 /* we need to exec on darwin, this is just an internal 804 * hack for passing the pipe fd along to the final child. */ 805 case 'P': 806 { 807 daemon_pipe_fds[1] = atoi(optarg); 808 break; 809 } 810 #endif 811 796 812 default: 797 813 { … … 811 827 812 828 #else // ifdef RT_OS_OS2 813 814 static int daemon_pipe_fds[2];815 829 816 830 if (fDaemonize) … … 882 896 883 897 /* Redirect standard i/o streams to /dev/null */ 884 freopen ("/dev/null", "r", stdin); 885 freopen ("/dev/null", "w", stdout); 886 freopen ("/dev/null", "w", stderr); 898 if (daemon_pipe_fds[0] > 2) 899 { 900 freopen ("/dev/null", "r", stdin); 901 freopen ("/dev/null", "w", stdout); 902 freopen ("/dev/null", "w", stderr); 903 } 887 904 888 905 /* close the reading end of the pipe */ 889 906 close(daemon_pipe_fds[0]); 907 908 # ifdef RT_OS_DARWIN 909 /* 910 * On leopard we're no longer allowed to use some of the core API's 911 * after forking - this will cause us to hit an int3. 912 * So, we'll have to execv VBoxSVC once again and hand it the pipe. 913 */ 914 const char *apszArgs[6]; 915 apszArgs[0] = argv[0]; 916 apszArgs[1] = "--pipe"; 917 char szPipeArg[32]; 918 RTStrPrintf(szPipeArg, sizeof(szPipeArg), "%d", daemon_pipe_fds[1]); 919 apszArgs[2] = szPipeArg; 920 if (pszPidFile) 921 { 922 apszArgs[3] = "--pidfile"; 923 apszArgs[4] = pszPidFile; 924 apszArgs[5] = NULL; 925 } 926 else 927 apszArgs[3] = NULL; 928 execv(apszArgs[0], (char * const *)apszArgs); 929 exit(0); 930 # endif 890 931 } 891 932 … … 1003 1044 } 1004 1045 1005 if ( fDaemonize)1046 if (daemon_pipe_fds[1] >= 0) 1006 1047 { 1007 1048 printf ("\nStarting event loop....\n[send TERM signal to quit]\n"); … … 1065 1106 } 1066 1107 1067 if (fDaemonize)1068 {1069 1108 #ifndef RT_OS_OS2 1109 if (daemon_pipe_fds[1] >= 0) 1110 { 1070 1111 /* close writing end of the pipe as well */ 1071 1112 close(daemon_pipe_fds[1]); 1072 #endif 1073 } 1113 } 1114 #endif 1074 1115 1075 1116 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.