VBoxServiceControl.cpp revision b47f1bf67de12aaf4f0827597196f26a5539c34b
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * VBoxServiceControl - Host-driven Guest Control.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Copyright (C) 2011 Oracle Corporation
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * available from http://www.virtualbox.org. This file is free software;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * you can redistribute it and/or modify it under the terms of the GNU
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * General Public License (GPL) as published by the Free Software
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/*******************************************************************************
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync* Header Files *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync*******************************************************************************/
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncusing namespace guestControl;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/*******************************************************************************
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync* Global Variables *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync*******************************************************************************/
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The control interval (milliseconds). */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The semaphore we're blocking our main control thread on. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTSEMEVENTMULTI g_hControlEvent = NIL_RTSEMEVENTMULTI;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The guest control service client ID. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** How many started guest processes are kept into memory for supplying
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * information to the host. Default is 25 processes. If 0 is specified,
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * the maximum number of processes is unlimited. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** List of guest control threads. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** Critical section protecting g_GuestControlExecThreads. */
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsyncstatic int VBoxServiceControlStartAllowed(bool *pbAllowed);
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync/** @copydoc VBOXSERVICE::pfnPreInit */
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsyncstatic DECLCALLBACK(int) VBoxServiceControlPreInit(void)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Read the service options from the VM's guest properties.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Note that these options can be overridden by the command line options later.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync int rc = VbglR3GuestPropConnect(&uGuestPropSvcClientID);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync if (rc == VERR_HGCM_SERVICE_NOT_FOUND) /* Host service is not available. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync VBoxServiceVerbose(0, "Control: Guest property service is not available, skipping\n");
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync VBoxServiceError("Control: Failed to connect to the guest property service! Error: %Rrc\n", rc);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync rc = VBoxServiceReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--control-procs-max-kept",
7bf07b1592dfaab1a4fb6d497fd0ff1302fb7585vboxsync if (rc == VERR_NOT_FOUND) /* If a value is not found, don't be sad! */
7c1f498692cd2393f8ba68cb62be482495106f93vboxsync /* Nothing to do here yet. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** @copydoc VBOXSERVICE::pfnOption */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncstatic DECLCALLBACK(int) VBoxServiceControlOption(const char **ppszShort, int argc, char **argv, int *pi)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* no short options */;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync else if (!strcmp(argv[*pi], "--control-procs-max-kept"))
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** @copydoc VBOXSERVICE::pfnInit */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncstatic DECLCALLBACK(int) VBoxServiceControlInit(void)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * If not specified, find the right interval default.
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * Then create the event sem to block on.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync rc = VbglR3GuestCtrlConnect(&g_GuestControlSvcClientID);
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync VBoxServiceVerbose(3, "Control: Service client ID: %#x\n", g_GuestControlSvcClientID);
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync /* Init thread list. */
91f8453d16b48876deddaba298c211071d0ca3a5vboxsync rc = RTCritSectInit(&g_GuestControlThreadsCritSect);
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync /* If the service was not found, we disable this service without
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync causing VBoxService to fail. */
9dfcf62b7a5a289684d46ee55f6042d49509daecvboxsync if (rc == VERR_HGCM_SERVICE_NOT_FOUND) /* Host service is not available. */
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync VBoxServiceVerbose(0, "Control: Guest control service is not available\n");
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync VBoxServiceError("Control: Failed to connect to the guest control service! Error: %Rrc\n", rc);
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync/** @copydoc VBOXSERVICE::pfnWorker */
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsyncDECLCALLBACK(int) VBoxServiceControlWorker(bool volatile *pfShutdown)
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * Tell the control thread that it can continue
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * spawning services.
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * Execution loop.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync VBoxServiceVerbose(3, "Control: Waiting for host msg ...\n");
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync rc = VbglR3GuestCtrlWaitForHostMsg(g_GuestControlSvcClientID, &uMsg, &uNumParms);
9bb98d54790a98dad0ad6d9bdc5d319b6fdf0bffvboxsync VBoxServiceVerbose(4, "Control: Message requires %ld parameters, but only 2 supplied -- retrying request (no error!)...\n", uNumParms);
9bb98d54790a98dad0ad6d9bdc5d319b6fdf0bffvboxsync rc = VINF_SUCCESS; /* Try to get "real" message in next block below. */
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync VBoxServiceVerbose(3, "Control: Getting host message failed with %Rrc\n", rc); /* VERR_GEN_IO_FAILURE seems to be normal if ran into timeout. */
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync VBoxServiceVerbose(3, "Control: Msg=%u (%u parms) retrieved\n", uMsg, uNumParms);
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync VBoxServiceVerbose(3, "Control: Host asked us to quit ...\n");
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync rc = VBoxServiceControlHandleCmdStartProc(g_GuestControlSvcClientID, uNumParms);
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync /** @todo Make buffer size configurable via guest properties/argv! */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync rc = VBoxServiceControlHandleCmdSetInput(g_GuestControlSvcClientID, uNumParms, _1M /* Buffer size */);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync rc = VBoxServiceControlHandleCmdGetOutput(g_GuestControlSvcClientID, uNumParms);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync VBoxServiceVerbose(3, "Control: Unsupported message from host! Msg=%u\n", uMsg);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* Don't terminate here; just wait for the next message. */
5704a317c3b6bdf4b59f6a6ebe45d443296b1995vboxsync VBoxServiceVerbose(3, "Control: Message was processed with rc=%Rrc\n", rc);
5704a317c3b6bdf4b59f6a6ebe45d443296b1995vboxsync /* Do we need to shutdown? */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* Let's sleep for a bit and let others run ... */
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * Handles starting processes on the guest.
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * @returns IPRT status code.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param u32ClientId The HGCM client session ID.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param uNumParms The number of parameters the host is offering.
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsyncint VBoxServiceControlHandleCmdStartProc(uint32_t uClientID, uint32_t uNumParms)
b8c2e8ba48bd659fa09a06770a7cedfae977d73bvboxsync#if 0 /* for valgrind */
1e289ac7f0c5324ef5712727fc61b2a322eb2e1avboxsync /* Command */
1e289ac7f0c5324ef5712727fc61b2a322eb2e1avboxsync /* Flags */
b8c2e8ba48bd659fa09a06770a7cedfae977d73bvboxsync /* Arguments */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* Environment */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* Credentials */
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync /* Timelimit */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync VBoxServiceVerbose(3, "ControlExec: Start process szCmd=%s, uFlags=%u, szArgs=%s, szEnv=%s, szUser=%s, szPW=%s, uTimeout=%u\n",
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync szCmd, uFlags, uNumArgs ? szArgs : "<None>", uNumEnvVars ? szEnv : "<None>", szUser, szPassword, uTimeLimitMS);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync bool fAllowed = false;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync int rc = VBoxServiceControlStartAllowed(&fAllowed);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync VBoxServiceError("ControlExec: Error determining whether process can be started or not, rc=%Rrc\n", rc);
a1a2e3f1c3ca7d6190c90ff67b7995b50b258794vboxsync int rc = RTCritSectEnter(&g_GuestControlThreadsCritSect);
a1a2e3f1c3ca7d6190c90ff67b7995b50b258794vboxsync /** @todo Put the following params into a struct! */
a1a2e3f1c3ca7d6190c90ff67b7995b50b258794vboxsync rc = VBoxServiceControlThreadStart(uClientID, uContextID,
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* Insert thread node into thread list. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /*rc =*/ RTListAppend(&g_GuestControlThreads, pThreadNode);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync int rc2 = RTCritSectLeave(&g_GuestControlThreadsCritSect);
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync else /* Process start is not allowed due to policy settings. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* Tell the host. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync rc = VbglR3GuestCtrlExecReportStatus(uClientID, uContextID, 0 /* PID, invalid. */,
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync VBoxServiceError("ControlExec: Failed to retrieve exec start command! Error: %Rrc\n", rc);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Gets output from stdout/stderr of a specified guest process.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @return IPRT status code.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param uPID PID of process to retrieve the output from.
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * @param uHandleId Stream ID (stdout = 0, stderr = 2) to get the output from.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param uTimeout Timeout (in ms) to wait for output becoming available.
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * @param pvBuf Pointer to a pre-allocated buffer to store the output.
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * @param cbBuf Size (in bytes) of the pre-allocated buffer.
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * @param pcbRead Pointer to number of bytes read. Optional.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncint VBoxServiceControlExecGetOutput(uint32_t uPID, uint32_t uHandleId, uint32_t uTimeout,
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* pcbRead is optional. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync ctrlRequest.enmType = VBOXSERVICECTRLREQUEST_STDERR_READ;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync ctrlRequest.enmType = VBOXSERVICECTRLREQUEST_STDOUT_READ;
47699a0c42ead32866009e0d91bfb349490feaf9vboxsync rc = VBoxServiceControlExecThreadPerform(uPID, &ctrlRequest);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Injects input to a specified running process.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @return IPRT status code.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param uPID PID of process to set the input for.
47699a0c42ead32866009e0d91bfb349490feaf9vboxsync * @param fPendingClose Flag indicating whether this is the last input block sent to the process.
78dfd747e1837f5de0bc5625c39dff4b98e3d4d4vboxsync * @param pvBuf Pointer to a buffer containing the actual input data.
47699a0c42ead32866009e0d91bfb349490feaf9vboxsync * @param cbBuf Size (in bytes) of the input buffer data.
70f7b6ff8dc13303a70e552dd7003aa672e985a2vboxsync * @param pcbWritten Pointer to number of bytes written to the process. Optional.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncint VBoxServiceControlSetInput(uint32_t uPID, bool fPendingClose,
78dfd747e1837f5de0bc5625c39dff4b98e3d4d4vboxsync /* pcbWritten is optional. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync ? VBOXSERVICECTRLREQUEST_STDIN_WRITE_EOF : VBOXSERVICECTRLREQUEST_STDIN_WRITE;
ac2b2ae448fe887af9a3269e40afff11ebb1f9d3vboxsync rc = VBoxServiceControlExecThreadPerform(uPID, &ctrlRequest);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Handles input for a started process by copying the received data into its
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * stdin pipe.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @returns IPRT status code.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param u32ClientId The HGCM client session ID.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param uNumParms The number of parameters the host is offering.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param cMaxBufSize The maximum buffer size for retrieving the input data.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncint VBoxServiceControlHandleCmdSetInput(uint32_t u32ClientId, uint32_t uNumParms, size_t cbMaxBufSize)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync AssertReturn(RT_IS_POWER_OF_TWO(cbMaxBufSize), VERR_INVALID_PARAMETER);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync uint8_t *pabBuffer = (uint8_t*)RTMemAlloc(cbMaxBufSize);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync uint32_t uStatus = INPUT_STS_UNDEFINED; /* Status sent back to the host. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync uint32_t cbWritten = 0; /* Number of bytes written to the guest. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Ask the host for the input data.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync int rc = VbglR3GuestCtrlExecGetHostCmdInput(u32ClientId, uNumParms,
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync VBoxServiceError("ControlExec: [PID %u]: Failed to retrieve exec input command! Error: %Rrc\n",
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync VBoxServiceError("ControlExec: [PID %u]: Too much input received! cbSize=%u, cbMaxBufSize=%u\n",
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Is this the last input block we need to deliver? Then let the pipe know ...
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync VBoxServiceVerbose(4, "ControlExec: [PID %u]: Got last input block of size %u ...\n",
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync rc = VBoxServiceControlSetInput(uPID, fPendingClose, pabBuffer,
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync VBoxServiceVerbose(4, "ControlExec: [PID %u]: Written input, rc=%Rrc, uFlags=0x%x, fPendingClose=%d, cbSize=%u, cbWritten=%u\n",
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync uPID, rc, uFlags, fPendingClose, cbSize, cbWritten);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync if (cbWritten || !cbSize) /* Did we write something or was there anything to write at all? */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * If there was an error and we did not set the host status
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * yet, then do it now.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync VBoxServiceVerbose(3, "ControlExec: [PID %u]: Input processed, CID=%u, uStatus=%u, uFlags=0x%x, cbWritten=%u\n",
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* Note: Since the context ID is unique the request *has* to be completed here,
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * regardless whether we got data or not! Otherwise the progress object
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * on the host never will get completed! */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync rc = VbglR3GuestCtrlExecReportStatusIn(u32ClientId, uContextID, uPID,
3dd53c06fd54914761cf550503f02fce1ed5a815vboxsync VBoxServiceError("ControlExec: [PID %u]: Failed to report input status! Error: %Rrc\n",
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Handles the guest control output command.
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * @return IPRT status code.
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * @param u32ClientId idClient The HGCM client session ID.
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * @param uNumParms cParms The number of parameters the host is
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync * offering.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncint VBoxServiceControlHandleCmdGetOutput(uint32_t u32ClientId, uint32_t uNumParms)
3dd53c06fd54914761cf550503f02fce1ed5a815vboxsync int rc = VbglR3GuestCtrlExecGetHostCmdOutput(u32ClientId, uNumParms,
ec9dc23c50665e8603e1be5a9b6b6fd4c4d949d4vboxsync rc = VBoxServiceControlExecGetOutput(uPID, uHandleID, RT_INDEFINITE_WAIT /* Timeout */,
d1fcf24d24368926be13484524a9e378070a9157vboxsync VBoxServiceVerbose(3, "ControlExec: [PID %u]: Got output, CID=%u, cbRead=%u, uHandle=%u, uFlags=%u\n",
3dd53c06fd54914761cf550503f02fce1ed5a815vboxsync VBoxServiceError("ControlExec: [PID %u]: Failed to retrieve output, CID=%u, uHandle=%u, rc=%Rrc\n",
3dd53c06fd54914761cf550503f02fce1ed5a815vboxsync /* Note: Since the context ID is unique the request *has* to be completed here,
3dd53c06fd54914761cf550503f02fce1ed5a815vboxsync * regardless whether we got data or not! Otherwise the progress object
3dd53c06fd54914761cf550503f02fce1ed5a815vboxsync * on the host never will get completed! */
3dd53c06fd54914761cf550503f02fce1ed5a815vboxsync /* cbRead now contains actual size. */
3dd53c06fd54914761cf550503f02fce1ed5a815vboxsync int rc2 = VbglR3GuestCtrlExecSendOut(u32ClientId, uContextID, uPID, uHandleID, uFlags,
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync VBoxServiceError("ControlExec: [PID %u]: Error handling output command! Error: %Rrc\n",
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** @copydoc VBOXSERVICE::pfnStop */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncstatic DECLCALLBACK(void) VBoxServiceControlStop(void)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /** @todo Later, figure what to do if we're in RTProcWait(). It's a very
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * annoying call since doesn't support timeouts in the posix world. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Ask the host service to cancel all pending requests so that we can
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * shutdown properly here.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync int rc = VbglR3GuestCtrlCancelPendingWaits(g_GuestControlSvcClientID);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync VBoxServiceError("Control: Cancelling pending waits failed; rc=%Rrc\n", rc);
while (pThread)
if (fLast)
bool fLimitReached = false;
VBoxServiceVerbose(2, "ControlExec: Maximum served guest processes set to %u, running=%u, stopped=%u\n",
if (iProcsLeft < 0)
fLimitReached = true;
return rc;
return pNode;
if (!pThread)