VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlProcess.cpp@ 61439

Last change on this file since 61439 was 60622, checked in by vboxsync, 9 years ago

Guest Control: Added proper handling for (VBoxService) toolbox exit codes, resolving various copyto/copyfrom bugs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 82.5 KB
Line 
1/* $Id: VBoxServiceControlProcess.cpp 60622 2016-04-21 13:00:20Z vboxsync $ */
2/** @file
3 * VBoxServiceControlThread - Guest process handling.
4 */
5
6/*
7 * Copyright (C) 2012-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#include <iprt/asm.h>
23#include <iprt/assert.h>
24#include <iprt/env.h>
25#include <iprt/file.h>
26#include <iprt/getopt.h>
27#include <iprt/handle.h>
28#include <iprt/mem.h>
29#include <iprt/path.h>
30#include <iprt/pipe.h>
31#include <iprt/poll.h>
32#include <iprt/process.h>
33#include <iprt/semaphore.h>
34#include <iprt/string.h>
35#include <iprt/thread.h>
36
37#include <VBox/VBoxGuestLib.h>
38#include <VBox/HostServices/GuestControlSvc.h>
39
40#include "VBoxServiceInternal.h"
41#include "VBoxServiceControl.h"
42#include "VBoxServiceToolBox.h"
43
44using namespace guestControl;
45
46
47/*********************************************************************************************************************************
48* Internal Functions *
49*********************************************************************************************************************************/
50static int vgsvcGstCtrlProcessAssignPID(PVBOXSERVICECTRLPROCESS pThread, uint32_t uPID);
51static int vgsvcGstCtrlProcessLock(PVBOXSERVICECTRLPROCESS pProcess);
52static int vgsvcGstCtrlProcessRequest(PVBOXSERVICECTRLPROCESS pProcess, const PVBGLR3GUESTCTRLCMDCTX pHostCtx,
53 PFNRT pfnFunction, unsigned cArgs, ...);
54static int vgsvcGstCtrlProcessSetupPipe(const char *pszHowTo, int fd, PRTHANDLE ph, PRTHANDLE *pph,
55 PRTPIPE phPipe);
56static int vgsvcGstCtrlProcessUnlock(PVBOXSERVICECTRLPROCESS pProcess);
57/* Request handlers. */
58static DECLCALLBACK(int) vgsvcGstCtrlProcessOnInput(PVBOXSERVICECTRLPROCESS pThis, const PVBGLR3GUESTCTRLCMDCTX pHostCtx,
59 bool fPendingClose, void *pvBuf, uint32_t cbBuf);
60static DECLCALLBACK(int) vgsvcGstCtrlProcessOnOutput(PVBOXSERVICECTRLPROCESS pThis, const PVBGLR3GUESTCTRLCMDCTX pHostCtx,
61 uint32_t uHandle, uint32_t cbToRead, uint32_t uFlags);
62static DECLCALLBACK(int) vgsvcGstCtrlProcessOnTerm(PVBOXSERVICECTRLPROCESS pThis);
63
64
65/**
66 * Initialies the passed in thread data structure with the parameters given.
67 *
68 * @return IPRT status code.
69 * @param pProcess Process to initialize.
70 * @param pSession Guest session the process is bound to.
71 * @param pStartupInfo Startup information.
72 * @param u32ContextID The context ID bound to this request / command.
73 */
74static int vgsvcGstCtrlProcessInit(PVBOXSERVICECTRLPROCESS pProcess,
75 const PVBOXSERVICECTRLSESSION pSession,
76 const PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo,
77 uint32_t u32ContextID)
78{
79 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
80 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
81 AssertPtrReturn(pStartupInfo, VERR_INVALID_POINTER);
82
83 /* General stuff. */
84 pProcess->hProcess = NIL_RTPROCESS;
85 pProcess->pSession = pSession;
86 pProcess->Node.pPrev = NULL;
87 pProcess->Node.pNext = NULL;
88
89 pProcess->fShutdown = false;
90 pProcess->fStarted = false;
91 pProcess->fStopped = false;
92
93 pProcess->uPID = 0; /* Don't have a PID yet. */
94 pProcess->cRefs = 0;
95 /*
96 * Use the initial context ID we got for starting
97 * the process to report back its status with the
98 * same context ID.
99 */
100 pProcess->uContextID = u32ContextID;
101 /*
102 * Note: pProcess->ClientID will be assigned when thread is started;
103 * every guest process has its own client ID to detect crashes on
104 * a per-guest-process level.
105 */
106
107 int rc = RTCritSectInit(&pProcess->CritSect);
108 if (RT_FAILURE(rc))
109 return rc;
110
111 pProcess->hPollSet = NIL_RTPOLLSET;
112 pProcess->hPipeStdInW = NIL_RTPIPE;
113 pProcess->hPipeStdOutR = NIL_RTPIPE;
114 pProcess->hPipeStdErrR = NIL_RTPIPE;
115 pProcess->hNotificationPipeW = NIL_RTPIPE;
116 pProcess->hNotificationPipeR = NIL_RTPIPE;
117
118 rc = RTReqQueueCreate(&pProcess->hReqQueue);
119 AssertReleaseRC(rc);
120
121 /* Copy over startup info. */
122 memcpy(&pProcess->StartupInfo, pStartupInfo, sizeof(VBOXSERVICECTRLPROCSTARTUPINFO));
123
124 /* Adjust timeout value. */
125 if ( pProcess->StartupInfo.uTimeLimitMS == UINT32_MAX
126 || pProcess->StartupInfo.uTimeLimitMS == 0)
127 pProcess->StartupInfo.uTimeLimitMS = RT_INDEFINITE_WAIT;
128
129 if (RT_FAILURE(rc)) /* Clean up on failure. */
130 VGSvcGstCtrlProcessFree(pProcess);
131 return rc;
132}
133
134
135/**
136 * Frees a guest process. On success, pProcess will be
137 * free'd and thus won't be available anymore.
138 *
139 * @return IPRT status code.
140 * @param pProcess Guest process to free.
141 */
142int VGSvcGstCtrlProcessFree(PVBOXSERVICECTRLPROCESS pProcess)
143{
144 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
145
146 VGSvcVerbose(3, "[PID %RU32]: Freeing (cRefs=%RU32)...\n", pProcess->uPID, pProcess->cRefs);
147 Assert(pProcess->cRefs == 0);
148
149 /*
150 * Destroy other thread data.
151 */
152 if (RTCritSectIsInitialized(&pProcess->CritSect))
153 RTCritSectDelete(&pProcess->CritSect);
154
155 int rc = RTReqQueueDestroy(pProcess->hReqQueue);
156 AssertRC(rc);
157
158 /*
159 * Remove from list.
160 */
161 AssertPtr(pProcess->pSession);
162 rc = VGSvcGstCtrlSessionProcessRemove(pProcess->pSession, pProcess);
163 AssertRC(rc);
164
165 /*
166 * Destroy thread structure as final step.
167 */
168 RTMemFree(pProcess);
169 pProcess = NULL;
170
171 return VINF_SUCCESS;
172}
173
174
175/**
176 * Signals a guest process thread that we want it to shut down in
177 * a gentle way.
178 *
179 * @return IPRT status code.
180 * @param pProcess Process to stop.
181 */
182int VGSvcGstCtrlProcessStop(PVBOXSERVICECTRLPROCESS pProcess)
183{
184 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
185
186 VGSvcVerbose(3, "[PID %RU32]: Stopping ...\n", pProcess->uPID);
187
188 /* Do *not* set pThread->fShutdown or other stuff here!
189 * The guest thread loop will clean up itself. */
190
191 return VGSvcGstCtrlProcessHandleTerm(pProcess);
192}
193
194
195/**
196 * Releases a previously acquired guest process (decreases the refcount).
197 *
198 * @param pProcess Process to unlock.
199 */
200void VGSvcGstCtrlProcessRelease(PVBOXSERVICECTRLPROCESS pProcess)
201{
202 AssertPtrReturnVoid(pProcess);
203
204 bool fShutdown = false;
205
206 int rc = RTCritSectEnter(&pProcess->CritSect);
207 if (RT_SUCCESS(rc))
208 {
209 Assert(pProcess->cRefs);
210 pProcess->cRefs--;
211 fShutdown = pProcess->fStopped; /* Has the process' thread been stopped? */
212
213 rc = RTCritSectLeave(&pProcess->CritSect);
214 AssertRC(rc);
215 }
216
217 if (fShutdown)
218 VGSvcGstCtrlProcessFree(pProcess);
219}
220
221
222/**
223 * Wait for a guest process thread to shut down.
224 *
225 * @return IPRT status code.
226 * @param pProcess Process to wait shutting down for.
227 * @param msTimeout Timeout in ms to wait for shutdown.
228 * @param prc Where to store the thread's return code.
229 * Optional.
230 */
231int VGSvcGstCtrlProcessWait(const PVBOXSERVICECTRLPROCESS pProcess, RTMSINTERVAL msTimeout, int *prc)
232{
233 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
234 AssertPtrNullReturn(prc, VERR_INVALID_POINTER);
235
236 int rc = vgsvcGstCtrlProcessLock(pProcess);
237 if (RT_SUCCESS(rc))
238 {
239 VGSvcVerbose(2, "[PID %RU32]: Waiting for shutdown (%RU32ms) ...\n", pProcess->uPID, msTimeout);
240
241 AssertMsgReturn(pProcess->fStarted,
242 ("Tried to wait on guest process=%p (PID %RU32) which has not been started yet\n",
243 pProcess, pProcess->uPID), VERR_INVALID_PARAMETER);
244
245 /* Guest process already has been stopped, no need to wait. */
246 if (!pProcess->fStopped)
247 {
248 /* Unlock process before waiting. */
249 rc = vgsvcGstCtrlProcessUnlock(pProcess);
250 AssertRC(rc);
251
252 /* Do the actual waiting. */
253 int rcThread;
254 Assert(pProcess->Thread != NIL_RTTHREAD);
255 rc = RTThreadWait(pProcess->Thread, msTimeout, &rcThread);
256 if (RT_SUCCESS(rc))
257 {
258 VGSvcVerbose(3, "[PID %RU32]: Thread shutdown complete, thread rc=%Rrc\n", pProcess->uPID, rcThread);
259 if (prc)
260 *prc = rcThread;
261 }
262 else
263 VGSvcError("[PID %RU32]: Waiting for shutting down thread returned error rc=%Rrc\n", pProcess->uPID, rc);
264 }
265 else
266 {
267 VGSvcVerbose(3, "[PID %RU32]: Thread already shut down, no waiting needed\n", pProcess->uPID);
268
269 int rc2 = vgsvcGstCtrlProcessUnlock(pProcess);
270 AssertRC(rc2);
271 }
272 }
273
274 VGSvcVerbose(3, "[PID %RU32]: Waiting resulted in rc=%Rrc\n", pProcess->uPID, rc);
275 return rc;
276}
277
278
279/**
280 * Closes the stdin pipe of a guest process.
281 *
282 * @return IPRT status code.
283 * @param pProcess The process which input pipe we close.
284 * @param phStdInW The standard input pipe handle.
285 */
286static int vgsvcGstCtrlProcessPollsetCloseInput(PVBOXSERVICECTRLPROCESS pProcess, PRTPIPE phStdInW)
287{
288 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
289 AssertPtrReturn(phStdInW, VERR_INVALID_POINTER);
290
291 int rc = RTPollSetRemove(pProcess->hPollSet, VBOXSERVICECTRLPIPEID_STDIN);
292 if (rc != VERR_POLL_HANDLE_ID_NOT_FOUND)
293 AssertRC(rc);
294
295 if (*phStdInW != NIL_RTPIPE)
296 {
297 rc = RTPipeClose(*phStdInW);
298 AssertRC(rc);
299 *phStdInW = NIL_RTPIPE;
300 }
301
302 return rc;
303}
304
305
306/**
307 * Names a poll handle ID.
308 *
309 * @returns Pointer to read-only string.
310 * @param idPollHnd What to name.
311 */
312static const char *vgsvcGstCtrlProcessPollHandleToString(uint32_t idPollHnd)
313{
314 switch (idPollHnd)
315 {
316 case VBOXSERVICECTRLPIPEID_UNKNOWN:
317 return "unknown";
318 case VBOXSERVICECTRLPIPEID_STDIN:
319 return "stdin";
320 case VBOXSERVICECTRLPIPEID_STDIN_WRITABLE:
321 return "stdin_writable";
322 case VBOXSERVICECTRLPIPEID_STDOUT:
323 return "stdout";
324 case VBOXSERVICECTRLPIPEID_STDERR:
325 return "stderr";
326 case VBOXSERVICECTRLPIPEID_IPC_NOTIFY:
327 return "ipc_notify";
328 default:
329 return "unknown";
330 }
331}
332
333
334/**
335 * Handle an error event on standard input.
336 *
337 * @return IPRT status code.
338 * @param pProcess Process to handle pollset for.
339 * @param fPollEvt The event mask returned by RTPollNoResume.
340 * @param phStdInW The standard input pipe handle.
341 */
342static int vgsvcGstCtrlProcessPollsetOnInput(PVBOXSERVICECTRLPROCESS pProcess, uint32_t fPollEvt, PRTPIPE phStdInW)
343{
344 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
345
346 NOREF(fPollEvt);
347
348 return vgsvcGstCtrlProcessPollsetCloseInput(pProcess, phStdInW);
349}
350
351
352/**
353 * Handle pending output data or error on standard out or standard error.
354 *
355 * @returns IPRT status code from client send.
356 * @param pProcess Process to handle pollset for.
357 * @param fPollEvt The event mask returned by RTPollNoResume.
358 * @param phPipeR The pipe handle.
359 * @param idPollHnd The pipe ID to handle.
360 */
361static int vgsvcGstCtrlProcessHandleOutputError(PVBOXSERVICECTRLPROCESS pProcess,
362 uint32_t fPollEvt, PRTPIPE phPipeR, uint32_t idPollHnd)
363{
364 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
365
366 if (!phPipeR)
367 return VINF_SUCCESS;
368
369#ifdef DEBUG
370 VGSvcVerbose(4, "[PID %RU32]: Output error: idPollHnd=%s, fPollEvt=0x%x\n",
371 pProcess->uPID, vgsvcGstCtrlProcessPollHandleToString(idPollHnd), fPollEvt);
372#endif
373
374 /* Remove pipe from poll set. */
375 int rc2 = RTPollSetRemove(pProcess->hPollSet, idPollHnd);
376 AssertMsg(RT_SUCCESS(rc2) || rc2 == VERR_POLL_HANDLE_ID_NOT_FOUND, ("%Rrc\n", rc2));
377
378 bool fClosePipe = true; /* By default close the pipe. */
379
380 /* Check if there's remaining data to read from the pipe. */
381 if (*phPipeR != NIL_RTPIPE)
382 {
383 size_t cbReadable;
384 rc2 = RTPipeQueryReadable(*phPipeR, &cbReadable);
385 if ( RT_SUCCESS(rc2)
386 && cbReadable)
387 {
388#ifdef DEBUG
389 VGSvcVerbose(3, "[PID %RU32]: idPollHnd=%s has %zu bytes left, vetoing close\n",
390 pProcess->uPID, vgsvcGstCtrlProcessPollHandleToString(idPollHnd), cbReadable);
391#endif
392 /* Veto closing the pipe yet because there's still stuff to read
393 * from the pipe. This can happen on UNIX-y systems where on
394 * error/hangup there still can be data to be read out. */
395 fClosePipe = false;
396 }
397 }
398#ifdef DEBUG
399 else
400 VGSvcVerbose(3, "[PID %RU32]: idPollHnd=%s will be closed\n",
401 pProcess->uPID, vgsvcGstCtrlProcessPollHandleToString(idPollHnd));
402#endif
403
404 if ( *phPipeR != NIL_RTPIPE
405 && fClosePipe)
406 {
407 rc2 = RTPipeClose(*phPipeR);
408 AssertRC(rc2);
409 *phPipeR = NIL_RTPIPE;
410 }
411
412 return VINF_SUCCESS;
413}
414
415
416/**
417 * Handle pending output data or error on standard out or standard error.
418 *
419 * @returns IPRT status code from client send.
420 * @param pProcess Process to handle pollset for.
421 * @param fPollEvt The event mask returned by RTPollNoResume.
422 * @param phPipeR The pipe handle.
423 * @param idPollHnd The pipe ID to handle.
424 *
425 */
426static int vgsvcGstCtrlProcessPollsetOnOutput(PVBOXSERVICECTRLPROCESS pProcess,
427 uint32_t fPollEvt, PRTPIPE phPipeR, uint32_t idPollHnd)
428{
429 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
430
431#ifdef DEBUG
432 VGSvcVerbose(4, "[PID %RU32]: Output event phPipeR=%p, idPollHnd=%s, fPollEvt=0x%x\n",
433 pProcess->uPID, phPipeR, vgsvcGstCtrlProcessPollHandleToString(idPollHnd), fPollEvt);
434#endif
435
436 if (!phPipeR)
437 return VINF_SUCCESS;
438
439 int rc = VINF_SUCCESS;
440
441#ifdef DEBUG
442 if (*phPipeR != NIL_RTPIPE)
443 {
444 size_t cbReadable;
445 rc = RTPipeQueryReadable(*phPipeR, &cbReadable);
446 if ( RT_SUCCESS(rc)
447 && cbReadable)
448 {
449 VGSvcVerbose(4, "[PID %RU32]: Output event cbReadable=%zu\n", pProcess->uPID, cbReadable);
450 }
451 }
452#endif
453
454#if 0
455 /* Push output to the host. */
456 if (fPollEvt & RTPOLL_EVT_READ)
457 {
458 size_t cbRead = 0;
459 uint8_t byData[_64K];
460 rc = RTPipeRead(*phPipeR, byData, sizeof(byData), &cbRead);
461 VGSvcVerbose(4, "VGSvcGstCtrlProcessHandleOutputEvent cbRead=%u, rc=%Rrc\n", cbRead, rc);
462
463 /* Make sure we go another poll round in case there was too much data
464 for the buffer to hold. */
465 fPollEvt &= RTPOLL_EVT_ERROR;
466 }
467#endif
468
469 if (fPollEvt & RTPOLL_EVT_ERROR)
470 rc = vgsvcGstCtrlProcessHandleOutputError(pProcess, fPollEvt, phPipeR, idPollHnd);
471 return rc;
472}
473
474
475/**
476 * Execution loop which runs in a dedicated per-started-process thread and
477 * handles all pipe input/output and signalling stuff.
478 *
479 * @return IPRT status code.
480 * @param pProcess The guest process to handle.
481 */
482static int vgsvcGstCtrlProcessProcLoop(PVBOXSERVICECTRLPROCESS pProcess)
483{
484 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
485
486 int rc;
487 int rc2;
488 uint64_t const uMsStart = RTTimeMilliTS();
489 RTPROCSTATUS ProcessStatus = { 254, RTPROCEXITREASON_ABEND };
490 bool fProcessAlive = true;
491 bool fProcessTimedOut = false;
492 uint64_t MsProcessKilled = UINT64_MAX;
493 RTMSINTERVAL const cMsPollBase = pProcess->hPipeStdInW != NIL_RTPIPE
494 ? 100 /* Need to poll for input. */
495 : 1000; /* Need only poll for process exit and aborts. */
496 RTMSINTERVAL cMsPollCur = 0;
497
498 /*
499 * Assign PID to thread data.
500 * Also check if there already was a thread with the same PID and shut it down -- otherwise
501 * the first (stale) entry will be found and we get really weird results!
502 */
503 rc = vgsvcGstCtrlProcessAssignPID(pProcess, pProcess->hProcess /* Opaque PID handle */);
504 if (RT_FAILURE(rc))
505 {
506 VGSvcError("Unable to assign PID=%u, to new thread, rc=%Rrc\n", pProcess->hProcess, rc);
507 return rc;
508 }
509
510 /*
511 * Before entering the loop, tell the host that we've started the guest
512 * and that it's now OK to send input to the process.
513 */
514 VGSvcVerbose(2, "[PID %RU32]: Process '%s' started, CID=%u, User=%s, cMsTimeout=%RU32\n",
515 pProcess->uPID, pProcess->StartupInfo.szCmd, pProcess->uContextID,
516 pProcess->StartupInfo.szUser, pProcess->StartupInfo.uTimeLimitMS);
517 VBGLR3GUESTCTRLCMDCTX ctxStart = { pProcess->uClientID, pProcess->uContextID };
518 rc = VbglR3GuestCtrlProcCbStatus(&ctxStart,
519 pProcess->uPID, PROC_STS_STARTED, 0 /* u32Flags */,
520 NULL /* pvData */, 0 /* cbData */);
521 if (rc == VERR_INTERRUPTED)
522 rc = VINF_SUCCESS; /* SIGCHLD send by quick childs! */
523 if (RT_FAILURE(rc))
524 VGSvcError("[PID %RU32]: Error reporting starting status to host, rc=%Rrc\n", pProcess->uPID, rc);
525
526 /*
527 * Process input, output, the test pipe and client requests.
528 */
529 while ( RT_SUCCESS(rc)
530 && RT_UNLIKELY(!pProcess->fShutdown))
531 {
532 /*
533 * Wait/Process all pending events.
534 */
535 uint32_t idPollHnd;
536 uint32_t fPollEvt;
537 rc2 = RTPollNoResume(pProcess->hPollSet, cMsPollCur, &fPollEvt, &idPollHnd);
538 if (pProcess->fShutdown)
539 continue;
540
541 cMsPollCur = 0; /* No rest until we've checked everything. */
542
543 if (RT_SUCCESS(rc2))
544 {
545 switch (idPollHnd)
546 {
547 case VBOXSERVICECTRLPIPEID_STDIN:
548 rc = vgsvcGstCtrlProcessPollsetOnInput(pProcess, fPollEvt, &pProcess->hPipeStdInW);
549 break;
550
551 case VBOXSERVICECTRLPIPEID_STDOUT:
552 rc = vgsvcGstCtrlProcessPollsetOnOutput(pProcess, fPollEvt, &pProcess->hPipeStdOutR, idPollHnd);
553 break;
554
555 case VBOXSERVICECTRLPIPEID_STDERR:
556 rc = vgsvcGstCtrlProcessPollsetOnOutput(pProcess, fPollEvt, &pProcess->hPipeStdOutR, idPollHnd);
557 break;
558
559 case VBOXSERVICECTRLPIPEID_IPC_NOTIFY:
560#ifdef DEBUG_andy
561 VGSvcVerbose(4, "[PID %RU32]: IPC notify\n", pProcess->uPID);
562#endif
563 rc2 = vgsvcGstCtrlProcessLock(pProcess);
564 if (RT_SUCCESS(rc2))
565 {
566 /* Drain the notification pipe. */
567 uint8_t abBuf[8];
568 size_t cbIgnore;
569 rc2 = RTPipeRead(pProcess->hNotificationPipeR, abBuf, sizeof(abBuf), &cbIgnore);
570 if (RT_FAILURE(rc2))
571 VGSvcError("Draining IPC notification pipe failed with rc=%Rrc\n", rc2);
572
573 /* Process all pending requests. */
574 VGSvcVerbose(4, "[PID %RU32]: Processing pending requests ...\n", pProcess->uPID);
575 Assert(pProcess->hReqQueue != NIL_RTREQQUEUE);
576 rc2 = RTReqQueueProcess(pProcess->hReqQueue,
577 0 /* Only process all pending requests, don't wait for new ones */);
578 if ( RT_FAILURE(rc2)
579 && rc2 != VERR_TIMEOUT)
580 VGSvcError("Processing requests failed with with rc=%Rrc\n", rc2);
581
582 int rc3 = vgsvcGstCtrlProcessUnlock(pProcess);
583 AssertRC(rc3);
584#ifdef DEBUG
585 VGSvcVerbose(4, "[PID %RU32]: Processing pending requests done, rc=%Rrc\n", pProcess->uPID, rc2);
586#endif
587 }
588
589 break;
590
591 default:
592 AssertMsgFailed(("Unknown idPollHnd=%RU32\n", idPollHnd));
593 break;
594 }
595
596 if (RT_FAILURE(rc) || rc == VINF_EOF)
597 break; /* Abort command, or client dead or something. */
598 }
599#if 0
600 VGSvcVerbose(4, "[PID %RU32]: Polling done, pollRc=%Rrc, pollCnt=%RU32, idPollHnd=%s, rc=%Rrc, fProcessAlive=%RTbool, fShutdown=%RTbool\n",
601 pProcess->uPID, rc2, RTPollSetGetCount(hPollSet), vgsvcGstCtrlProcessPollHandleToString(idPollHnd), rc, fProcessAlive, pProcess->fShutdown);
602 VGSvcVerbose(4, "[PID %RU32]: stdOut=%s, stdErrR=%s\n",
603 pProcess->uPID,
604 *phStdOutR == NIL_RTPIPE ? "closed" : "open",
605 *phStdErrR == NIL_RTPIPE ? "closed" : "open");
606#endif
607 if (RT_UNLIKELY(pProcess->fShutdown))
608 break; /* We were asked to shutdown. */
609
610 /*
611 * Check for process death.
612 */
613 if (fProcessAlive)
614 {
615 rc2 = RTProcWaitNoResume(pProcess->hProcess, RTPROCWAIT_FLAGS_NOBLOCK, &ProcessStatus);
616 if (RT_SUCCESS_NP(rc2))
617 {
618 fProcessAlive = false;
619 /* Note: Don't bail out here yet. First check in the next block below
620 * if all needed pipe outputs have been consumed. */
621 }
622 else
623 {
624 if (RT_UNLIKELY(rc2 == VERR_INTERRUPTED))
625 continue;
626 if (RT_UNLIKELY(rc2 == VERR_PROCESS_NOT_FOUND))
627 {
628 fProcessAlive = false;
629 ProcessStatus.enmReason = RTPROCEXITREASON_ABEND;
630 ProcessStatus.iStatus = 255;
631 AssertFailed();
632 }
633 else
634 AssertMsg(rc2 == VERR_PROCESS_RUNNING, ("%Rrc\n", rc2));
635 }
636 }
637
638 /*
639 * If the process has terminated and all output has been consumed,
640 * we should be heading out.
641 */
642 if (!fProcessAlive)
643 {
644 if ( fProcessTimedOut
645 || ( pProcess->hPipeStdOutR == NIL_RTPIPE
646 && pProcess->hPipeStdErrR == NIL_RTPIPE)
647 )
648 {
649 VGSvcVerbose(3, "[PID %RU32]: RTProcWaitNoResume=%Rrc\n", pProcess->uPID, rc2);
650 break;
651 }
652 }
653
654 /*
655 * Check for timed out, killing the process.
656 */
657 uint32_t cMilliesLeft = RT_INDEFINITE_WAIT;
658 if ( pProcess->StartupInfo.uTimeLimitMS != RT_INDEFINITE_WAIT
659 && pProcess->StartupInfo.uTimeLimitMS != 0)
660 {
661 uint64_t u64Now = RTTimeMilliTS();
662 uint64_t cMsElapsed = u64Now - uMsStart;
663 if (cMsElapsed >= pProcess->StartupInfo.uTimeLimitMS)
664 {
665 fProcessTimedOut = true;
666 if ( MsProcessKilled == UINT64_MAX
667 || u64Now - MsProcessKilled > 1000)
668 {
669 if (u64Now - MsProcessKilled > 20*60*1000)
670 break; /* Give up after 20 mins. */
671
672 VGSvcVerbose(3, "[PID %RU32]: Timed out (%RU64ms elapsed > %RU32ms timeout), killing ...\n",
673 pProcess->uPID, cMsElapsed, pProcess->StartupInfo.uTimeLimitMS);
674
675 rc2 = RTProcTerminate(pProcess->hProcess);
676 VGSvcVerbose(3, "[PID %RU32]: Killing process resulted in rc=%Rrc\n",
677 pProcess->uPID, rc2);
678 MsProcessKilled = u64Now;
679 continue;
680 }
681 cMilliesLeft = 10000;
682 }
683 else
684 cMilliesLeft = pProcess->StartupInfo.uTimeLimitMS - (uint32_t)cMsElapsed;
685 }
686
687 /* Reset the polling interval since we've done all pending work. */
688 cMsPollCur = fProcessAlive
689 ? cMsPollBase
690 : RT_MS_1MIN;
691 if (cMilliesLeft < cMsPollCur)
692 cMsPollCur = cMilliesLeft;
693 }
694
695 VGSvcVerbose(3, "[PID %RU32]: Loop ended: rc=%Rrc, fShutdown=%RTbool, fProcessAlive=%RTbool, fProcessTimedOut=%RTbool, MsProcessKilled=%RU64\n",
696 pProcess->uPID, rc, pProcess->fShutdown, fProcessAlive, fProcessTimedOut, MsProcessKilled, MsProcessKilled);
697 VGSvcVerbose(3, "[PID %RU32]: *phStdOutR=%s, *phStdErrR=%s\n",
698 pProcess->uPID,
699 pProcess->hPipeStdOutR == NIL_RTPIPE ? "closed" : "open",
700 pProcess->hPipeStdErrR == NIL_RTPIPE ? "closed" : "open");
701
702 /* Signal that this thread is in progress of shutting down. */
703 ASMAtomicWriteBool(&pProcess->fShutdown, true);
704
705 /*
706 * Try killing the process if it's still alive at this point.
707 */
708 if (fProcessAlive)
709 {
710 if (MsProcessKilled == UINT64_MAX)
711 {
712 VGSvcVerbose(2, "[PID %RU32]: Is still alive and not killed yet\n", pProcess->uPID);
713
714 MsProcessKilled = RTTimeMilliTS();
715 rc2 = RTProcTerminate(pProcess->hProcess);
716 if (rc2 == VERR_NOT_FOUND)
717 {
718 fProcessAlive = false;
719 }
720 else if (RT_FAILURE(rc2))
721 VGSvcError("[PID %RU32]: Killing process failed with rc=%Rrc\n", pProcess->uPID, rc2);
722 RTThreadSleep(500);
723 }
724
725 for (int i = 0; i < 10 && fProcessAlive; i++)
726 {
727 VGSvcVerbose(4, "[PID %RU32]: Kill attempt %d/10: Waiting to exit ...\n", pProcess->uPID, i + 1);
728 rc2 = RTProcWait(pProcess->hProcess, RTPROCWAIT_FLAGS_NOBLOCK, &ProcessStatus);
729 if (RT_SUCCESS(rc2))
730 {
731 VGSvcVerbose(4, "[PID %RU32]: Kill attempt %d/10: Exited\n", pProcess->uPID, i + 1);
732 fProcessAlive = false;
733 break;
734 }
735 if (i >= 5)
736 {
737 VGSvcVerbose(4, "[PID %RU32]: Kill attempt %d/10: Trying to terminate ...\n", pProcess->uPID, i + 1);
738 rc2 = RTProcTerminate(pProcess->hProcess);
739 if ( RT_FAILURE(rc)
740 && rc2 != VERR_NOT_FOUND)
741 VGSvcError("PID %RU32]: Killing process failed with rc=%Rrc\n",
742 pProcess->uPID, rc2);
743 }
744 RTThreadSleep(i >= 5 ? 2000 : 500);
745 }
746
747 if (fProcessAlive)
748 VGSvcError("[PID %RU32]: Could not be killed\n", pProcess->uPID);
749 }
750
751 /*
752 * Shutdown procedure:
753 * - Set the pProcess->fShutdown indicator to let others know we're
754 * not accepting any new requests anymore.
755 * - After setting the indicator, try to process all outstanding
756 * requests to make sure they're getting delivered.
757 *
758 * Note: After removing the process from the session's list it's not
759 * even possible for the session anymore to control what's
760 * happening to this thread, so be careful and don't mess it up.
761 */
762
763 rc2 = vgsvcGstCtrlProcessLock(pProcess);
764 if (RT_SUCCESS(rc2))
765 {
766 VGSvcVerbose(3, "[PID %RU32]: Processing outstanding requests ...\n", pProcess->uPID);
767
768 /* Process all pending requests (but don't wait for new ones). */
769 Assert(pProcess->hReqQueue != NIL_RTREQQUEUE);
770 rc2 = RTReqQueueProcess(pProcess->hReqQueue, 0 /* No timeout */);
771 if ( RT_FAILURE(rc2)
772 && rc2 != VERR_TIMEOUT)
773 VGSvcError("[PID %RU32]: Processing outstanding requests failed with with rc=%Rrc\n", pProcess->uPID, rc2);
774
775 VGSvcVerbose(3, "[PID %RU32]: Processing outstanding requests done, rc=%Rrc\n", pProcess->uPID, rc2);
776
777 rc2 = vgsvcGstCtrlProcessUnlock(pProcess);
778 AssertRC(rc2);
779 }
780
781 /*
782 * If we don't have a client problem (RT_FAILURE(rc)) we'll reply to the
783 * clients exec packet now.
784 */
785 if (RT_SUCCESS(rc))
786 {
787 uint32_t uStatus = PROC_STS_UNDEFINED;
788 uint32_t fFlags = 0;
789
790 if ( fProcessTimedOut && !fProcessAlive && MsProcessKilled != UINT64_MAX)
791 {
792 VGSvcVerbose(3, "[PID %RU32]: Timed out and got killed\n", pProcess->uPID);
793 uStatus = PROC_STS_TOK;
794 }
795 else if (fProcessTimedOut && fProcessAlive && MsProcessKilled != UINT64_MAX)
796 {
797 VGSvcVerbose(3, "[PID %RU32]: Timed out and did *not* get killed\n", pProcess->uPID);
798 uStatus = PROC_STS_TOA;
799 }
800 else if (pProcess->fShutdown && (fProcessAlive || MsProcessKilled != UINT64_MAX))
801 {
802 VGSvcVerbose(3, "[PID %RU32]: Got terminated because system/service is about to shutdown\n", pProcess->uPID);
803 uStatus = PROC_STS_DWN; /* Service is stopping, process was killed. */
804 fFlags = pProcess->StartupInfo.uFlags; /* Return handed-in execution flags back to the host. */
805 }
806 else if (fProcessAlive)
807 VGSvcError("[PID %RU32]: Is alive when it should not!\n", pProcess->uPID);
808 else if (MsProcessKilled != UINT64_MAX)
809 VGSvcError("[PID %RU32]: Has been killed when it should not!\n", pProcess->uPID);
810 else if (ProcessStatus.enmReason == RTPROCEXITREASON_NORMAL)
811 {
812 VGSvcVerbose(3, "[PID %RU32]: Ended with RTPROCEXITREASON_NORMAL (Exit code: %d)\n",
813 pProcess->uPID, ProcessStatus.iStatus);
814 uStatus = PROC_STS_TEN;
815 fFlags = ProcessStatus.iStatus;
816 }
817 else if (ProcessStatus.enmReason == RTPROCEXITREASON_SIGNAL)
818 {
819 VGSvcVerbose(3, "[PID %RU32]: Ended with RTPROCEXITREASON_SIGNAL (Signal: %u)\n",
820 pProcess->uPID, ProcessStatus.iStatus);
821 uStatus = PROC_STS_TES;
822 fFlags = ProcessStatus.iStatus;
823 }
824 else if (ProcessStatus.enmReason == RTPROCEXITREASON_ABEND)
825 {
826 /* ProcessStatus.iStatus will be undefined. */
827 VGSvcVerbose(3, "[PID %RU32]: Ended with RTPROCEXITREASON_ABEND\n", pProcess->uPID);
828 uStatus = PROC_STS_TEA;
829 fFlags = ProcessStatus.iStatus;
830 }
831 else
832 VGSvcVerbose(1, "[PID %RU32]: Handling process status %u not implemented\n", pProcess->uPID, ProcessStatus.enmReason);
833 VGSvcVerbose(2, "[PID %RU32]: Ended, ClientID=%u, CID=%u, Status=%u, Flags=0x%x\n",
834 pProcess->uPID, pProcess->uClientID, pProcess->uContextID, uStatus, fFlags);
835
836 VBGLR3GUESTCTRLCMDCTX ctxEnd = { pProcess->uClientID, pProcess->uContextID };
837 rc2 = VbglR3GuestCtrlProcCbStatus(&ctxEnd, pProcess->uPID, uStatus, fFlags, NULL /* pvData */, 0 /* cbData */);
838 if ( RT_FAILURE(rc2)
839 && rc2 == VERR_NOT_FOUND)
840 VGSvcError("[PID %RU32]: Error reporting final status to host; rc=%Rrc\n", pProcess->uPID, rc2);
841 }
842
843 VGSvcVerbose(3, "[PID %RU32]: Process loop returned with rc=%Rrc\n", pProcess->uPID, rc);
844 return rc;
845}
846
847
848/**
849 * Initializes a pipe's handle and pipe object.
850 *
851 * @return IPRT status code.
852 * @param ph The pipe's handle to initialize.
853 * @param phPipe The pipe's object to initialize.
854 */
855static int vgsvcGstCtrlProcessInitPipe(PRTHANDLE ph, PRTPIPE phPipe)
856{
857 AssertPtrReturn(ph, VERR_INVALID_PARAMETER);
858 AssertPtrReturn(phPipe, VERR_INVALID_PARAMETER);
859
860 ph->enmType = RTHANDLETYPE_PIPE;
861 ph->u.hPipe = NIL_RTPIPE;
862 *phPipe = NIL_RTPIPE;
863
864 return VINF_SUCCESS;
865}
866
867
868/**
869 * Sets up the redirection / pipe / nothing for one of the standard handles.
870 *
871 * @returns IPRT status code. No client replies made.
872 * @param pszHowTo How to set up this standard handle.
873 * @param fd Which standard handle it is (0 == stdin, 1 ==
874 * stdout, 2 == stderr).
875 * @param ph The generic handle that @a pph may be set
876 * pointing to. Always set.
877 * @param pph Pointer to the RTProcCreateExec argument.
878 * Always set.
879 * @param phPipe Where to return the end of the pipe that we
880 * should service.
881 */
882static int vgsvcGstCtrlProcessSetupPipe(const char *pszHowTo, int fd, PRTHANDLE ph, PRTHANDLE *pph, PRTPIPE phPipe)
883{
884 AssertPtrReturn(ph, VERR_INVALID_POINTER);
885 AssertPtrReturn(pph, VERR_INVALID_POINTER);
886 AssertPtrReturn(phPipe, VERR_INVALID_POINTER);
887
888 int rc;
889
890 ph->enmType = RTHANDLETYPE_PIPE;
891 ph->u.hPipe = NIL_RTPIPE;
892 *pph = NULL;
893 *phPipe = NIL_RTPIPE;
894
895 if (!strcmp(pszHowTo, "|"))
896 {
897 /*
898 * Setup a pipe for forwarding to/from the client.
899 * The ph union struct will be filled with a pipe read/write handle
900 * to represent the "other" end to phPipe.
901 */
902 if (fd == 0) /* stdin? */
903 {
904 /* Connect a wrtie pipe specified by phPipe to stdin. */
905 rc = RTPipeCreate(&ph->u.hPipe, phPipe, RTPIPE_C_INHERIT_READ);
906 }
907 else /* stdout or stderr. */
908 {
909 /* Connect a read pipe specified by phPipe to stdout or stderr. */
910 rc = RTPipeCreate(phPipe, &ph->u.hPipe, RTPIPE_C_INHERIT_WRITE);
911 }
912
913 if (RT_FAILURE(rc))
914 return rc;
915
916 ph->enmType = RTHANDLETYPE_PIPE;
917 *pph = ph;
918 }
919 else if (!strcmp(pszHowTo, "/dev/null"))
920 {
921 /*
922 * Redirect to/from /dev/null.
923 */
924 RTFILE hFile;
925 rc = RTFileOpenBitBucket(&hFile, fd == 0 ? RTFILE_O_READ : RTFILE_O_WRITE);
926 if (RT_FAILURE(rc))
927 return rc;
928
929 ph->enmType = RTHANDLETYPE_FILE;
930 ph->u.hFile = hFile;
931 *pph = ph;
932 }
933 else /* Add other piping stuff here. */
934 rc = VINF_SUCCESS; /* Same as parent (us). */
935
936 return rc;
937}
938
939
940/**
941 * Expands a file name / path to its real content. This only works on Windows
942 * for now (e.g. translating "%TEMP%\foo.exe" to "C:\Windows\Temp" when starting
943 * with system / administrative rights).
944 *
945 * @return IPRT status code.
946 * @param pszPath Path to resolve.
947 * @param pszExpanded Pointer to string to store the resolved path in.
948 * @param cbExpanded Size (in bytes) of string to store the resolved path.
949 */
950static int vgsvcGstCtrlProcessMakeFullPath(const char *pszPath, char *pszExpanded, size_t cbExpanded)
951{
952 int rc = VINF_SUCCESS;
953/** @todo r=bird: This feature shall be made optional, i.e. require a
954 * flag to be passed down. Further, it shall work on the environment
955 * block of the new process (i.e. include env changes passed down from
956 * the caller). I would also suggest using the unix variable expansion
957 * syntax, not the DOS one.
958 *
959 * Since this currently not available on non-windows guests, I suggest
960 * we disable it until such a time as it is implemented correctly. */
961#ifdef RT_OS_WINDOWS
962 if (!ExpandEnvironmentStrings(pszPath, pszExpanded, (DWORD)cbExpanded))
963 rc = RTErrConvertFromWin32(GetLastError());
964#else
965 /* No expansion for non-Windows yet. */
966 rc = RTStrCopy(pszExpanded, cbExpanded, pszPath);
967#endif
968#ifdef DEBUG
969 VGSvcVerbose(3, "vgsvcGstCtrlProcessMakeFullPath: %s -> %s\n", pszPath, pszExpanded);
970#endif
971 return rc;
972}
973
974
975/**
976 * Resolves the full path of a specified executable name. This function also
977 * resolves internal VBoxService tools to its appropriate executable path + name if
978 * VBOXSERVICE_NAME is specified as pszFileName.
979 *
980 * @return IPRT status code.
981 * @param pszFileName File name to resolve.
982 * @param pszResolved Pointer to a string where the resolved file name will be stored.
983 * @param cbResolved Size (in bytes) of resolved file name string.
984 */
985static int vgsvcGstCtrlProcessResolveExecutable(const char *pszFileName, char *pszResolved, size_t cbResolved)
986{
987 AssertPtrReturn(pszFileName, VERR_INVALID_POINTER);
988 AssertPtrReturn(pszResolved, VERR_INVALID_POINTER);
989 AssertReturn(cbResolved, VERR_INVALID_PARAMETER);
990
991 int rc = VINF_SUCCESS;
992
993 char szPathToResolve[RTPATH_MAX];
994 if ( (g_pszProgName && (RTStrICmp(pszFileName, g_pszProgName) == 0))
995 || !RTStrICmp(pszFileName, VBOXSERVICE_NAME))
996 {
997 /* Resolve executable name of this process. */
998 if (!RTProcGetExecutablePath(szPathToResolve, sizeof(szPathToResolve)))
999 rc = VERR_FILE_NOT_FOUND;
1000 }
1001 else
1002 {
1003 /* Take the raw argument to resolve. */
1004 rc = RTStrCopy(szPathToResolve, sizeof(szPathToResolve), pszFileName);
1005 }
1006
1007 if (RT_SUCCESS(rc))
1008 {
1009 rc = vgsvcGstCtrlProcessMakeFullPath(szPathToResolve, pszResolved, cbResolved);
1010 if (RT_SUCCESS(rc))
1011 VGSvcVerbose(3, "Looked up executable: %s -> %s\n", pszFileName, pszResolved);
1012 }
1013
1014 if (RT_FAILURE(rc))
1015 VGSvcError("Failed to lookup executable '%s' with rc=%Rrc\n", pszFileName, rc);
1016 return rc;
1017}
1018
1019
1020/**
1021 * Constructs the argv command line by resolving environment variables
1022 * and relative paths.
1023 *
1024 * @return IPRT status code.
1025 * @param pszArgv0 First argument (argv0), either original or modified version. Optional.
1026 * @param papszArgs Original argv command line from the host, starting at argv[1].
1027 * @param fFlags The process creation flags pass to us from the host.
1028 * @param ppapszArgv Pointer to a pointer with the new argv command line.
1029 * Needs to be freed with RTGetOptArgvFree.
1030 */
1031static int vgsvcGstCtrlProcessAllocateArgv(const char *pszArgv0, const char * const *papszArgs, uint32_t fFlags,
1032 char ***ppapszArgv)
1033{
1034 AssertPtrReturn(ppapszArgv, VERR_INVALID_POINTER);
1035
1036 VGSvcVerbose(3, "VGSvcGstCtrlProcessPrepareArgv: pszArgv0=%p, papszArgs=%p, fFlags=%#x, ppapszArgv=%p\n",
1037 pszArgv0, papszArgs, fFlags, ppapszArgv);
1038
1039 int rc = VINF_SUCCESS;
1040 uint32_t cArgs;
1041 for (cArgs = 0; papszArgs[cArgs]; cArgs++)
1042 {
1043 if (cArgs >= UINT32_MAX - 2)
1044 return VERR_BUFFER_OVERFLOW;
1045 }
1046
1047 /* Allocate new argv vector (adding + 2 for argv0 + termination). */
1048 size_t cbSize = (cArgs + 2) * sizeof(char *);
1049 char **papszNewArgv = (char **)RTMemAlloc(cbSize);
1050 if (!papszNewArgv)
1051 return VERR_NO_MEMORY;
1052
1053#ifdef DEBUG
1054 VGSvcVerbose(3, "VGSvcGstCtrlProcessAllocateArgv: cbSize=%RU32, cArgs=%RU32\n", cbSize, cArgs);
1055#endif
1056
1057 /* HACK ALERT! Since we still don't allow the user to really specify the first
1058 argument separately from the executable image, we have to fudge
1059 a little in the unquoted argument case to deal with executables
1060 containing spaces. */
1061 /** @todo Fix the stupid host/guest protocol so the user can do this for us! */
1062 if ( !(fFlags & EXECUTEPROCESSFLAG_UNQUOTED_ARGS)
1063 || !strpbrk(pszArgv0, " \t\n\r")
1064 || pszArgv0[0] == '"')
1065 rc = RTStrDupEx(&papszNewArgv[0], pszArgv0);
1066 else
1067 {
1068 size_t cchArgv0 = strlen(pszArgv0);
1069 rc = RTStrAllocEx(&papszNewArgv[0], 1 + cchArgv0 + 1 + 1);
1070 if (RT_SUCCESS(rc))
1071 {
1072 char *pszDst = papszNewArgv[0];
1073 *pszDst++ = '"';
1074 memcpy(pszDst, pszArgv0, cchArgv0);
1075 pszDst += cchArgv0;
1076 *pszDst++ = '"';
1077 *pszDst = '\0';
1078 }
1079 }
1080 if (RT_SUCCESS(rc))
1081 {
1082 size_t i;
1083 for (i = 0; i < cArgs; i++)
1084 {
1085 char *pszArg;
1086#if 0 /* Arguments expansion -- untested. */
1087 if (fFlags & EXECUTEPROCESSFLAG_EXPAND_ARGUMENTS)
1088 {
1089/** @todo r=bird: If you want this, we need a generic implementation, preferably in RTEnv or somewhere like that. The marking
1090 * up of the variables must be the same on all platforms. */
1091 /* According to MSDN the limit on older Windows version is 32K, whereas
1092 * Vista+ there are no limits anymore. We still stick to 4K. */
1093 char szExpanded[_4K];
1094# ifdef RT_OS_WINDOWS
1095 if (!ExpandEnvironmentStrings(papszArgs[i], szExpanded, sizeof(szExpanded)))
1096 rc = RTErrConvertFromWin32(GetLastError());
1097# else
1098 /* No expansion for non-Windows yet. */
1099 rc = RTStrCopy(papszArgs[i], sizeof(szExpanded), szExpanded);
1100# endif
1101 if (RT_SUCCESS(rc))
1102 rc = RTStrDupEx(&pszArg, szExpanded);
1103 }
1104 else
1105#endif
1106 rc = RTStrDupEx(&pszArg, papszArgs[i]);
1107
1108 if (RT_FAILURE(rc))
1109 break;
1110
1111 papszNewArgv[i + 1] = pszArg;
1112 }
1113
1114 if (RT_SUCCESS(rc))
1115 {
1116 /* Terminate array. */
1117 papszNewArgv[cArgs + 1] = NULL;
1118
1119 *ppapszArgv = papszNewArgv;
1120 return VINF_SUCCESS;
1121 }
1122
1123 /* Failed, bail out. */
1124 for (; i > 0; i--)
1125 RTStrFree(papszNewArgv[i]);
1126 }
1127 RTMemFree(papszNewArgv);
1128 return rc;
1129}
1130
1131
1132/**
1133 * Assigns a valid PID to a guest control thread and also checks if there already was
1134 * another (stale) guest process which was using that PID before and destroys it.
1135 *
1136 * @return IPRT status code.
1137 * @param pProcess Process to assign PID to.
1138 * @param uPID PID to assign to the specified guest control execution thread.
1139 */
1140static int vgsvcGstCtrlProcessAssignPID(PVBOXSERVICECTRLPROCESS pProcess, uint32_t uPID)
1141{
1142 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
1143 AssertReturn(uPID, VERR_INVALID_PARAMETER);
1144
1145 AssertPtr(pProcess->pSession);
1146 int rc = RTCritSectEnter(&pProcess->pSession->CritSect);
1147 if (RT_SUCCESS(rc))
1148 {
1149 /* Search old threads using the desired PID and shut them down completely -- it's
1150 * not used anymore. */
1151 PVBOXSERVICECTRLPROCESS pProcessCur;
1152 bool fTryAgain;
1153 do
1154 {
1155 fTryAgain = false;
1156 RTListForEach(&pProcess->pSession->lstProcesses, pProcessCur, VBOXSERVICECTRLPROCESS, Node)
1157 {
1158 if (pProcessCur->uPID == uPID)
1159 {
1160 Assert(pProcessCur != pProcess); /* can't happen */
1161 uint32_t uTriedPID = uPID;
1162 uPID += 391939;
1163 VGSvcVerbose(2, "PID %RU32 was used before (process %p), trying again with %RU32 ...\n",
1164 uTriedPID, pProcessCur, uPID);
1165 fTryAgain = true;
1166 break;
1167 }
1168 }
1169 } while (fTryAgain);
1170
1171 /* Assign PID to current thread. */
1172 pProcess->uPID = uPID;
1173
1174 rc = RTCritSectLeave(&pProcess->pSession->CritSect);
1175 AssertRC(rc);
1176 }
1177
1178 return rc;
1179}
1180
1181
1182static void vgsvcGstCtrlProcessFreeArgv(char **papszArgv)
1183{
1184 if (papszArgv)
1185 {
1186 size_t i = 0;
1187 while (papszArgv[i])
1188 RTStrFree(papszArgv[i++]);
1189 RTMemFree(papszArgv);
1190 }
1191}
1192
1193
1194/**
1195 * Helper function to create/start a process on the guest.
1196 *
1197 * @return IPRT status code.
1198 * @param pszExec Full qualified path of process to start (without arguments).
1199 * @param papszArgs Pointer to array of command line arguments.
1200 * @param hEnv Handle to environment block to use.
1201 * @param fFlags Process execution flags.
1202 * @param phStdIn Handle for the process' stdin pipe.
1203 * @param phStdOut Handle for the process' stdout pipe.
1204 * @param phStdErr Handle for the process' stderr pipe.
1205 * @param pszAsUser User name (account) to start the process under.
1206 * @param pszPassword Password of the specified user.
1207 * @param pszDomain Domain to use for authentication.
1208 * @param phProcess Pointer which will receive the process handle after
1209 * successful process start.
1210 */
1211static int vgsvcGstCtrlProcessCreateProcess(const char *pszExec, const char * const *papszArgs, RTENV hEnv, uint32_t fFlags,
1212 PCRTHANDLE phStdIn, PCRTHANDLE phStdOut, PCRTHANDLE phStdErr,
1213 const char *pszAsUser, const char *pszPassword, const char *pszDomain,
1214 PRTPROCESS phProcess)
1215{
1216 AssertPtrReturn(pszExec, VERR_INVALID_PARAMETER);
1217 AssertPtrReturn(papszArgs, VERR_INVALID_PARAMETER);
1218 /* phStdIn is optional. */
1219 /* phStdOut is optional. */
1220 /* phStdErr is optional. */
1221 /* pszPassword is optional. */
1222 /* pszDomain is optional. */
1223 AssertPtrReturn(phProcess, VERR_INVALID_PARAMETER);
1224
1225 int rc = VINF_SUCCESS;
1226 char szExecExp[RTPATH_MAX];
1227
1228#ifdef DEBUG
1229 /* Never log this in release mode! */
1230 VGSvcVerbose(4, "pszUser=%s, pszPassword=%s, pszDomain=%s\n", pszAsUser, pszPassword, pszDomain);
1231#endif
1232
1233#ifdef RT_OS_WINDOWS
1234 /*
1235 * If sysprep should be executed do this in the context of VBoxService, which
1236 * (usually, if started by SCM) has administrator rights. Because of that a UI
1237 * won't be shown (doesn't have a desktop).
1238 */
1239 if (!RTStrICmp(pszExec, "sysprep"))
1240 {
1241 /* Use a predefined sysprep path as default. */
1242 char szSysprepCmd[RTPATH_MAX] = "C:\\sysprep\\sysprep.exe";
1243 /** @todo Check digital signature of file above before executing it? */
1244
1245 /*
1246 * On Windows Vista (and up) sysprep is located in "system32\\Sysprep\\sysprep.exe",
1247 * so detect the OS and use a different path.
1248 */
1249 OSVERSIONINFOEX OSInfoEx;
1250 RT_ZERO(OSInfoEx);
1251 OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
1252 BOOL fRet = GetVersionEx((LPOSVERSIONINFO) &OSInfoEx);
1253 if ( fRet
1254 && OSInfoEx.dwPlatformId == VER_PLATFORM_WIN32_NT
1255 && OSInfoEx.dwMajorVersion >= 6 /* Vista or later */)
1256 {
1257 rc = RTEnvGetEx(RTENV_DEFAULT, "windir", szSysprepCmd, sizeof(szSysprepCmd), NULL);
1258#ifndef RT_ARCH_AMD64
1259 /* Don't execute 64-bit sysprep from a 32-bit service host! */
1260 char szSysWow64[RTPATH_MAX];
1261 if (RTStrPrintf(szSysWow64, sizeof(szSysWow64), "%s", szSysprepCmd))
1262 {
1263 rc = RTPathAppend(szSysWow64, sizeof(szSysWow64), "SysWow64");
1264 AssertRC(rc);
1265 }
1266 if ( RT_SUCCESS(rc)
1267 && RTPathExists(szSysWow64))
1268 VGSvcVerbose(0, "Warning: This service is 32-bit; could not execute sysprep on 64-bit OS!\n");
1269#endif
1270 if (RT_SUCCESS(rc))
1271 rc = RTPathAppend(szSysprepCmd, sizeof(szSysprepCmd), "system32\\Sysprep\\sysprep.exe");
1272 if (RT_SUCCESS(rc))
1273 RTPathChangeToDosSlashes(szSysprepCmd, false /* No forcing necessary */);
1274
1275 if (RT_FAILURE(rc))
1276 VGSvcError("Failed to detect sysrep location, rc=%Rrc\n", rc);
1277 }
1278 else if (!fRet)
1279 VGSvcError("Failed to retrieve OS information, last error=%ld\n", GetLastError());
1280
1281 VGSvcVerbose(3, "Sysprep executable is: %s\n", szSysprepCmd);
1282
1283 if (RT_SUCCESS(rc))
1284 {
1285 char **papszArgsExp;
1286 rc = vgsvcGstCtrlProcessAllocateArgv(szSysprepCmd /* argv0 */, papszArgs, fFlags, &papszArgsExp);
1287 if (RT_SUCCESS(rc))
1288 {
1289 /* As we don't specify credentials for the sysprep process, it will
1290 * run under behalf of the account VBoxService was started under, most
1291 * likely local system. */
1292 rc = RTProcCreateEx(szSysprepCmd, papszArgsExp, hEnv, 0 /* fFlags */,
1293 phStdIn, phStdOut, phStdErr, NULL /* pszAsUser */,
1294 NULL /* pszPassword */, phProcess);
1295 vgsvcGstCtrlProcessFreeArgv(papszArgsExp);
1296 }
1297 }
1298
1299 if (RT_FAILURE(rc))
1300 VGSvcVerbose(3, "Starting sysprep returned rc=%Rrc\n", rc);
1301
1302 return rc;
1303 }
1304#endif /* RT_OS_WINDOWS */
1305
1306#ifdef VBOX_WITH_VBOXSERVICE_TOOLBOX
1307 if (RTStrStr(pszExec, "vbox_") == pszExec)
1308 {
1309 /* We want to use the internal toolbox (all internal
1310 * tools are starting with "vbox_" (e.g. "vbox_cat"). */
1311 rc = vgsvcGstCtrlProcessResolveExecutable(VBOXSERVICE_NAME, szExecExp, sizeof(szExecExp));
1312 }
1313 else
1314 {
1315#endif
1316 /*
1317 * Do the environment variables expansion on executable and arguments.
1318 */
1319 rc = vgsvcGstCtrlProcessResolveExecutable(pszExec, szExecExp, sizeof(szExecExp));
1320#ifdef VBOX_WITH_VBOXSERVICE_TOOLBOX
1321 }
1322#endif
1323 if (RT_SUCCESS(rc))
1324 {
1325 char **papszArgsExp;
1326 /** @todo r-bird: pszExec != argv[0]! When are you going to get that?!? How many
1327 * times does this need to be pointed out? HOST/GUEST INTERFACE IS MISDESIGNED! */
1328 rc = vgsvcGstCtrlProcessAllocateArgv(pszExec /* Always use the unmodified executable name as argv0. */,
1329 papszArgs /* Append the rest of the argument vector (if any). */,
1330 fFlags, &papszArgsExp);
1331 if (RT_FAILURE(rc))
1332 {
1333 /* Don't print any arguments -- may contain passwords or other sensible data! */
1334 VGSvcError("Could not prepare arguments, rc=%Rrc\n", rc);
1335 }
1336 else
1337 {
1338 uint32_t uProcFlags = 0;
1339 if (fFlags)
1340 {
1341 if (fFlags & EXECUTEPROCESSFLAG_HIDDEN)
1342 uProcFlags |= RTPROC_FLAGS_HIDDEN;
1343 /** @todo Rename to EXECUTEPROCESSFLAG_PROFILE in next API change. */
1344 if (!(fFlags & EXECUTEPROCESSFLAG_NO_PROFILE))
1345 uProcFlags |= RTPROC_FLAGS_PROFILE;
1346 if (fFlags & EXECUTEPROCESSFLAG_UNQUOTED_ARGS)
1347 uProcFlags |= RTPROC_FLAGS_UNQUOTED_ARGS;
1348 }
1349
1350 /* If no user name specified run with current credentials (e.g.
1351 * full service/system rights). This is prohibited via official Main API!
1352 *
1353 * Otherwise use the RTPROC_FLAGS_SERVICE to use some special authentication
1354 * code (at least on Windows) for running processes as different users
1355 * started from our system service. */
1356 if (pszAsUser && *pszAsUser)
1357 uProcFlags |= RTPROC_FLAGS_SERVICE;
1358#ifdef DEBUG
1359 VGSvcVerbose(3, "Command: %s\n", szExecExp);
1360 for (size_t i = 0; papszArgsExp[i]; i++)
1361 VGSvcVerbose(3, "\targv[%ld]: %s\n", i, papszArgsExp[i]);
1362#endif
1363 VGSvcVerbose(3, "Starting process '%s' ...\n", szExecExp);
1364
1365 const char *pszUser;
1366#ifdef RT_OS_WINDOWS
1367 /* If a domain name is given, construct an UPN (User Principle Name) with
1368 * the domain name built-in, e.g. "[email protected]". */
1369 char *pszUserUPN = NULL;
1370 if ( pszDomain
1371 && strlen(pszDomain))
1372 {
1373 int cbUserUPN = RTStrAPrintf(&pszUserUPN, "%s@%s", pszAsUser, pszDomain);
1374 if (cbUserUPN > 0)
1375 {
1376 pszUser = pszUserUPN;
1377 VGSvcVerbose(3, "Using UPN: %s\n", pszUserUPN);
1378 }
1379 }
1380
1381 if (!pszUserUPN) /* Fallback */
1382#endif
1383 pszUser = pszAsUser;
1384
1385 /* Do normal execution. */
1386 rc = RTProcCreateEx(szExecExp, papszArgsExp, hEnv, uProcFlags,
1387 phStdIn, phStdOut, phStdErr,
1388 pszUser,
1389 pszPassword && *pszPassword ? pszPassword : NULL,
1390 phProcess);
1391#ifdef RT_OS_WINDOWS
1392 if (pszUserUPN)
1393 RTStrFree(pszUserUPN);
1394#endif
1395 VGSvcVerbose(3, "Starting process '%s' returned rc=%Rrc\n", szExecExp, rc);
1396
1397 vgsvcGstCtrlProcessFreeArgv(papszArgsExp);
1398 }
1399 }
1400 return rc;
1401}
1402
1403
1404#ifdef DEBUG
1405static int vgsvcGstCtrlProcessDumpToFile(const char *pszFileName, void *pvBuf, size_t cbBuf)
1406{
1407 AssertPtrReturn(pszFileName, VERR_INVALID_POINTER);
1408 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
1409
1410 if (!cbBuf)
1411 return VINF_SUCCESS;
1412
1413 char szFile[RTPATH_MAX];
1414
1415 int rc = RTPathTemp(szFile, sizeof(szFile));
1416 if (RT_SUCCESS(rc))
1417 rc = RTPathAppend(szFile, sizeof(szFile), pszFileName);
1418
1419 if (RT_SUCCESS(rc))
1420 {
1421 VGSvcVerbose(4, "Dumping %ld bytes to '%s'\n", cbBuf, szFile);
1422
1423 RTFILE fh;
1424 rc = RTFileOpen(&fh, szFile, RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE);
1425 if (RT_SUCCESS(rc))
1426 {
1427 rc = RTFileWrite(fh, pvBuf, cbBuf, NULL /* pcbWritten */);
1428 RTFileClose(fh);
1429 }
1430 }
1431
1432 return rc;
1433}
1434#endif /* DEBUG */
1435
1436
1437/**
1438 * The actual worker routine (loop) for a started guest process.
1439 *
1440 * @return IPRT status code.
1441 * @param pProcess The process we're servicing and monitoring.
1442 */
1443static int vgsvcGstCtrlProcessProcessWorker(PVBOXSERVICECTRLPROCESS pProcess)
1444{
1445 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
1446 VGSvcVerbose(3, "Thread of process pThread=0x%p = '%s' started\n", pProcess, pProcess->StartupInfo.szCmd);
1447
1448 int rc = VbglR3GuestCtrlConnect(&pProcess->uClientID);
1449 if (RT_FAILURE(rc))
1450 {
1451 VGSvcError("Process thread '%s' (%p) failed to connect to the guest control service, rc=%Rrc\n",
1452 pProcess->StartupInfo.szCmd, pProcess, rc);
1453 RTThreadUserSignal(RTThreadSelf());
1454 return rc;
1455 }
1456
1457 VGSvcVerbose(3, "Guest process '%s' got client ID=%u, flags=0x%x\n",
1458 pProcess->StartupInfo.szCmd, pProcess->uClientID, pProcess->StartupInfo.uFlags);
1459
1460 /* The process thread is not interested in receiving any commands;
1461 * tell the host service. */
1462 rc = VbglR3GuestCtrlMsgFilterSet(pProcess->uClientID, 0 /* Skip all */,
1463 0 /* Filter mask to add */, 0 /* Filter mask to remove */);
1464 if (RT_FAILURE(rc))
1465 {
1466 VGSvcError("Unable to set message filter, rc=%Rrc\n", rc);
1467 /* Non-critical. */
1468 }
1469
1470 rc = VGSvcGstCtrlSessionProcessAdd(pProcess->pSession, pProcess);
1471 if (RT_FAILURE(rc))
1472 {
1473 VGSvcError("Errorwhile adding guest process '%s' (%p) to session process list, rc=%Rrc\n",
1474 pProcess->StartupInfo.szCmd, pProcess, rc);
1475 RTThreadUserSignal(RTThreadSelf());
1476 return rc;
1477 }
1478
1479 bool fSignalled = false; /* Indicator whether we signalled the thread user event already. */
1480
1481 /*
1482 * Prepare argument list.
1483 */
1484 char **papszArgs;
1485 uint32_t uNumArgs = 0; /* Initialize in case of RTGetOptArgvFromString() is failing ... */
1486 rc = RTGetOptArgvFromString(&papszArgs, (int*)&uNumArgs,
1487 (pProcess->StartupInfo.uNumArgs > 0) ? pProcess->StartupInfo.szArgs : "",
1488 RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL);
1489 /* Did we get the same result? */
1490 Assert(pProcess->StartupInfo.uNumArgs == uNumArgs + 1 /* Take argv[0] into account */);
1491
1492 /*
1493 * Prepare environment variables list.
1494 */
1495/** @todo r=bird: you don't need to prepare this, do you? Why don't you replace
1496 * the brilliant RTStrAPrintf call with RTEnvPutEx and drop the papszEnv related code? */
1497 char **papszEnv = NULL;
1498 uint32_t uNumEnvVars = 0; /* Initialize in case of failing ... */
1499 if (RT_SUCCESS(rc))
1500 {
1501 /* Prepare environment list. */
1502 if (pProcess->StartupInfo.uNumEnvVars)
1503 {
1504 papszEnv = (char **)RTMemAlloc(pProcess->StartupInfo.uNumEnvVars * sizeof(char*));
1505 AssertPtr(papszEnv);
1506 uNumEnvVars = pProcess->StartupInfo.uNumEnvVars;
1507
1508 const char *pszCur = pProcess->StartupInfo.szEnv;
1509 uint32_t i = 0;
1510 uint32_t cbLen = 0;
1511 while (cbLen < pProcess->StartupInfo.cbEnv)
1512 {
1513 /* sanity check */
1514 if (i >= pProcess->StartupInfo.uNumEnvVars)
1515 {
1516 rc = VERR_INVALID_PARAMETER;
1517 break;
1518 }
1519 int cbStr = RTStrAPrintf(&papszEnv[i++], "%s", pszCur);
1520 if (cbStr < 0)
1521 {
1522 rc = VERR_NO_STR_MEMORY;
1523 break;
1524 }
1525 pszCur += cbStr + 1; /* Skip terminating '\0' */
1526 cbLen += cbStr + 1; /* Skip terminating '\0' */
1527 }
1528 Assert(i == pProcess->StartupInfo.uNumEnvVars);
1529 }
1530 }
1531
1532 /*
1533 * Create the environment.
1534 */
1535 RTENV hEnv;
1536 if (RT_SUCCESS(rc))
1537 rc = RTEnvClone(&hEnv, RTENV_DEFAULT);
1538 if (RT_SUCCESS(rc))
1539 {
1540 size_t i;
1541 for (i = 0; i < uNumEnvVars && papszEnv; i++)
1542 {
1543 rc = RTEnvPutEx(hEnv, papszEnv[i]);
1544 if (RT_FAILURE(rc))
1545 break;
1546 }
1547 if (RT_SUCCESS(rc))
1548 {
1549 /*
1550 * Setup the redirection of the standard stuff.
1551 */
1552 /** @todo consider supporting: gcc stuff.c >file 2>&1. */
1553 RTHANDLE hStdIn;
1554 PRTHANDLE phStdIn;
1555 rc = vgsvcGstCtrlProcessSetupPipe("|", 0 /*STDIN_FILENO*/,
1556 &hStdIn, &phStdIn, &pProcess->hPipeStdInW);
1557 if (RT_SUCCESS(rc))
1558 {
1559 RTHANDLE hStdOut;
1560 PRTHANDLE phStdOut;
1561 rc = vgsvcGstCtrlProcessSetupPipe( (pProcess->StartupInfo.uFlags & EXECUTEPROCESSFLAG_WAIT_STDOUT)
1562 ? "|" : "/dev/null",
1563 1 /*STDOUT_FILENO*/,
1564 &hStdOut, &phStdOut, &pProcess->hPipeStdOutR);
1565 if (RT_SUCCESS(rc))
1566 {
1567 RTHANDLE hStdErr;
1568 PRTHANDLE phStdErr;
1569 rc = vgsvcGstCtrlProcessSetupPipe( (pProcess->StartupInfo.uFlags & EXECUTEPROCESSFLAG_WAIT_STDERR)
1570 ? "|" : "/dev/null",
1571 2 /*STDERR_FILENO*/,
1572 &hStdErr, &phStdErr, &pProcess->hPipeStdErrR);
1573 if (RT_SUCCESS(rc))
1574 {
1575 /*
1576 * Create a poll set for the pipes and let the
1577 * transport layer add stuff to it as well.
1578 */
1579 rc = RTPollSetCreate(&pProcess->hPollSet);
1580 if (RT_SUCCESS(rc))
1581 {
1582 uint32_t uFlags = RTPOLL_EVT_ERROR;
1583#if 0
1584 /* Add reading event to pollset to get some more information. */
1585 uFlags |= RTPOLL_EVT_READ;
1586#endif
1587 /* Stdin. */
1588 if (RT_SUCCESS(rc))
1589 rc = RTPollSetAddPipe(pProcess->hPollSet,
1590 pProcess->hPipeStdInW, RTPOLL_EVT_ERROR, VBOXSERVICECTRLPIPEID_STDIN);
1591 /* Stdout. */
1592 if (RT_SUCCESS(rc))
1593 rc = RTPollSetAddPipe(pProcess->hPollSet,
1594 pProcess->hPipeStdOutR, uFlags, VBOXSERVICECTRLPIPEID_STDOUT);
1595 /* Stderr. */
1596 if (RT_SUCCESS(rc))
1597 rc = RTPollSetAddPipe(pProcess->hPollSet,
1598 pProcess->hPipeStdErrR, uFlags, VBOXSERVICECTRLPIPEID_STDERR);
1599 /* IPC notification pipe. */
1600 if (RT_SUCCESS(rc))
1601 rc = RTPipeCreate(&pProcess->hNotificationPipeR, &pProcess->hNotificationPipeW, 0 /* Flags */);
1602 if (RT_SUCCESS(rc))
1603 rc = RTPollSetAddPipe(pProcess->hPollSet,
1604 pProcess->hNotificationPipeR, RTPOLL_EVT_READ, VBOXSERVICECTRLPIPEID_IPC_NOTIFY);
1605 if (RT_SUCCESS(rc))
1606 {
1607 AssertPtr(pProcess->pSession);
1608 bool fNeedsImpersonation = !(pProcess->pSession->fFlags & VBOXSERVICECTRLSESSION_FLAG_SPAWN);
1609
1610 rc = vgsvcGstCtrlProcessCreateProcess(pProcess->StartupInfo.szCmd, papszArgs, hEnv,
1611 pProcess->StartupInfo.uFlags,
1612 phStdIn, phStdOut, phStdErr,
1613 fNeedsImpersonation ? pProcess->StartupInfo.szUser : NULL,
1614 fNeedsImpersonation ? pProcess->StartupInfo.szPassword : NULL,
1615 fNeedsImpersonation ? pProcess->StartupInfo.szDomain : NULL,
1616 &pProcess->hProcess);
1617 if (RT_FAILURE(rc))
1618 VGSvcError("Error starting process, rc=%Rrc\n", rc);
1619 /*
1620 * Tell the session thread that it can continue
1621 * spawning guest processes. This needs to be done after the new
1622 * process has been started because otherwise signal handling
1623 * on (Open) Solaris does not work correctly (see @bugref{5068}).
1624 */
1625 int rc2 = RTThreadUserSignal(RTThreadSelf());
1626 if (RT_SUCCESS(rc))
1627 rc = rc2;
1628 fSignalled = true;
1629
1630 if (RT_SUCCESS(rc))
1631 {
1632 /*
1633 * Close the child ends of any pipes and redirected files.
1634 */
1635 rc2 = RTHandleClose(phStdIn); AssertRC(rc2);
1636 phStdIn = NULL;
1637 rc2 = RTHandleClose(phStdOut); AssertRC(rc2);
1638 phStdOut = NULL;
1639 rc2 = RTHandleClose(phStdErr); AssertRC(rc2);
1640 phStdErr = NULL;
1641
1642 /* Enter the process main loop. */
1643 rc = vgsvcGstCtrlProcessProcLoop(pProcess);
1644
1645 /*
1646 * The handles that are no longer in the set have
1647 * been closed by the above call in order to prevent
1648 * the guest from getting stuck accessing them.
1649 * So, NIL the handles to avoid closing them again.
1650 */
1651 if (RT_FAILURE(RTPollSetQueryHandle(pProcess->hPollSet,
1652 VBOXSERVICECTRLPIPEID_IPC_NOTIFY, NULL)))
1653 {
1654 pProcess->hNotificationPipeR = NIL_RTPIPE;
1655 pProcess->hNotificationPipeW = NIL_RTPIPE;
1656 }
1657 if (RT_FAILURE(RTPollSetQueryHandle(pProcess->hPollSet,
1658 VBOXSERVICECTRLPIPEID_STDERR, NULL)))
1659 pProcess->hPipeStdErrR = NIL_RTPIPE;
1660 if (RT_FAILURE(RTPollSetQueryHandle(pProcess->hPollSet,
1661 VBOXSERVICECTRLPIPEID_STDOUT, NULL)))
1662 pProcess->hPipeStdOutR = NIL_RTPIPE;
1663 if (RT_FAILURE(RTPollSetQueryHandle(pProcess->hPollSet,
1664 VBOXSERVICECTRLPIPEID_STDIN, NULL)))
1665 pProcess->hPipeStdInW = NIL_RTPIPE;
1666 }
1667 }
1668 RTPollSetDestroy(pProcess->hPollSet);
1669
1670 RTPipeClose(pProcess->hNotificationPipeR);
1671 pProcess->hNotificationPipeR = NIL_RTPIPE;
1672 RTPipeClose(pProcess->hNotificationPipeW);
1673 pProcess->hNotificationPipeW = NIL_RTPIPE;
1674 }
1675 RTPipeClose(pProcess->hPipeStdErrR);
1676 pProcess->hPipeStdErrR = NIL_RTPIPE;
1677 RTHandleClose(phStdErr);
1678 if (phStdErr)
1679 RTHandleClose(phStdErr);
1680 }
1681 RTPipeClose(pProcess->hPipeStdOutR);
1682 pProcess->hPipeStdOutR = NIL_RTPIPE;
1683 RTHandleClose(&hStdOut);
1684 if (phStdOut)
1685 RTHandleClose(phStdOut);
1686 }
1687 RTPipeClose(pProcess->hPipeStdInW);
1688 pProcess->hPipeStdInW = NIL_RTPIPE;
1689 RTHandleClose(phStdIn);
1690 }
1691 }
1692 RTEnvDestroy(hEnv);
1693 }
1694
1695 if (pProcess->uClientID)
1696 {
1697 if (RT_FAILURE(rc))
1698 {
1699 VBGLR3GUESTCTRLCMDCTX ctx = { pProcess->uClientID, pProcess->uContextID };
1700 int rc2 = VbglR3GuestCtrlProcCbStatus(&ctx,
1701 pProcess->uPID, PROC_STS_ERROR, rc,
1702 NULL /* pvData */, 0 /* cbData */);
1703 if ( RT_FAILURE(rc2)
1704 && rc2 != VERR_NOT_FOUND)
1705 VGSvcError("[PID %RU32]: Could not report process failure error; rc=%Rrc (process error %Rrc)\n",
1706 pProcess->uPID, rc2, rc);
1707 }
1708
1709 /* Disconnect this client from the guest control service. This also cancels all
1710 * outstanding host requests. */
1711 VGSvcVerbose(3, "[PID %RU32]: Disconnecting (client ID=%u) ...\n", pProcess->uPID, pProcess->uClientID);
1712 VbglR3GuestCtrlDisconnect(pProcess->uClientID);
1713 pProcess->uClientID = 0;
1714 }
1715
1716 /* Free argument + environment variable lists. */
1717 if (uNumEnvVars)
1718 {
1719 for (uint32_t i = 0; i < uNumEnvVars; i++)
1720 RTStrFree(papszEnv[i]);
1721 RTMemFree(papszEnv);
1722 }
1723 if (uNumArgs)
1724 RTGetOptArgvFree(papszArgs);
1725
1726 /*
1727 * If something went wrong signal the user event so that others don't wait
1728 * forever on this thread.
1729 */
1730 if (RT_FAILURE(rc) && !fSignalled)
1731 RTThreadUserSignal(RTThreadSelf());
1732
1733 VGSvcVerbose(3, "[PID %RU32]: Thread of process '%s' ended with rc=%Rrc\n",
1734 pProcess->uPID, pProcess->StartupInfo.szCmd, rc);
1735
1736 /* Finally, update stopped status. */
1737 ASMAtomicXchgBool(&pProcess->fStopped, true);
1738
1739 return rc;
1740}
1741
1742
1743static int vgsvcGstCtrlProcessLock(PVBOXSERVICECTRLPROCESS pProcess)
1744{
1745 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
1746 int rc = RTCritSectEnter(&pProcess->CritSect);
1747 AssertRC(rc);
1748 return rc;
1749}
1750
1751
1752/**
1753 * Thread main routine for a started process.
1754 *
1755 * @return IPRT status code.
1756 * @param hThreadSelf The thread handle.
1757 * @param pvUser Pointer to a VBOXSERVICECTRLPROCESS structure.
1758 *
1759 */
1760static DECLCALLBACK(int) vgsvcGstCtrlProcessThread(RTTHREAD hThreadSelf, void *pvUser)
1761{
1762 PVBOXSERVICECTRLPROCESS pProcess = (PVBOXSERVICECTRLPROCESS)pvUser;
1763 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
1764 return vgsvcGstCtrlProcessProcessWorker(pProcess);
1765}
1766
1767
1768static int vgsvcGstCtrlProcessUnlock(PVBOXSERVICECTRLPROCESS pProcess)
1769{
1770 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
1771 int rc = RTCritSectLeave(&pProcess->CritSect);
1772 AssertRC(rc);
1773 return rc;
1774}
1775
1776
1777/**
1778 * Executes (starts) a process on the guest. This causes a new thread to be created
1779 * so that this function will not block the overall program execution.
1780 *
1781 * @return IPRT status code.
1782 * @param pSession Guest session.
1783 * @param pStartupInfo Startup info.
1784 * @param uContextID Context ID to associate the process to start with.
1785 */
1786int VGSvcGstCtrlProcessStart(const PVBOXSERVICECTRLSESSION pSession,
1787 const PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo, uint32_t uContextID)
1788{
1789 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
1790 AssertPtrReturn(pStartupInfo, VERR_INVALID_POINTER);
1791
1792 /*
1793 * Allocate new thread data and assign it to our thread list.
1794 */
1795 PVBOXSERVICECTRLPROCESS pProcess = (PVBOXSERVICECTRLPROCESS)RTMemAlloc(sizeof(VBOXSERVICECTRLPROCESS));
1796 if (!pProcess)
1797 return VERR_NO_MEMORY;
1798
1799 int rc = vgsvcGstCtrlProcessInit(pProcess, pSession, pStartupInfo, uContextID);
1800 if (RT_SUCCESS(rc))
1801 {
1802 static uint32_t s_uCtrlExecThread = 0;
1803 if (s_uCtrlExecThread++ == UINT32_MAX)
1804 s_uCtrlExecThread = 0; /* Wrap around to not let IPRT freak out. */
1805 rc = RTThreadCreateF(&pProcess->Thread, vgsvcGstCtrlProcessThread,
1806 pProcess /*pvUser*/, 0 /*cbStack*/,
1807 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "gctl%u", s_uCtrlExecThread);
1808 if (RT_FAILURE(rc))
1809 {
1810 VGSvcError("Creating thread for guest process '%s' failed: rc=%Rrc, pProcess=%p\n",
1811 pStartupInfo->szCmd, rc, pProcess);
1812
1813 VGSvcGstCtrlProcessFree(pProcess);
1814 }
1815 else
1816 {
1817 VGSvcVerbose(4, "Waiting for thread to initialize ...\n");
1818
1819 /* Wait for the thread to initialize. */
1820 rc = RTThreadUserWait(pProcess->Thread, 60 * 1000 /* 60 seconds max. */);
1821 AssertRC(rc);
1822 if ( ASMAtomicReadBool(&pProcess->fShutdown)
1823 || RT_FAILURE(rc))
1824 {
1825 VGSvcError("Thread for process '%s' failed to start, rc=%Rrc\n", pStartupInfo->szCmd, rc);
1826 VGSvcGstCtrlProcessFree(pProcess);
1827 }
1828 else
1829 {
1830 ASMAtomicXchgBool(&pProcess->fStarted, true);
1831 }
1832 }
1833 }
1834
1835 return rc;
1836}
1837
1838
1839static DECLCALLBACK(int) vgsvcGstCtrlProcessOnInput(PVBOXSERVICECTRLPROCESS pThis,
1840 const PVBGLR3GUESTCTRLCMDCTX pHostCtx,
1841 bool fPendingClose, void *pvBuf, uint32_t cbBuf)
1842{
1843 AssertPtrReturn(pThis, VERR_INVALID_POINTER);
1844 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
1845
1846 int rc;
1847
1848 size_t cbWritten = 0;
1849 if (pvBuf && cbBuf)
1850 {
1851 if (pThis->hPipeStdInW != NIL_RTPIPE)
1852 rc = RTPipeWrite(pThis->hPipeStdInW, pvBuf, cbBuf, &cbWritten);
1853 else
1854 rc = VINF_EOF;
1855 }
1856 else
1857 rc = VERR_INVALID_PARAMETER;
1858
1859 /*
1860 * If this is the last write + we have really have written all data
1861 * we need to close the stdin pipe on our end and remove it from
1862 * the poll set.
1863 */
1864 if ( fPendingClose
1865 && cbBuf == cbWritten)
1866 {
1867 int rc2 = vgsvcGstCtrlProcessPollsetCloseInput(pThis, &pThis->hPipeStdInW);
1868 if (RT_SUCCESS(rc))
1869 rc = rc2;
1870 }
1871
1872 uint32_t uStatus = INPUT_STS_UNDEFINED; /* Status to send back to the host. */
1873 uint32_t fFlags = 0; /* No flags at the moment. */
1874 if (RT_SUCCESS(rc))
1875 {
1876 VGSvcVerbose(4, "[PID %RU32]: Written %RU32 bytes input, CID=%RU32, fPendingClose=%RTbool\n",
1877 pThis->uPID, cbWritten, pHostCtx->uContextID, fPendingClose);
1878 uStatus = INPUT_STS_WRITTEN;
1879 }
1880 else
1881 {
1882 if (rc == VERR_BAD_PIPE)
1883 uStatus = INPUT_STS_TERMINATED;
1884 else if (rc == VERR_BUFFER_OVERFLOW)
1885 uStatus = INPUT_STS_OVERFLOW;
1886 /* else undefined */
1887 }
1888
1889 /*
1890 * If there was an error and we did not set the host status
1891 * yet, then do it now.
1892 */
1893 if ( RT_FAILURE(rc)
1894 && uStatus == INPUT_STS_UNDEFINED)
1895 {
1896 uStatus = INPUT_STS_ERROR;
1897 fFlags = rc; /* funny thing to call a "flag"... */
1898 }
1899 Assert(uStatus > INPUT_STS_UNDEFINED);
1900
1901 int rc2 = VbglR3GuestCtrlProcCbStatusInput(pHostCtx, pThis->uPID, uStatus, fFlags, (uint32_t)cbWritten);
1902 if (RT_SUCCESS(rc))
1903 rc = rc2;
1904
1905#ifdef DEBUG
1906 VGSvcVerbose(3, "[PID %RU32]: vgsvcGstCtrlProcessOnInput returned with rc=%Rrc\n", pThis->uPID, rc);
1907#endif
1908 return VINF_SUCCESS; /** @todo Return rc here as soon as RTReqQueue todos are fixed. */
1909}
1910
1911
1912static DECLCALLBACK(int) vgsvcGstCtrlProcessOnOutput(PVBOXSERVICECTRLPROCESS pThis,
1913 const PVBGLR3GUESTCTRLCMDCTX pHostCtx,
1914 uint32_t uHandle, uint32_t cbToRead, uint32_t fFlags)
1915{
1916 AssertPtrReturn(pThis, VERR_INVALID_POINTER);
1917 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
1918
1919 const PVBOXSERVICECTRLSESSION pSession = pThis->pSession;
1920 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
1921
1922 int rc;
1923
1924 uint32_t cbBuf = cbToRead;
1925 uint8_t *pvBuf = (uint8_t *)RTMemAlloc(cbBuf);
1926 if (pvBuf)
1927 {
1928 PRTPIPE phPipe = uHandle == OUTPUT_HANDLE_ID_STDOUT
1929 ? &pThis->hPipeStdOutR
1930 : &pThis->hPipeStdErrR;
1931 AssertPtr(phPipe);
1932
1933 size_t cbRead = 0;
1934 if (*phPipe != NIL_RTPIPE)
1935 {
1936 rc = RTPipeRead(*phPipe, pvBuf, cbBuf, &cbRead);
1937 if (RT_FAILURE(rc))
1938 {
1939 RTPollSetRemove(pThis->hPollSet, uHandle == OUTPUT_HANDLE_ID_STDERR
1940 ? VBOXSERVICECTRLPIPEID_STDERR : VBOXSERVICECTRLPIPEID_STDOUT);
1941 RTPipeClose(*phPipe);
1942 *phPipe = NIL_RTPIPE;
1943 if (rc == VERR_BROKEN_PIPE)
1944 rc = VINF_EOF;
1945 }
1946 }
1947 else
1948 rc = VINF_EOF;
1949
1950#ifdef DEBUG
1951 if (RT_SUCCESS(rc))
1952 {
1953 if ( pSession->fFlags & VBOXSERVICECTRLSESSION_FLAG_DUMPSTDOUT
1954 && ( uHandle == OUTPUT_HANDLE_ID_STDOUT
1955 || uHandle == OUTPUT_HANDLE_ID_STDOUT_DEPRECATED)
1956 )
1957 {
1958 /** @todo r=bird: vgsvcGstCtrlProcessDumpToFile(void *pvBuf, size_t cbBuf, const char *pszFileNmFmt, ...) */
1959 char szDumpFile[RTPATH_MAX];
1960 if (!RTStrPrintf(szDumpFile, sizeof(szDumpFile), "VBoxService_Session%RU32_PID%RU32_StdOut.txt",
1961 pSession->StartupInfo.uSessionID, pThis->uPID)) rc = VERR_BUFFER_UNDERFLOW;
1962 if (RT_SUCCESS(rc))
1963 rc = vgsvcGstCtrlProcessDumpToFile(szDumpFile, pvBuf, cbRead);
1964 AssertRC(rc);
1965 }
1966 else if ( pSession->fFlags & VBOXSERVICECTRLSESSION_FLAG_DUMPSTDERR
1967 && uHandle == OUTPUT_HANDLE_ID_STDERR)
1968 {
1969 char szDumpFile[RTPATH_MAX];
1970 if (!RTStrPrintf(szDumpFile, sizeof(szDumpFile), "VBoxService_Session%RU32_PID%RU32_StdErr.txt",
1971 pSession->StartupInfo.uSessionID, pThis->uPID))
1972 rc = VERR_BUFFER_UNDERFLOW;
1973 if (RT_SUCCESS(rc))
1974 rc = vgsvcGstCtrlProcessDumpToFile(szDumpFile, pvBuf, cbRead);
1975 AssertRC(rc);
1976 }
1977 }
1978#endif
1979
1980 if (RT_SUCCESS(rc))
1981 {
1982#ifdef DEBUG
1983 VGSvcVerbose(3, "[PID %RU32]: Read %RU32 bytes output: uHandle=%RU32, CID=%RU32, fFlags=%x\n",
1984 pThis->uPID, cbRead, uHandle, pHostCtx->uContextID, fFlags);
1985#endif
1986 /** Note: Don't convert/touch/modify/whatever the output data here! This might be binary
1987 * data which the host needs to work with -- so just pass through all data unfiltered! */
1988
1989 /* Note: Since the context ID is unique the request *has* to be completed here,
1990 * regardless whether we got data or not! Otherwise the waiting events
1991 * on the host never will get completed! */
1992 Assert((uint32_t)cbRead == cbRead);
1993 rc = VbglR3GuestCtrlProcCbOutput(pHostCtx, pThis->uPID, uHandle, fFlags, pvBuf, (uint32_t)cbRead);
1994 if ( RT_FAILURE(rc)
1995 && rc == VERR_NOT_FOUND) /* Not critical if guest PID is not found on the host (anymore). */
1996 rc = VINF_SUCCESS;
1997 }
1998
1999 RTMemFree(pvBuf);
2000 }
2001 else
2002 rc = VERR_NO_MEMORY;
2003
2004#ifdef DEBUG
2005 VGSvcVerbose(3, "[PID %RU32]: Reading output returned with rc=%Rrc\n", pThis->uPID, rc);
2006#endif
2007 return VINF_SUCCESS; /** @todo Return rc here as soon as RTReqQueue todos are fixed. */
2008}
2009
2010
2011static DECLCALLBACK(int) vgsvcGstCtrlProcessOnTerm(PVBOXSERVICECTRLPROCESS pThis)
2012{
2013 AssertPtrReturn(pThis, VERR_INVALID_POINTER);
2014
2015 if (!ASMAtomicXchgBool(&pThis->fShutdown, true))
2016 VGSvcVerbose(3, "[PID %RU32]: Setting shutdown flag ...\n", pThis->uPID);
2017
2018 return VINF_SUCCESS; /** @todo Return rc here as soon as RTReqQueue todos are fixed. */
2019}
2020
2021
2022static int vgsvcGstCtrlProcessRequestExV(PVBOXSERVICECTRLPROCESS pProcess, const PVBGLR3GUESTCTRLCMDCTX pHostCtx, bool fAsync,
2023 RTMSINTERVAL uTimeoutMS, PRTREQ pReq, PFNRT pfnFunction, unsigned cArgs, va_list Args)
2024{
2025 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
2026 /* pHostCtx is optional. */
2027 AssertPtrReturn(pfnFunction, VERR_INVALID_POINTER);
2028 if (!fAsync)
2029 AssertPtrReturn(pfnFunction, VERR_INVALID_POINTER);
2030
2031 int rc = vgsvcGstCtrlProcessLock(pProcess);
2032 if (RT_SUCCESS(rc))
2033 {
2034#ifdef DEBUG
2035 VGSvcVerbose(3, "[PID %RU32]: vgsvcGstCtrlProcessRequestExV fAsync=%RTbool, uTimeoutMS=%RU32, cArgs=%u\n",
2036 pProcess->uPID, fAsync, uTimeoutMS, cArgs);
2037#endif
2038 uint32_t fFlags = RTREQFLAGS_IPRT_STATUS;
2039 if (fAsync)
2040 {
2041 Assert(uTimeoutMS == 0);
2042 fFlags |= RTREQFLAGS_NO_WAIT;
2043 }
2044
2045 rc = RTReqQueueCallV(pProcess->hReqQueue, &pReq, uTimeoutMS, fFlags, pfnFunction, cArgs, Args);
2046 if (RT_SUCCESS(rc))
2047 {
2048 /* Wake up the process' notification pipe to get
2049 * the request being processed. */
2050 Assert(pProcess->hNotificationPipeW != NIL_RTPIPE);
2051 size_t cbWritten = 0;
2052 rc = RTPipeWrite(pProcess->hNotificationPipeW, "i", 1, &cbWritten);
2053 if ( RT_SUCCESS(rc)
2054 && cbWritten != 1)
2055 {
2056 VGSvcError("[PID %RU32]: Notification pipe got %zu bytes instead of 1\n",
2057 pProcess->uPID, cbWritten);
2058 }
2059 else if (RT_UNLIKELY(RT_FAILURE(rc)))
2060 VGSvcError("[PID %RU32]: Writing to notification pipe failed, rc=%Rrc\n",
2061 pProcess->uPID, rc);
2062 }
2063 else
2064 VGSvcError("[PID %RU32]: RTReqQueueCallV failed, rc=%Rrc\n",
2065 pProcess->uPID, rc);
2066
2067 int rc2 = vgsvcGstCtrlProcessUnlock(pProcess);
2068 if (RT_SUCCESS(rc))
2069 rc = rc2;
2070 }
2071
2072#ifdef DEBUG
2073 VGSvcVerbose(3, "[PID %RU32]: vgsvcGstCtrlProcessRequestExV returned rc=%Rrc\n", pProcess->uPID, rc);
2074#endif
2075 return rc;
2076}
2077
2078
2079static int vgsvcGstCtrlProcessRequestAsync(PVBOXSERVICECTRLPROCESS pProcess, const PVBGLR3GUESTCTRLCMDCTX pHostCtx,
2080 PFNRT pfnFunction, unsigned cArgs, ...)
2081{
2082 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
2083 /* pHostCtx is optional. */
2084 AssertPtrReturn(pfnFunction, VERR_INVALID_POINTER);
2085
2086 va_list va;
2087 va_start(va, cArgs);
2088 int rc = vgsvcGstCtrlProcessRequestExV(pProcess, pHostCtx, true /* fAsync */, 0 /* uTimeoutMS */,
2089 NULL /* pReq */, pfnFunction, cArgs, va);
2090 va_end(va);
2091
2092 return rc;
2093}
2094
2095
2096#if 0 /* unused */
2097static int vgsvcGstCtrlProcessRequestWait(PVBOXSERVICECTRLPROCESS pProcess, const PVBGLR3GUESTCTRLCMDCTX pHostCtx,
2098 RTMSINTERVAL uTimeoutMS, PRTREQ pReq, PFNRT pfnFunction, unsigned cArgs, ...)
2099{
2100 AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
2101 /* pHostCtx is optional. */
2102 AssertPtrReturn(pfnFunction, VERR_INVALID_POINTER);
2103
2104 va_list va;
2105 va_start(va, cArgs);
2106 int rc = vgsvcGstCtrlProcessRequestExV(pProcess, pHostCtx, false /* fAsync */, uTimeoutMS,
2107 pReq, pfnFunction, cArgs, va);
2108 va_end(va);
2109
2110 return rc;
2111}
2112#endif
2113
2114
2115int VGSvcGstCtrlProcessHandleInput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx,
2116 bool fPendingClose, void *pvBuf, uint32_t cbBuf)
2117{
2118 if (!ASMAtomicReadBool(&pProcess->fShutdown))
2119 return vgsvcGstCtrlProcessRequestAsync(pProcess, pHostCtx, (PFNRT)vgsvcGstCtrlProcessOnInput,
2120 5 /* cArgs */, pProcess, pHostCtx, fPendingClose, pvBuf, cbBuf);
2121
2122 return vgsvcGstCtrlProcessOnInput(pProcess, pHostCtx, fPendingClose, pvBuf, cbBuf);
2123}
2124
2125
2126int VGSvcGstCtrlProcessHandleOutput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx,
2127 uint32_t uHandle, uint32_t cbToRead, uint32_t fFlags)
2128{
2129 if (!ASMAtomicReadBool(&pProcess->fShutdown))
2130 return vgsvcGstCtrlProcessRequestAsync(pProcess, pHostCtx, (PFNRT)vgsvcGstCtrlProcessOnOutput,
2131 5 /* cArgs */, pProcess, pHostCtx, uHandle, cbToRead, fFlags);
2132
2133 return vgsvcGstCtrlProcessOnOutput(pProcess, pHostCtx, uHandle, cbToRead, fFlags);
2134}
2135
2136
2137int VGSvcGstCtrlProcessHandleTerm(PVBOXSERVICECTRLPROCESS pProcess)
2138{
2139 if (!ASMAtomicReadBool(&pProcess->fShutdown))
2140 return vgsvcGstCtrlProcessRequestAsync(pProcess, NULL /* pHostCtx */, (PFNRT)vgsvcGstCtrlProcessOnTerm,
2141 1 /* cArgs */, pProcess);
2142
2143 return vgsvcGstCtrlProcessOnTerm(pProcess);
2144}
2145
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette