VirtualBox

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

Last change on this file since 98613 was 98526, checked in by vboxsync, 22 months ago

Guest Control: Initial commit (work in progress, disabled by default). bugref:9783

IGuestDirectory:

Added new attributes id + status + an own event source. Also added for rewind support via rewind().

New event types for guest directory [un]registration, state changes and entry reads.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.1 KB
Line 
1/* $Id: VBoxServiceControl.cpp 98526 2023-02-10 15:10:50Z 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#ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
261 | VBOX_GUESTCTRL_GF_0_TOOLBOX_AS_CMDS
262#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
263 | VBOX_GUESTCTRL_GF_0_SHUTDOWN;
264 rc = VbglR3GuestCtrlReportFeatures(g_idControlSvcClient, fGuestFeatures, &g_fControlHostFeatures0);
265 if (RT_SUCCESS(rc))
266 VGSvcVerbose(3, "Host features: %#RX64\n", g_fControlHostFeatures0);
267 else
268 VGSvcVerbose(1, "Warning! Feature reporing failed: %Rrc\n", rc);
269
270 return VINF_SUCCESS;
271 }
272 VGSvcError("Failed to become guest control master: %Rrc\n", rc);
273 VbglR3GuestCtrlDisconnect(g_idControlSvcClient);
274
275 return rc;
276}
277
278/**
279 * @interface_method_impl{VBOXSERVICE,pfnWorker}
280 */
281static DECLCALLBACK(int) vgsvcGstCtrlWorker(bool volatile *pfShutdown)
282{
283 /*
284 * Tell the control thread that it can continue spawning services.
285 */
286 RTThreadUserSignal(RTThreadSelf());
287 Assert(g_idControlSvcClient > 0);
288
289 /* Allocate a scratch buffer for messages which also send
290 * payload data with them. */
291 uint32_t cbScratchBuf = _64K; /** @todo Make buffer size configurable via guest properties/argv! */
292 AssertReturn(RT_IS_POWER_OF_TWO(cbScratchBuf), VERR_INVALID_PARAMETER);
293 uint8_t *pvScratchBuf = (uint8_t*)RTMemAlloc(cbScratchBuf);
294 AssertReturn(pvScratchBuf, VERR_NO_MEMORY);
295
296 int rc = VINF_SUCCESS; /* (shut up compiler warnings) */
297 int cRetrievalFailed = 0; /* Number of failed message retrievals in a row. */
298 while (!*pfShutdown)
299 {
300 VGSvcVerbose(3, "GstCtrl: Waiting for host msg ...\n");
301 VBGLR3GUESTCTRLCMDCTX ctxHost = { g_idControlSvcClient, 0 /*idContext*/, 2 /*uProtocol*/, 0 /*cParms*/ };
302 uint32_t idMsg = 0;
303 rc = VbglR3GuestCtrlMsgPeekWait(g_idControlSvcClient, &idMsg, &ctxHost.uNumParms, &g_idControlSession);
304 if (RT_SUCCESS(rc))
305 {
306 cRetrievalFailed = 0; /* Reset failed retrieval count. */
307 VGSvcVerbose(4, "idMsg=%RU32 (%s) (%RU32 parms) retrieved\n",
308 idMsg, GstCtrlHostMsgtoStr((eHostMsg)idMsg), ctxHost.uNumParms);
309
310 /*
311 * Handle the host message.
312 */
313 switch (idMsg)
314 {
315 case HOST_MSG_CANCEL_PENDING_WAITS:
316 VGSvcVerbose(1, "We were asked to quit ...\n");
317 break;
318
319 case HOST_MSG_SESSION_CREATE:
320 rc = vgsvcGstCtrlHandleSessionOpen(&ctxHost);
321 break;
322
323 /* This message is also sent to the child session process (by the host). */
324 case HOST_MSG_SESSION_CLOSE:
325 rc = vgsvcGstCtrlHandleSessionClose(&ctxHost);
326 break;
327
328 default:
329 if (VbglR3GuestCtrlSupportsOptimizations(g_idControlSvcClient))
330 {
331 rc = VbglR3GuestCtrlMsgSkip(g_idControlSvcClient, VERR_NOT_SUPPORTED, idMsg);
332 VGSvcVerbose(1, "Skipped unexpected message idMsg=%RU32 (%s), cParms=%RU32 (rc=%Rrc)\n",
333 idMsg, GstCtrlHostMsgtoStr((eHostMsg)idMsg), ctxHost.uNumParms, rc);
334 }
335 else
336 {
337 rc = VbglR3GuestCtrlMsgSkipOld(g_idControlSvcClient);
338 VGSvcVerbose(3, "Skipped idMsg=%RU32, cParms=%RU32, rc=%Rrc\n", idMsg, ctxHost.uNumParms, rc);
339 }
340 break;
341 }
342
343 /* Do we need to shutdown? */
344 if (idMsg == HOST_MSG_CANCEL_PENDING_WAITS)
345 break;
346
347 /* Let's sleep for a bit and let others run ... */
348 RTThreadYield();
349 }
350 /*
351 * Handle restore notification from host. All the context IDs (sessions,
352 * files, proceses, etc) are invalidated by a VM restore and must be closed.
353 */
354 else if (rc == VERR_VM_RESTORED)
355 {
356 VGSvcVerbose(1, "The VM session ID changed (i.e. restored), closing stale root session\n");
357
358 /* Make sure that all other session threads are gone.
359 * This is necessary, as the new VM session (NOT to be confused with guest session!) will re-use
360 * the guest session IDs. */
361 int rc2 = VGSvcGstCtrlSessionThreadDestroyAll(&g_lstControlSessionThreads, 0 /* Flags */);
362 if (RT_FAILURE(rc2))
363 VGSvcError("Closing session threads failed with rc=%Rrc\n", rc2);
364
365 /* Make sure to also close the root session (session 0). */
366 rc2 = VGSvcGstCtrlSessionClose(&g_Session);
367 AssertRC(rc2);
368
369 rc2 = VbglR3GuestCtrlSessionHasChanged(g_idControlSvcClient, g_idControlSession);
370 AssertRC(rc2);
371
372 /* Invalidate the internal state to match the current host we got restored from. */
373 rc2 = vgsvcGstCtrlInvalidate();
374 AssertRC(rc2);
375 }
376 else
377 {
378 /* Note: VERR_GEN_IO_FAILURE seems to be normal if ran into timeout. */
379 /** @todo r=bird: Above comment makes no sense. How can you get a timeout in a blocking HGCM call? */
380 VGSvcError("GstCtrl: Getting host message failed with %Rrc\n", rc);
381
382 /* Check for VM session change. */
383 /** @todo We don't need to check the host here. */
384 uint64_t idNewSession = g_idControlSession;
385 int rc2 = VbglR3GetSessionId(&idNewSession);
386 if ( RT_SUCCESS(rc2)
387 && (idNewSession != g_idControlSession))
388 {
389 VGSvcVerbose(1, "GstCtrl: The VM session ID changed\n");
390 g_idControlSession = idNewSession;
391
392 /* Close all opened guest sessions -- all context IDs, sessions etc.
393 * are now invalid. */
394 rc2 = VGSvcGstCtrlSessionClose(&g_Session);
395 AssertRC(rc2);
396
397 /* Do a reconnect. */
398 VGSvcVerbose(1, "Reconnecting to HGCM service ...\n");
399 rc2 = VbglR3GuestCtrlConnect(&g_idControlSvcClient);
400 if (RT_SUCCESS(rc2))
401 {
402 VGSvcVerbose(3, "Guest control service client ID=%RU32\n", g_idControlSvcClient);
403 cRetrievalFailed = 0;
404 continue; /* Skip waiting. */
405 }
406 VGSvcError("Unable to re-connect to HGCM service, rc=%Rrc, bailing out\n", rc);
407 break;
408 }
409
410 if (rc == VERR_INTERRUPTED)
411 RTThreadYield(); /* To be on the safe side... */
412 else if (++cRetrievalFailed <= 16) /** @todo Make this configurable? */
413 RTThreadSleep(1000); /* Wait a bit before retrying. */
414 else
415 {
416 VGSvcError("Too many failed attempts in a row to get next message, bailing out\n");
417 break;
418 }
419 }
420 }
421
422 VGSvcVerbose(0, "Guest control service stopped\n");
423
424 /* Delete scratch buffer. */
425 if (pvScratchBuf)
426 RTMemFree(pvScratchBuf);
427
428 VGSvcVerbose(0, "Guest control worker returned with rc=%Rrc\n", rc);
429 return rc;
430}
431
432
433static int vgsvcGstCtrlHandleSessionOpen(PVBGLR3GUESTCTRLCMDCTX pHostCtx)
434{
435 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
436
437 /*
438 * Retrieve the message parameters.
439 */
440 PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo;
441 int rc = VbglR3GuestCtrlSessionGetOpen(pHostCtx, &pStartupInfo);
442 if (RT_SUCCESS(rc))
443 {
444 /*
445 * Flat out refuse to work with protocol v1 hosts.
446 */
447 if (pStartupInfo->uProtocol == 2)
448 {
449 pHostCtx->uProtocol = pStartupInfo->uProtocol;
450 VGSvcVerbose(3, "Client ID=%RU32 now is using protocol %RU32\n", pHostCtx->uClientID, pHostCtx->uProtocol);
451
452/** @todo Someone explain why this code isn't in this file too? v1 support? */
453 rc = VGSvcGstCtrlSessionThreadCreate(&g_lstControlSessionThreads, pStartupInfo, NULL /* ppSessionThread */);
454 /* Report failures to the host (successes are taken care of by the session thread). */
455 }
456 else
457 {
458 VGSvcError("The host wants to use protocol v%u, we only support v2!\n", pStartupInfo->uProtocol);
459 rc = VERR_VERSION_MISMATCH;
460 }
461 if (RT_FAILURE(rc))
462 {
463 int rc2 = VbglR3GuestCtrlSessionNotify(pHostCtx, GUEST_SESSION_NOTIFYTYPE_ERROR, rc);
464 if (RT_FAILURE(rc2))
465 VGSvcError("Reporting session error status on open failed with rc=%Rrc\n", rc2);
466 }
467 }
468 else
469 {
470 VGSvcError("Error fetching parameters for opening guest session: %Rrc\n", rc);
471 VbglR3GuestCtrlMsgSkip(pHostCtx->uClientID, rc, UINT32_MAX);
472 }
473
474 VbglR3GuestCtrlSessionStartupInfoFree(pStartupInfo);
475 pStartupInfo = NULL;
476
477 VGSvcVerbose(3, "Opening a new guest session returned rc=%Rrc\n", rc);
478 return rc;
479}
480
481
482static int vgsvcGstCtrlHandleSessionClose(PVBGLR3GUESTCTRLCMDCTX pHostCtx)
483{
484 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
485
486 uint32_t idSession;
487 uint32_t fFlags;
488 int rc = VbglR3GuestCtrlSessionGetClose(pHostCtx, &fFlags, &idSession);
489 if (RT_SUCCESS(rc))
490 {
491 rc = VERR_NOT_FOUND;
492
493 PVBOXSERVICECTRLSESSIONTHREAD pThread;
494 RTListForEach(&g_lstControlSessionThreads, pThread, VBOXSERVICECTRLSESSIONTHREAD, Node)
495 {
496 if ( pThread->pStartupInfo
497 && pThread->pStartupInfo->uSessionID == idSession)
498 {
499 rc = VGSvcGstCtrlSessionThreadDestroy(pThread, fFlags);
500 break;
501 }
502 }
503
504#if 0 /** @todo A bit of a mess here as this message goes to both to this process (master) and the session process. */
505 if (RT_FAILURE(rc))
506 {
507 /* Report back on failure. On success this will be done
508 * by the forked session thread. */
509 int rc2 = VbglR3GuestCtrlSessionNotify(pHostCtx,
510 GUEST_SESSION_NOTIFYTYPE_ERROR, rc);
511 if (RT_FAILURE(rc2))
512 {
513 VGSvcError("Reporting session error status on close failed with rc=%Rrc\n", rc2);
514 if (RT_SUCCESS(rc))
515 rc = rc2;
516 }
517 }
518#endif
519 VGSvcVerbose(2, "Closing guest session %RU32 returned rc=%Rrc\n", idSession, rc);
520 }
521 else
522 {
523 VGSvcError("Error fetching parameters for closing guest session: %Rrc\n", rc);
524 VbglR3GuestCtrlMsgSkip(pHostCtx->uClientID, rc, UINT32_MAX);
525 }
526 return rc;
527}
528
529
530/**
531 * @interface_method_impl{VBOXSERVICE,pfnStop}
532 */
533static DECLCALLBACK(void) vgsvcGstCtrlStop(void)
534{
535 VGSvcVerbose(3, "Stopping ...\n");
536
537 /** @todo Later, figure what to do if we're in RTProcWait(). It's a very
538 * annoying call since doesn't support timeouts in the posix world. */
539 if (g_hControlEvent != NIL_RTSEMEVENTMULTI)
540 RTSemEventMultiSignal(g_hControlEvent);
541
542 /*
543 * Ask the host service to cancel all pending requests for the main
544 * control thread so that we can shutdown properly here.
545 */
546 if (g_idControlSvcClient)
547 {
548 VGSvcVerbose(3, "Cancelling pending waits (client ID=%u) ...\n",
549 g_idControlSvcClient);
550
551 int rc = VbglR3GuestCtrlCancelPendingWaits(g_idControlSvcClient);
552 if (RT_FAILURE(rc))
553 VGSvcError("Cancelling pending waits failed; rc=%Rrc\n", rc);
554 }
555}
556
557
558/**
559 * Destroys all guest process threads which are still active.
560 */
561static void vgsvcGstCtrlShutdown(void)
562{
563 VGSvcVerbose(2, "Shutting down ...\n");
564
565 int rc2 = VGSvcGstCtrlSessionThreadDestroyAll(&g_lstControlSessionThreads, 0 /* Flags */);
566 if (RT_FAILURE(rc2))
567 VGSvcError("Closing session threads failed with rc=%Rrc\n", rc2);
568
569 rc2 = VGSvcGstCtrlSessionClose(&g_Session);
570 if (RT_FAILURE(rc2))
571 VGSvcError("Closing session failed with rc=%Rrc\n", rc2);
572
573 VGSvcVerbose(2, "Shutting down complete\n");
574}
575
576
577/**
578 * @interface_method_impl{VBOXSERVICE,pfnTerm}
579 */
580static DECLCALLBACK(void) vgsvcGstCtrlTerm(void)
581{
582 VGSvcVerbose(3, "Terminating ...\n");
583
584 vgsvcGstCtrlShutdown();
585
586 VGSvcVerbose(3, "Disconnecting client ID=%u ...\n", g_idControlSvcClient);
587 VbglR3GuestCtrlDisconnect(g_idControlSvcClient);
588 g_idControlSvcClient = 0;
589
590 if (g_hControlEvent != NIL_RTSEMEVENTMULTI)
591 {
592 RTSemEventMultiDestroy(g_hControlEvent);
593 g_hControlEvent = NIL_RTSEMEVENTMULTI;
594 }
595}
596
597
598/**
599 * The 'vminfo' service description.
600 */
601VBOXSERVICE g_Control =
602{
603 /* pszName. */
604 "control",
605 /* pszDescription. */
606 "Host-driven Guest Control",
607 /* pszUsage. */
608#ifdef DEBUG
609 " [--control-dump-stderr] [--control-dump-stdout]\n"
610#endif
611 " [--control-interval <ms>]"
612 ,
613 /* pszOptions. */
614#ifdef DEBUG
615 " --control-dump-stderr Dumps all guest proccesses stderr data to the\n"
616 " temporary directory.\n"
617 " --control-dump-stdout Dumps all guest proccesses stdout data to the\n"
618 " temporary directory.\n"
619#endif
620 " --control-interval Specifies the interval at which to check for\n"
621 " new control messages. The default is 1000 ms.\n"
622 ,
623 /* methods */
624 vgsvcGstCtrlPreInit,
625 vgsvcGstCtrlOption,
626 vgsvcGstCtrlInit,
627 vgsvcGstCtrlWorker,
628 vgsvcGstCtrlStop,
629 vgsvcGstCtrlTerm
630};
631
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