VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.cpp@ 99120

Last change on this file since 99120 was 99120, checked in by vboxsync, 14 months ago

Guest Control: Added ability of specifying an optional current working directory to started guest processes. This needs Guest Additions which support this. bugref:8053

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.2 KB
Line 
1/* $Id: VBoxServiceControl.cpp 99120 2023-03-22 17:30:14Z vboxsync $ */
2/** @file
3 * VBoxServiceControl - Host-driven Guest Control.
4 */
5
6/*
7 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/** @page pg_vgsvc_gstctrl VBoxService - Guest Control
29 *
30 * The Guest Control subservice helps implementing the IGuest APIs.
31 *
32 * The communication between this service (and its children) and IGuest goes
33 * over the HGCM GuestControl service.
34 *
35 * The IGuest APIs provides means to manipulate (control) files, directories,
36 * symbolic links and processes within the guest. Most of these means requires
37 * credentials of a guest OS user to operate, though some restricted ones
38 * operates directly as the VBoxService user (root / system service account).
39 *
40 * The current design is that a subprocess is spawned for handling operations as
41 * a given user. This process is represented as IGuestSession in the API. The
42 * subprocess will be spawned as the given use, giving up the privileges the
43 * parent subservice had.
44 *
45 * It will try handle as many of the operations directly from within the
46 * subprocess, but for more complicated things (or things that haven't yet been
47 * converted), it will spawn a helper process that does the actual work.
48 *
49 * These helpers are the typically modeled on similar unix core utilities, like
50 * mkdir, rm, rmdir, cat and so on. The helper tools can also be launched
51 * directly from VBoxManage by the user by prepending the 'vbox_' prefix to the
52 * unix command.
53 *
54 */
55
56
57/*********************************************************************************************************************************
58* Header Files *
59*********************************************************************************************************************************/
60#include <iprt/asm.h>
61#include <iprt/assert.h>
62#include <iprt/env.h>
63#include <iprt/file.h>
64#include <iprt/getopt.h>
65#include <iprt/mem.h>
66#include <iprt/path.h>
67#include <iprt/process.h>
68#include <iprt/semaphore.h>
69#include <iprt/thread.h>
70#include <VBox/err.h>
71#include <VBox/VBoxGuestLib.h>
72#include <VBox/HostServices/GuestControlSvc.h>
73#include "VBoxServiceInternal.h"
74#include "VBoxServiceControl.h"
75#include "VBoxServiceUtils.h"
76
77using namespace guestControl;
78
79
80/*********************************************************************************************************************************
81* Global Variables *
82*********************************************************************************************************************************/
83/** The control interval (milliseconds). */
84static uint32_t g_msControlInterval = 0;
85/** The semaphore we're blocking our main control thread on. */
86static RTSEMEVENTMULTI g_hControlEvent = NIL_RTSEMEVENTMULTI;
87/** The VM session ID. Changes whenever the VM is restored or reset. */
88static uint64_t g_idControlSession;
89/** The guest control service client ID. */
90uint32_t g_idControlSvcClient = 0;
91/** VBOX_GUESTCTRL_HF_XXX */
92uint64_t g_fControlHostFeatures0 = 0;
93#if 0 /** @todo process limit */
94/** How many started guest processes are kept into memory for supplying
95 * information to the host. Default is 256 processes. If 0 is specified,
96 * the maximum number of processes is unlimited. */
97static uint32_t g_uControlProcsMaxKept = 256;
98#endif
99/** List of guest control session threads (VBOXSERVICECTRLSESSIONTHREAD).
100 * A guest session thread represents a forked guest session process
101 * of VBoxService. */
102RTLISTANCHOR g_lstControlSessionThreads;
103/** The local session object used for handling all session-related stuff.
104 * When using the legacy guest control protocol (< 2), this session runs
105 * under behalf of the VBoxService main process. On newer protocol versions
106 * each session is a forked version of VBoxService using the appropriate
107 * user credentials for opening a guest session. These forked sessions then
108 * are kept in VBOXSERVICECTRLSESSIONTHREAD structures. */
109VBOXSERVICECTRLSESSION g_Session;
110/** Copy of VbglR3GuestCtrlSupportsOptimizations().*/
111bool g_fControlSupportsOptimizations = true;
112
113
114/*********************************************************************************************************************************
115* Internal Functions *
116*********************************************************************************************************************************/
117static int vgsvcGstCtrlHandleSessionOpen(PVBGLR3GUESTCTRLCMDCTX pHostCtx);
118static int vgsvcGstCtrlHandleSessionClose(PVBGLR3GUESTCTRLCMDCTX pHostCtx);
119static int vgsvcGstCtrlInvalidate(void);
120static void vgsvcGstCtrlShutdown(void);
121
122
123/**
124 * @interface_method_impl{VBOXSERVICE,pfnPreInit}
125 */
126static DECLCALLBACK(int) vgsvcGstCtrlPreInit(void)
127{
128 int rc;
129#ifdef VBOX_WITH_GUEST_PROPS
130 /*
131 * Read the service options from the VM's guest properties.
132 * Note that these options can be overridden by the command line options later.
133 */
134 uint32_t uGuestPropSvcClientID;
135 rc = VbglR3GuestPropConnect(&uGuestPropSvcClientID);
136 if (RT_FAILURE(rc))
137 {
138 if (rc == VERR_HGCM_SERVICE_NOT_FOUND) /* Host service is not available. */
139 {
140 VGSvcVerbose(0, "Guest property service is not available, skipping\n");
141 rc = VINF_SUCCESS;
142 }
143 else
144 VGSvcError("Failed to connect to the guest property service, rc=%Rrc\n", rc);
145 }
146 else
147 VbglR3GuestPropDisconnect(uGuestPropSvcClientID);
148
149 if (rc == VERR_NOT_FOUND) /* If a value is not found, don't be sad! */
150 rc = VINF_SUCCESS;
151#else
152 /* Nothing to do here yet. */
153 rc = VINF_SUCCESS;
154#endif
155
156 if (RT_SUCCESS(rc))
157 {
158 /* Init session object. */
159 rc = VGSvcGstCtrlSessionInit(&g_Session, 0 /* Flags */);
160 }
161
162 return rc;
163}
164
165
166/**
167 * @interface_method_impl{VBOXSERVICE,pfnOption}
168 */
169static DECLCALLBACK(int) vgsvcGstCtrlOption(const char **ppszShort, int argc, char **argv, int *pi)
170{
171 int rc = -1;
172 if (ppszShort)
173 /* no short options */;
174 else if (!strcmp(argv[*pi], "--control-interval"))
175 rc = VGSvcArgUInt32(argc, argv, "", pi,
176 &g_msControlInterval, 1, UINT32_MAX - 1);
177#ifdef DEBUG
178 else if (!strcmp(argv[*pi], "--control-dump-stdout"))
179 {
180 g_Session.fFlags |= VBOXSERVICECTRLSESSION_FLAG_DUMPSTDOUT;
181 rc = 0; /* Flag this command as parsed. */
182 }
183 else if (!strcmp(argv[*pi], "--control-dump-stderr"))
184 {
185 g_Session.fFlags |= VBOXSERVICECTRLSESSION_FLAG_DUMPSTDERR;
186 rc = 0; /* Flag this command as parsed. */
187 }
188#endif
189 return rc;
190}
191
192
193/**
194 * @interface_method_impl{VBOXSERVICE,pfnInit}
195 */
196static DECLCALLBACK(int) vgsvcGstCtrlInit(void)
197{
198 /*
199 * If not specified, find the right interval default.
200 * Then create the event sem to block on.
201 */
202 if (!g_msControlInterval)
203 g_msControlInterval = 1000;
204
205 int rc = RTSemEventMultiCreate(&g_hControlEvent);
206 AssertRCReturn(rc, rc);
207
208 VbglR3GetSessionId(&g_idControlSession); /* The status code is ignored as this information is not available with VBox < 3.2.10. */
209
210 RTListInit(&g_lstControlSessionThreads);
211
212 /*
213 * Try connect to the host service and tell it we want to be master (if supported).
214 */
215 rc = VbglR3GuestCtrlConnect(&g_idControlSvcClient);
216 if (RT_SUCCESS(rc))
217 {
218 rc = vgsvcGstCtrlInvalidate();
219 if (RT_SUCCESS(rc))
220 return rc;
221 }
222 else
223 {
224 /* If the service was not found, we disable this service without
225 causing VBoxService to fail. */
226 if (rc == VERR_HGCM_SERVICE_NOT_FOUND) /* Host service is not available. */
227 {
228 VGSvcVerbose(0, "Guest control service is not available\n");
229 rc = VERR_SERVICE_DISABLED;
230 }
231 else
232 VGSvcError("Failed to connect to the guest control service! Error: %Rrc\n", rc);
233 }
234 RTSemEventMultiDestroy(g_hControlEvent);
235 g_hControlEvent = NIL_RTSEMEVENTMULTI;
236 g_idControlSvcClient = 0;
237 return rc;
238}
239
240static int vgsvcGstCtrlInvalidate(void)
241{
242 VGSvcVerbose(1, "Invalidating configuration ...\n");
243
244 int rc = VINF_SUCCESS;
245
246 g_fControlSupportsOptimizations = VbglR3GuestCtrlSupportsOptimizations(g_idControlSvcClient);
247 if (g_fControlSupportsOptimizations)
248 rc = VbglR3GuestCtrlMakeMeMaster(g_idControlSvcClient);
249 if (RT_SUCCESS(rc))
250 {
251 VGSvcVerbose(3, "Guest control service client ID=%RU32%s\n",
252 g_idControlSvcClient, g_fControlSupportsOptimizations ? " w/ optimizations" : "");
253
254 /*
255 * Report features to the host.
256 */
257 const uint64_t fGuestFeatures = VBOX_GUESTCTRL_GF_0_SET_SIZE
258 | VBOX_GUESTCTRL_GF_0_PROCESS_ARGV0
259 | VBOX_GUESTCTRL_GF_0_PROCESS_DYNAMIC_SIZES
260 | VBOX_GUESTCTRL_GF_0_PROCESS_CWD
261#ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
262 | VBOX_GUESTCTRL_GF_0_TOOLBOX_AS_CMDS
263#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
264 | VBOX_GUESTCTRL_GF_0_SHUTDOWN;
265 rc = VbglR3GuestCtrlReportFeatures(g_idControlSvcClient, fGuestFeatures, &g_fControlHostFeatures0);
266 if (RT_SUCCESS(rc))
267 VGSvcVerbose(3, "Host features: %#RX64\n", g_fControlHostFeatures0);
268 else
269 VGSvcVerbose(1, "Warning! Feature reporing failed: %Rrc\n", rc);
270
271 return VINF_SUCCESS;
272 }
273 VGSvcError("Failed to become guest control master: %Rrc\n", rc);
274 VbglR3GuestCtrlDisconnect(g_idControlSvcClient);
275
276 return rc;
277}
278
279/**
280 * @interface_method_impl{VBOXSERVICE,pfnWorker}
281 */
282static DECLCALLBACK(int) vgsvcGstCtrlWorker(bool volatile *pfShutdown)
283{
284 /*
285 * Tell the control thread that it can continue spawning services.
286 */
287 RTThreadUserSignal(RTThreadSelf());
288 Assert(g_idControlSvcClient > 0);
289
290 /* Allocate a scratch buffer for messages which also send
291 * payload data with them. */
292 uint32_t cbScratchBuf = _64K; /** @todo Make buffer size configurable via guest properties/argv! */
293 AssertReturn(RT_IS_POWER_OF_TWO(cbScratchBuf), VERR_INVALID_PARAMETER);
294 uint8_t *pvScratchBuf = (uint8_t*)RTMemAlloc(cbScratchBuf);
295 AssertReturn(pvScratchBuf, VERR_NO_MEMORY);
296
297 int rc = VINF_SUCCESS; /* (shut up compiler warnings) */
298 int cRetrievalFailed = 0; /* Number of failed message retrievals in a row. */
299 while (!*pfShutdown)
300 {
301 VGSvcVerbose(3, "GstCtrl: Waiting for host msg ...\n");
302 VBGLR3GUESTCTRLCMDCTX ctxHost = { g_idControlSvcClient, 0 /*idContext*/, 2 /*uProtocol*/, 0 /*cParms*/ };
303 uint32_t idMsg = 0;
304 rc = VbglR3GuestCtrlMsgPeekWait(g_idControlSvcClient, &idMsg, &ctxHost.uNumParms, &g_idControlSession);
305 if (RT_SUCCESS(rc))
306 {
307 cRetrievalFailed = 0; /* Reset failed retrieval count. */
308 VGSvcVerbose(4, "idMsg=%RU32 (%s) (%RU32 parms) retrieved\n",
309 idMsg, GstCtrlHostMsgtoStr((eHostMsg)idMsg), ctxHost.uNumParms);
310
311 /*
312 * Handle the host message.
313 */
314 switch (idMsg)
315 {
316 case HOST_MSG_CANCEL_PENDING_WAITS:
317 VGSvcVerbose(1, "We were asked to quit ...\n");
318 break;
319
320 case HOST_MSG_SESSION_CREATE:
321 rc = vgsvcGstCtrlHandleSessionOpen(&ctxHost);
322 break;
323
324 /* This message is also sent to the child session process (by the host). */
325 case HOST_MSG_SESSION_CLOSE:
326 rc = vgsvcGstCtrlHandleSessionClose(&ctxHost);
327 break;
328
329 default:
330 if (VbglR3GuestCtrlSupportsOptimizations(g_idControlSvcClient))
331 {
332 rc = VbglR3GuestCtrlMsgSkip(g_idControlSvcClient, VERR_NOT_SUPPORTED, idMsg);
333 VGSvcVerbose(1, "Skipped unexpected message idMsg=%RU32 (%s), cParms=%RU32 (rc=%Rrc)\n",
334 idMsg, GstCtrlHostMsgtoStr((eHostMsg)idMsg), ctxHost.uNumParms, rc);
335 }
336 else
337 {
338 rc = VbglR3GuestCtrlMsgSkipOld(g_idControlSvcClient);
339 VGSvcVerbose(3, "Skipped idMsg=%RU32, cParms=%RU32, rc=%Rrc\n", idMsg, ctxHost.uNumParms, rc);
340 }
341 break;
342 }
343
344 /* Do we need to shutdown? */
345 if (idMsg == HOST_MSG_CANCEL_PENDING_WAITS)
346 break;
347
348 /* Let's sleep for a bit and let others run ... */
349 RTThreadYield();
350 }
351 /*
352 * Handle restore notification from host. All the context IDs (sessions,
353 * files, proceses, etc) are invalidated by a VM restore and must be closed.
354 */
355 else if (rc == VERR_VM_RESTORED)
356 {
357 VGSvcVerbose(1, "The VM session ID changed (i.e. restored), closing stale root session\n");
358
359 /* Make sure that all other session threads are gone.
360 * This is necessary, as the new VM session (NOT to be confused with guest session!) will re-use
361 * the guest session IDs. */
362 int rc2 = VGSvcGstCtrlSessionThreadDestroyAll(&g_lstControlSessionThreads, 0 /* Flags */);
363 if (RT_FAILURE(rc2))
364 VGSvcError("Closing session threads failed with rc=%Rrc\n", rc2);
365
366 /* Make sure to also close the root session (session 0). */
367 rc2 = VGSvcGstCtrlSessionClose(&g_Session);
368 AssertRC(rc2);
369
370 rc2 = VbglR3GuestCtrlSessionHasChanged(g_idControlSvcClient, g_idControlSession);
371 AssertRC(rc2);
372
373 /* Invalidate the internal state to match the current host we got restored from. */
374 rc2 = vgsvcGstCtrlInvalidate();
375 AssertRC(rc2);
376 }
377 else
378 {
379 /* Note: VERR_GEN_IO_FAILURE seems to be normal if ran into timeout. */
380 /** @todo r=bird: Above comment makes no sense. How can you get a timeout in a blocking HGCM call? */
381 VGSvcError("GstCtrl: Getting host message failed with %Rrc\n", rc);
382
383 /* Check for VM session change. */
384 /** @todo We don't need to check the host here. */
385 uint64_t idNewSession = g_idControlSession;
386 int rc2 = VbglR3GetSessionId(&idNewSession);
387 if ( RT_SUCCESS(rc2)
388 && (idNewSession != g_idControlSession))
389 {
390 VGSvcVerbose(1, "GstCtrl: The VM session ID changed\n");
391 g_idControlSession = idNewSession;
392
393 /* Close all opened guest sessions -- all context IDs, sessions etc.
394 * are now invalid. */
395 rc2 = VGSvcGstCtrlSessionClose(&g_Session);
396 AssertRC(rc2);
397
398 /* Do a reconnect. */
399 VGSvcVerbose(1, "Reconnecting to HGCM service ...\n");
400 rc2 = VbglR3GuestCtrlConnect(&g_idControlSvcClient);
401 if (RT_SUCCESS(rc2))
402 {
403 VGSvcVerbose(3, "Guest control service client ID=%RU32\n", g_idControlSvcClient);
404 cRetrievalFailed = 0;
405 continue; /* Skip waiting. */
406 }
407 VGSvcError("Unable to re-connect to HGCM service, rc=%Rrc, bailing out\n", rc);
408 break;
409 }
410
411 if (rc == VERR_INTERRUPTED)
412 RTThreadYield(); /* To be on the safe side... */
413 else if (++cRetrievalFailed <= 16) /** @todo Make this configurable? */
414 RTThreadSleep(1000); /* Wait a bit before retrying. */
415 else
416 {
417 VGSvcError("Too many failed attempts in a row to get next message, bailing out\n");
418 break;
419 }
420 }
421 }
422
423 VGSvcVerbose(0, "Guest control service stopped\n");
424
425 /* Delete scratch buffer. */
426 if (pvScratchBuf)
427 RTMemFree(pvScratchBuf);
428
429 VGSvcVerbose(0, "Guest control worker returned with rc=%Rrc\n", rc);
430 return rc;
431}
432
433
434static int vgsvcGstCtrlHandleSessionOpen(PVBGLR3GUESTCTRLCMDCTX pHostCtx)
435{
436 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
437
438 /*
439 * Retrieve the message parameters.
440 */
441 PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo;
442 int rc = VbglR3GuestCtrlSessionGetOpen(pHostCtx, &pStartupInfo);
443 if (RT_SUCCESS(rc))
444 {
445 /*
446 * Flat out refuse to work with protocol v1 hosts.
447 */
448 if (pStartupInfo->uProtocol == 2)
449 {
450 pHostCtx->uProtocol = pStartupInfo->uProtocol;
451 VGSvcVerbose(3, "Client ID=%RU32 now is using protocol %RU32\n", pHostCtx->uClientID, pHostCtx->uProtocol);
452
453/** @todo Someone explain why this code isn't in this file too? v1 support? */
454 rc = VGSvcGstCtrlSessionThreadCreate(&g_lstControlSessionThreads, pStartupInfo, NULL /* ppSessionThread */);
455 /* Report failures to the host (successes are taken care of by the session thread). */
456 }
457 else
458 {
459 VGSvcError("The host wants to use protocol v%u, we only support v2!\n", pStartupInfo->uProtocol);
460 rc = VERR_VERSION_MISMATCH;
461 }
462 if (RT_FAILURE(rc))
463 {
464 int rc2 = VbglR3GuestCtrlSessionNotify(pHostCtx, GUEST_SESSION_NOTIFYTYPE_ERROR, rc);
465 if (RT_FAILURE(rc2))
466 VGSvcError("Reporting session error status on open failed with rc=%Rrc\n", rc2);
467 }
468 }
469 else
470 {
471 VGSvcError("Error fetching parameters for opening guest session: %Rrc\n", rc);
472 VbglR3GuestCtrlMsgSkip(pHostCtx->uClientID, rc, UINT32_MAX);
473 }
474
475 VbglR3GuestCtrlSessionStartupInfoFree(pStartupInfo);
476 pStartupInfo = NULL;
477
478 VGSvcVerbose(3, "Opening a new guest session returned rc=%Rrc\n", rc);
479 return rc;
480}
481
482
483static int vgsvcGstCtrlHandleSessionClose(PVBGLR3GUESTCTRLCMDCTX pHostCtx)
484{
485 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
486
487 uint32_t idSession;
488 uint32_t fFlags;
489 int rc = VbglR3GuestCtrlSessionGetClose(pHostCtx, &fFlags, &idSession);
490 if (RT_SUCCESS(rc))
491 {
492 rc = VERR_NOT_FOUND;
493
494 PVBOXSERVICECTRLSESSIONTHREAD pThread;
495 RTListForEach(&g_lstControlSessionThreads, pThread, VBOXSERVICECTRLSESSIONTHREAD, Node)
496 {
497 if ( pThread->pStartupInfo
498 && pThread->pStartupInfo->uSessionID == idSession)
499 {
500 rc = VGSvcGstCtrlSessionThreadDestroy(pThread, fFlags);
501 break;
502 }
503 }
504
505#if 0 /** @todo A bit of a mess here as this message goes to both to this process (master) and the session process. */
506 if (RT_FAILURE(rc))
507 {
508 /* Report back on failure. On success this will be done
509 * by the forked session thread. */
510 int rc2 = VbglR3GuestCtrlSessionNotify(pHostCtx,
511 GUEST_SESSION_NOTIFYTYPE_ERROR, rc);
512 if (RT_FAILURE(rc2))
513 {
514 VGSvcError("Reporting session error status on close failed with rc=%Rrc\n", rc2);
515 if (RT_SUCCESS(rc))
516 rc = rc2;
517 }
518 }
519#endif
520 VGSvcVerbose(2, "Closing guest session %RU32 returned rc=%Rrc\n", idSession, rc);
521 }
522 else
523 {
524 VGSvcError("Error fetching parameters for closing guest session: %Rrc\n", rc);
525 VbglR3GuestCtrlMsgSkip(pHostCtx->uClientID, rc, UINT32_MAX);
526 }
527 return rc;
528}
529
530
531/**
532 * @interface_method_impl{VBOXSERVICE,pfnStop}
533 */
534static DECLCALLBACK(void) vgsvcGstCtrlStop(void)
535{
536 VGSvcVerbose(3, "Stopping ...\n");
537
538 /** @todo Later, figure what to do if we're in RTProcWait(). It's a very
539 * annoying call since doesn't support timeouts in the posix world. */
540 if (g_hControlEvent != NIL_RTSEMEVENTMULTI)
541 RTSemEventMultiSignal(g_hControlEvent);
542
543 /*
544 * Ask the host service to cancel all pending requests for the main
545 * control thread so that we can shutdown properly here.
546 */
547 if (g_idControlSvcClient)
548 {
549 VGSvcVerbose(3, "Cancelling pending waits (client ID=%u) ...\n",
550 g_idControlSvcClient);
551
552 int rc = VbglR3GuestCtrlCancelPendingWaits(g_idControlSvcClient);
553 if (RT_FAILURE(rc))
554 VGSvcError("Cancelling pending waits failed; rc=%Rrc\n", rc);
555 }
556}
557
558
559/**
560 * Destroys all guest process threads which are still active.
561 */
562static void vgsvcGstCtrlShutdown(void)
563{
564 VGSvcVerbose(2, "Shutting down ...\n");
565
566 int rc2 = VGSvcGstCtrlSessionThreadDestroyAll(&g_lstControlSessionThreads, 0 /* Flags */);
567 if (RT_FAILURE(rc2))
568 VGSvcError("Closing session threads failed with rc=%Rrc\n", rc2);
569
570 rc2 = VGSvcGstCtrlSessionClose(&g_Session);
571 if (RT_FAILURE(rc2))
572 VGSvcError("Closing session failed with rc=%Rrc\n", rc2);
573
574 VGSvcVerbose(2, "Shutting down complete\n");
575}
576
577
578/**
579 * @interface_method_impl{VBOXSERVICE,pfnTerm}
580 */
581static DECLCALLBACK(void) vgsvcGstCtrlTerm(void)
582{
583 VGSvcVerbose(3, "Terminating ...\n");
584
585 vgsvcGstCtrlShutdown();
586
587 VGSvcVerbose(3, "Disconnecting client ID=%u ...\n", g_idControlSvcClient);
588 VbglR3GuestCtrlDisconnect(g_idControlSvcClient);
589 g_idControlSvcClient = 0;
590
591 if (g_hControlEvent != NIL_RTSEMEVENTMULTI)
592 {
593 RTSemEventMultiDestroy(g_hControlEvent);
594 g_hControlEvent = NIL_RTSEMEVENTMULTI;
595 }
596}
597
598
599/**
600 * The 'vminfo' service description.
601 */
602VBOXSERVICE g_Control =
603{
604 /* pszName. */
605 "control",
606 /* pszDescription. */
607 "Host-driven Guest Control",
608 /* pszUsage. */
609#ifdef DEBUG
610 " [--control-dump-stderr] [--control-dump-stdout]\n"
611#endif
612 " [--control-interval <ms>]"
613 ,
614 /* pszOptions. */
615#ifdef DEBUG
616 " --control-dump-stderr Dumps all guest proccesses stderr data to the\n"
617 " temporary directory.\n"
618 " --control-dump-stdout Dumps all guest proccesses stdout data to the\n"
619 " temporary directory.\n"
620#endif
621 " --control-interval Specifies the interval at which to check for\n"
622 " new control messages. The default is 1000 ms.\n"
623 ,
624 /* methods */
625 vgsvcGstCtrlPreInit,
626 vgsvcGstCtrlOption,
627 vgsvcGstCtrlInit,
628 vgsvcGstCtrlWorker,
629 vgsvcGstCtrlStop,
630 vgsvcGstCtrlTerm
631};
632
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use