Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylegibson/1275812 to your computer and use it in GitHub Desktop.
Save kylegibson/1275812 to your computer and use it in GitHub Desktop.
Patch file for VirtualBox 4.0.8 to correctly pass start parameters onto spawned daemon process
--- VirtualBox-4.0.8_OSE/src/VBox/Main/src-server/xpcom/server.cpp 2011-05-16 12:33:47.000000000 -0400
+++ VirtualBox-4.0.8_OSE.fix/src/VBox/Main/src-server/xpcom/server.cpp 2011-05-18 18:01:04.784596001 -0400
@@ -712,15 +712,23 @@
}
}
-static nsresult vboxsvcSpawnDaemonByReExec(const char *pszPath)
+static nsresult vboxsvcSpawnDaemonByReExec(const char *pszPath, bool bAutoShutdown, const char *pszPidFile)
{
PRFileDesc *readable = nsnull, *writable = nsnull;
PRProcessAttr *attr = nsnull;
nsresult rv = NS_ERROR_FAILURE;
PRFileDesc *devNull;
+ int args_index = 0;
// The ugly casts are necessary because the PR_CreateProcessDetached has
// a const array of writable strings as a parameter. It won't write. */
- char * const args[] = { (char *)pszPath, (char *)"--auto-shutdown", 0 };
+ char * args[1 + 1 + 2 + 1];
+ args[args_index++] = (char *)pszPath;
+ if (bAutoShutdown) args[args_index++] = (char *)"--auto-shutdown";
+ if (pszPidFile) {
+ args[args_index++] = (char *)"--pidfile";
+ args[args_index++] = (char *)pszPidFile;
+ }
+ args[args_index++] = 0;
// Use a pipe to determine when the daemon process is in the position
// to actually process requests. The daemon will write "READY" to the pipe.
@@ -743,7 +751,7 @@
PR_ProcessAttrSetStdioRedirect(attr, PR_StandardOutput, devNull);
PR_ProcessAttrSetStdioRedirect(attr, PR_StandardError, devNull);
- if (PR_CreateProcessDetached(pszPath, args, nsnull, attr) != PR_SUCCESS)
+ if (PR_CreateProcessDetached(pszPath, (char * const *)args, nsnull, attr) != PR_SUCCESS)
goto end;
// Close /dev/null
@@ -847,7 +855,7 @@
if (fDaemonize)
{
- vboxsvcSpawnDaemonByReExec(argv[0]);
+ vboxsvcSpawnDaemonByReExec(argv[0], gAutoShutdown, g_pszPidFile);
exit(126);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment