Skip to content

Commit

Permalink
Merge pull request #5842 from computezrmle/Remove-unused-launch_vboxvm()
Browse files Browse the repository at this point in the history
Remove unused launch_vboxvm()
  • Loading branch information
AenBleidd authored Oct 9, 2024
2 parents f27cc8e + 5223dc8 commit dca4153
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 176 deletions.
175 changes: 0 additions & 175 deletions samples/vboxwrapper/vbox_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,181 +892,6 @@ int VBOX_BASE::launch_vboxsvc() {
return retval;
}

// Launch the VM.
int VBOX_BASE::launch_vboxvm() {
char cmdline[1024];
char* argv[5];
int argc;
string output;
int retval = ERR_EXEC;

// Construct the command line parameters
//
if (headless) {
argv[0] = const_cast<char*>("VboxHeadless.exe");
} else {
argv[0] = const_cast<char*>("VirtualBox.exe");
}
argv[1] = const_cast<char*>("--startvm");
argv[2] = const_cast<char*>(vm_name.c_str());
if (headless) {
argv[3] = const_cast<char*>("--vrde config");
} else {
argv[3] = const_cast<char*>("--no-startvm-errormsgbox");
}
argv[4] = NULL;
argc = 4;

strcpy(cmdline, "");
for (int i=0; i<argc; i++) {
strcat(cmdline, argv[i]);
if (i<argc-1) {
strcat(cmdline, " ");
}
}

#ifdef _WIN32
char buf[256];
STARTUPINFO si;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
HANDLE hReadPipe = NULL, hWritePipe = NULL;
void* pBuf = NULL;
DWORD dwCount = 0;
unsigned long ulExitCode = 0;
unsigned long ulExitTimeout = 0;

memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
memset(&sa, 0, sizeof(sa));
memset(&sd, 0, sizeof(sd));

InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, true, NULL, false);

sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = &sd;

if (!CreatePipe(&hReadPipe, &hWritePipe, &sa, NULL)) {
vboxlog_msg("CreatePipe failed (%d).", GetLastError());
goto CLEANUP;
}
SetHandleInformation(hReadPipe, HANDLE_FLAG_INHERIT, 0);

si.cb = sizeof(STARTUPINFO);
si.dwFlags |= STARTF_FORCEOFFFEEDBACK | STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
si.hStdOutput = hWritePipe;
si.hStdError = hWritePipe;
si.hStdInput = NULL;

// Execute command
if (!CreateProcess(
NULL,
cmdline,
NULL,
NULL,
TRUE,
CREATE_NO_WINDOW,
NULL,
NULL,
&si,
&pi
)) {

vboxlog_msg(
"Status Report: Launching virtualbox.exe/vboxheadless.exe failed."
);
vboxlog_msg(
" Error: %s (%d)",
windows_format_error_string(GetLastError(), buf, sizeof(buf)),
GetLastError()
);
goto CLEANUP;
}

while(1) {
GetExitCodeProcess(pi.hProcess, &ulExitCode);

// Copy stdout/stderr to output buffer,
// Handle in the loop so that we can
// copy the pipe as it is populated
// and prevent the child process from blocking
// in case the output is bigger than pipe buffer.
PeekNamedPipe(hReadPipe, NULL, NULL, NULL, &dwCount, NULL);
if (dwCount) {
pBuf = malloc(dwCount+1);
memset(pBuf, 0, dwCount+1);

if (ReadFile(hReadPipe, pBuf, dwCount, &dwCount, NULL)) {
output += (char*)pBuf;
}

free(pBuf);
}

if ((ulExitCode != STILL_ACTIVE) || (ulExitTimeout >= 1000)) break;

Sleep(250);
ulExitTimeout += 250;
}

if (ulExitCode != STILL_ACTIVE) {
sanitize_output(output);
vboxlog_msg(
"Status Report: Virtualbox.exe/Vboxheadless.exe exited prematurely."
);
vboxlog_msg(
" Exit Code: %d",
ulExitCode
);
vboxlog_msg(
" Output: %s",
output.c_str()
);
}

if (pi.hProcess && (ulExitCode == STILL_ACTIVE)) {
vm_pid = pi.dwProcessId;
vm_pid_handle = pi.hProcess;
retval = BOINC_SUCCESS;
}

CLEANUP:
if (pi.hThread) CloseHandle(pi.hThread);
if (hReadPipe) CloseHandle(hReadPipe);
if (hWritePipe) CloseHandle(hWritePipe);

#else
int pid = fork();
if (-1 == pid) {
vboxlog_msg(
"Status Report: Launching virtualbox/vboxheadless failed."
);
vboxlog_msg(
" Error: %s (%d)",
strerror(errno),
errno
);
retval = ERR_FORK;
} else if (0 == pid) {
if (-1 == execv(argv[0], argv)) {
_exit(errno);
}
} else {
vm_pid = pid;
retval = BOINC_SUCCESS;
}
#endif

string cmd_line = cmdline;
vbm_trace(cmd_line, output, retval);

return retval;
}

// If there are errors we can recover from, process them here.
//
int VBOX_BASE::vbm_popen(string& command, string& output, const char* item, bool log_error, bool retry_failures, unsigned int timeout, bool log_trace) {
Expand Down
1 change: 0 additions & 1 deletion samples/vboxwrapper/vbox_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ struct VBOX_BASE : VBOX_JOB {
static void sanitize_output(string& output);

int launch_vboxsvc();
int launch_vboxvm();

int vbm_popen(
string& command, string& output, const char* item,
Expand Down

0 comments on commit dca4153

Please sign in to comment.