VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp@ 36214

Last change on this file since 36214 was 35077, checked in by vboxsync, 14 years ago

VBoxService/AutoMount: Fixed shutting down flag race when actually starting the thread.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.9 KB
Line 
1/* $Id: VBoxServiceAutoMount.cpp 35077 2010-12-14 13:37:49Z vboxsync $ */
2/** @file
3 * VBoxService - Auto-mounting for Shared Folders.
4 */
5
6/*
7 * Copyright (C) 2010 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/assert.h>
23#include <iprt/dir.h>
24#include <iprt/mem.h>
25#include <iprt/path.h>
26#include <iprt/string.h>
27#include <iprt/semaphore.h>
28#include <VBox/VBoxGuestLib.h>
29#include "VBoxServiceInternal.h"
30#include "VBoxServiceUtils.h"
31
32#include <errno.h>
33#include <grp.h>
34#include <sys/mount.h>
35#ifdef RT_OS_SOLARIS
36# include <sys/mntent.h>
37# include <sys/mnttab.h>
38# include <sys/vfs.h>
39#else
40# include <mntent.h>
41# include <paths.h>
42#endif
43#include <unistd.h>
44
45RT_C_DECLS_BEGIN
46#include "../../linux/sharedfolders/vbsfmount.h"
47RT_C_DECLS_END
48
49#ifdef RT_OS_SOLARIS
50# define VBOXSERVICE_AUTOMOUNT_DEFAULT_DIR "/mnt"
51#else
52# define VBOXSERVICE_AUTOMOUNT_DEFAULT_DIR "/media"
53#endif
54
55#ifndef _PATH_MOUNTED
56 #ifdef RT_OS_SOLARIS
57 #define _PATH_MOUNTED "/etc/mnttab"
58 #else
59 #define _PATH_MOUNTED "/etc/mtab"
60 #endif
61#endif
62
63/*******************************************************************************
64* Global Variables *
65*******************************************************************************/
66/** The semaphore we're blocking on. */
67static RTSEMEVENTMULTI g_AutoMountEvent = NIL_RTSEMEVENTMULTI;
68/** The Shared Folders service client ID. */
69static uint32_t g_SharedFoldersSvcClientID = 0;
70
71/** @copydoc VBOXSERVICE::pfnPreInit */
72static DECLCALLBACK(int) VBoxServiceAutoMountPreInit(void)
73{
74 return VINF_SUCCESS;
75}
76
77
78/** @copydoc VBOXSERVICE::pfnOption */
79static DECLCALLBACK(int) VBoxServiceAutoMountOption(const char **ppszShort, int argc, char **argv, int *pi)
80{
81 NOREF(ppszShort);
82 NOREF(argc);
83 NOREF(argv);
84 NOREF(pi);
85 return VINF_SUCCESS;
86}
87
88
89/** @copydoc VBOXSERVICE::pfnInit */
90static DECLCALLBACK(int) VBoxServiceAutoMountInit(void)
91{
92 VBoxServiceVerbose(3, "VBoxServiceAutoMountInit\n");
93
94 int rc = RTSemEventMultiCreate(&g_AutoMountEvent);
95 AssertRCReturn(rc, rc);
96
97 rc = VbglR3SharedFolderConnect(&g_SharedFoldersSvcClientID);
98 if (RT_SUCCESS(rc))
99 {
100 VBoxServiceVerbose(3, "VBoxServiceAutoMountInit: Service Client ID: %#x\n", g_SharedFoldersSvcClientID);
101 }
102 else
103 {
104 /* If the service was not found, we disable this service without
105 causing VBoxService to fail. */
106 if (rc == VERR_HGCM_SERVICE_NOT_FOUND) /* Host service is not available. */
107 {
108 VBoxServiceVerbose(0, "VBoxServiceAutoMountInit: Shared Folders service is not available\n");
109 rc = VERR_SERVICE_DISABLED;
110 }
111 else
112 VBoxServiceError("Control: Failed to connect to the Shared Folders service! Error: %Rrc\n", rc);
113 RTSemEventMultiDestroy(g_AutoMountEvent);
114 g_AutoMountEvent = NIL_RTSEMEVENTMULTI;
115 }
116
117 return rc;
118}
119
120
121/** @todo Integrate into RTFsQueryMountpoint(). */
122static bool VBoxServiceAutoMountShareIsMounted(const char *pszShare,
123 char *pszMountPoint, size_t cbMountPoint)
124{
125 AssertPtrReturn(pszShare, VERR_INVALID_PARAMETER);
126 AssertPtrReturn(pszMountPoint, VERR_INVALID_PARAMETER);
127 AssertReturn(cbMountPoint, VERR_INVALID_PARAMETER);
128
129 bool fMounted = false;
130 /* @todo What to do if we have a relative path in mtab instead
131 * of an absolute one ("temp" vs. "/media/temp")?
132 * procfs contains the full path but not the actual share name ...
133 * FILE *pFh = setmntent("/proc/mounts", "r+t"); */
134#ifdef RT_OS_SOLARIS
135 FILE *pFh = fopen(_PATH_MOUNTED, "r");
136 if (!pFh)
137 VBoxServiceError("VBoxServiceAutoMountShareIsMounted: Could not open mount tab \"%s\"!\n",
138 _PATH_MOUNTED);
139 else
140 {
141 mnttab mntTab;
142 while ((getmntent(pFh, &mntTab)))
143 {
144 if (!RTStrICmp(mntTab.mnt_special, pszShare))
145 {
146 fMounted = RTStrPrintf(pszMountPoint, cbMountPoint, "%s", mntTab.mnt_mountp)
147 ? true : false;
148 break;
149 }
150 }
151 fclose(pFh);
152 }
153#else
154 FILE *pFh = setmntent(_PATH_MOUNTED, "r+t");
155 if (pFh == NULL)
156 VBoxServiceError("VBoxServiceAutoMountShareIsMounted: Could not open mount tab \"%s\"!\n",
157 _PATH_MOUNTED);
158 else
159 {
160 mntent *pMntEnt;
161 while ((pMntEnt = getmntent(pFh)))
162 {
163 if (!RTStrICmp(pMntEnt->mnt_fsname, pszShare))
164 {
165 fMounted = RTStrPrintf(pszMountPoint, cbMountPoint, "%s", pMntEnt->mnt_dir)
166 ? true : false;
167 break;
168 }
169 }
170 endmntent(pFh);
171 }
172#endif
173
174 VBoxServiceVerbose(4, "VBoxServiceAutoMountShareIsMounted: Share \"%s\" at mount point \"%s\" = %s\n",
175 pszShare, fMounted ? pszMountPoint : "<None>", fMounted ? "Yes" : "No");
176 return fMounted;
177}
178
179
180static int VBoxServiceAutoMountUnmount(const char *pszMountPoint)
181{
182 AssertPtrReturn(pszMountPoint, VERR_INVALID_PARAMETER);
183
184 int rc = VINF_SUCCESS;
185 uint8_t uTries = 0;
186 int r;
187 while (uTries++ < 3)
188 {
189 r = umount(pszMountPoint);
190 if (r == 0)
191 break;
192 RTThreadSleep(5000); /* Wait a while ... */
193 }
194 if (r == -1)
195 rc = RTErrConvertFromErrno(errno);
196 return rc;
197}
198
199
200static int VBoxServiceAutoMountPrepareMountPoint(const char *pszMountPoint, const char *pszShareName,
201 vbsf_mount_opts *pOpts)
202{
203 AssertPtrReturn(pOpts, VERR_INVALID_PARAMETER);
204 AssertPtrReturn(pszMountPoint, VERR_INVALID_PARAMETER);
205 AssertPtrReturn(pszShareName, VERR_INVALID_PARAMETER);
206
207 RTFMODE fMode = RTFS_UNIX_IRWXU | RTFS_UNIX_IRWXG; /* Owner (=root) and the group (=vboxsf) have full access. */
208 int rc = RTDirCreateFullPath(pszMountPoint, fMode);
209 if (RT_SUCCESS(rc))
210 {
211 rc = RTPathSetOwnerEx(pszMountPoint, NIL_RTUID /* Owner, unchanged */, pOpts->gid, RTPATH_F_ON_LINK);
212 if (RT_SUCCESS(rc))
213 {
214 rc = RTPathSetMode(pszMountPoint, fMode);
215 if (RT_FAILURE(rc))
216 {
217 if (rc == VERR_WRITE_PROTECT)
218 {
219 VBoxServiceVerbose(3, "VBoxServiceAutoMountPrepareMountPoint: Mount directory \"%s\" already is used/mounted\n", pszMountPoint);
220 rc = VINF_SUCCESS;
221 }
222 else
223 VBoxServiceError("VBoxServiceAutoMountPrepareMountPoint: Could not set mode %RTfmode for mount directory \"%s\", rc = %Rrc\n",
224 fMode, pszMountPoint, rc);
225 }
226 }
227 else
228 VBoxServiceError("VBoxServiceAutoMountPrepareMountPoint: Could not set permissions for mount directory \"%s\", rc = %Rrc\n",
229 pszMountPoint, rc);
230 }
231 else
232 VBoxServiceError("VBoxServiceAutoMountPrepareMountPoint: Could not create mount directory \"%s\" with mode %RTfmode, rc = %Rrc\n",
233 pszMountPoint, fMode, rc);
234 return rc;
235}
236
237
238static int VBoxServiceAutoMountSharedFolder(const char *pszShareName, const char *pszMountPoint,
239 vbsf_mount_opts *pOpts)
240{
241 AssertPtr(pOpts);
242
243 int rc = VINF_SUCCESS;
244 char szAlreadyMountedTo[RTPATH_MAX];
245 /* If a Shared Folder already is mounted but not to our desired mount point,
246 * do an unmount first! */
247 if ( VBoxServiceAutoMountShareIsMounted(pszShareName, szAlreadyMountedTo, sizeof(szAlreadyMountedTo))
248 && RTStrICmp(pszMountPoint, szAlreadyMountedTo))
249 {
250 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Shared folder \"%s\" already mounted to \"%s\", unmounting ...\n",
251 pszShareName, szAlreadyMountedTo);
252 rc = VBoxServiceAutoMountUnmount(szAlreadyMountedTo);
253 if (RT_FAILURE(rc))
254 VBoxServiceError("VBoxServiceAutoMountWorker: Failed to unmount \"%s\", %s (%d)!\n",
255 szAlreadyMountedTo, strerror(errno), errno);
256 }
257
258 if (RT_SUCCESS(rc))
259 rc = VBoxServiceAutoMountPrepareMountPoint(pszMountPoint, pszShareName, pOpts);
260 if (RT_SUCCESS(rc))
261 {
262#ifdef RT_OS_SOLARIS
263 int flags = 0; /* No flags used yet. */
264 int r = mount(pszShareName,
265 pszMountPoint,
266 flags,
267 "vboxsf",
268 NULL, /* char *dataptr */
269 0, /* int datalen */
270 NULL, /* char *optptr */
271 0); /* int optlen */
272 if (r == 0)
273 {
274 VBoxServiceVerbose(0, "VBoxServiceAutoMountWorker: Shared folder \"%s\" was mounted to \"%s\"\n", pszShareName, pszMountPoint);
275 }
276 else
277 {
278 if (errno != EBUSY) /* Share is already mounted? Then skip error msg. */
279 VBoxServiceError("VBoxServiceAutoMountWorker: Could not mount shared folder \"%s\" to \"%s\", error = %s\n",
280 pszShareName, pszMountPoint, strerror(errno));
281 }
282#else /* !RT_OS_SOLARIS */
283 unsigned long flags = MS_NODEV;
284
285 const char *szOptions = { "rw" };
286 struct vbsf_mount_info_new mntinf;
287
288 mntinf.nullchar = '\0';
289 mntinf.signature[0] = VBSF_MOUNT_SIGNATURE_BYTE_0;
290 mntinf.signature[1] = VBSF_MOUNT_SIGNATURE_BYTE_1;
291 mntinf.signature[2] = VBSF_MOUNT_SIGNATURE_BYTE_2;
292 mntinf.length = sizeof(mntinf);
293
294 mntinf.uid = pOpts->uid;
295 mntinf.gid = pOpts->gid;
296 mntinf.ttl = pOpts->ttl;
297 mntinf.dmode = pOpts->dmode;
298 mntinf.fmode = pOpts->fmode;
299 mntinf.dmask = pOpts->dmask;
300 mntinf.fmask = pOpts->fmask;
301
302 strcpy(mntinf.name, pszShareName);
303 strcpy(mntinf.nls_name, "\0");
304
305 int r = mount(NULL,
306 pszMountPoint,
307 "vboxsf",
308 flags,
309 &mntinf);
310 if (r == 0)
311 {
312 VBoxServiceVerbose(0, "VBoxServiceAutoMountWorker: Shared folder \"%s\" was mounted to \"%s\"\n", pszShareName, pszMountPoint);
313
314 r = vbsfmount_complete(pszShareName, pszMountPoint, flags, pOpts);
315 switch (r)
316 {
317 case 0: /* Success. */
318 errno = 0; /* Clear all errors/warnings. */
319 break;
320
321 case 1:
322 VBoxServiceError("VBoxServiceAutoMountWorker: Could not update mount table (failed to create memstream): %s\n", strerror(errno));
323 break;
324
325 case 2:
326 VBoxServiceError("VBoxServiceAutoMountWorker: Could not open mount table for update: %s\n", strerror(errno));
327 break;
328
329 case 3:
330 VBoxServiceError("VBoxServiceAutoMountWorker: Could not add an entry to the mount table: %s\n", strerror(errno));
331 break;
332
333 default:
334 VBoxServiceError("VBoxServiceAutoMountWorker: Unknown error while completing mount operation: %d\n", r);
335 break;
336 }
337 }
338 else /* r == -1, we got some error in errno. */
339 {
340 if (errno == EPROTO)
341 {
342 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Messed up share name, re-trying ...\n");
343
344 /* Sometimes the mount utility messes up the share name. Try to
345 * un-mangle it again. */
346 char szCWD[4096];
347 size_t cchCWD;
348 if (!getcwd(szCWD, sizeof(szCWD)))
349 VBoxServiceError("VBoxServiceAutoMountWorker: Failed to get the current working directory\n");
350 cchCWD = strlen(szCWD);
351 if (!strncmp(pszMountPoint, szCWD, cchCWD))
352 {
353 while (pszMountPoint[cchCWD] == '/')
354 ++cchCWD;
355 /* We checked before that we have enough space */
356 strcpy(mntinf.name, pszMountPoint + cchCWD);
357 }
358 r = mount(NULL, pszMountPoint, "vboxsf", flags, &mntinf);
359 }
360 if (errno == EPROTO)
361 {
362 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Re-trying with old mounting structure ...\n");
363
364 /* New mount tool with old vboxsf module? Try again using the old
365 * vbsf_mount_info_old structure. */
366 struct vbsf_mount_info_old mntinf_old;
367 memcpy(&mntinf_old.name, &mntinf.name, MAX_HOST_NAME);
368 memcpy(&mntinf_old.nls_name, mntinf.nls_name, MAX_NLS_NAME);
369 mntinf_old.uid = mntinf.uid;
370 mntinf_old.gid = mntinf.gid;
371 mntinf_old.ttl = mntinf.ttl;
372 r = mount(NULL, pszMountPoint, "vboxsf", flags, &mntinf_old);
373 }
374 if (r == -1) /* Was there some error from one of the tries above? */
375 {
376 switch (errno)
377 {
378 /* If we get EINVAL here, the system already has mounted the Shared Folder to another
379 * mount point. */
380 case EINVAL:
381 VBoxServiceVerbose(0, "VBoxServiceAutoMountWorker: Shared folder \"%s\" already is mounted!\n", pszShareName);
382 /* Ignore this error! */
383 break;
384 case EBUSY:
385 /* Ignore these errors! */
386 break;
387
388 default:
389 VBoxServiceError("VBoxServiceAutoMountWorker: Could not mount shared folder \"%s\" to \"%s\": %s (%d)\n",
390 pszShareName, pszMountPoint, strerror(errno), errno);
391 rc = RTErrConvertFromErrno(errno);
392 break;
393 }
394 }
395 }
396#endif /* !RT_OS_SOLARIS */
397 }
398 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Mounting returned with rc=%Rrc\n", rc);
399 return rc;
400}
401
402static int VBoxServiceAutoMountProcessMappings(PVBGLR3SHAREDFOLDERMAPPING paMappings, uint32_t cMappings,
403 const char *pszMountDir, const char *pszSharePrefix, uint32_t uClientID)
404{
405 if (cMappings == 0)
406 return VINF_SUCCESS;
407 AssertPtrReturn(paMappings, VERR_INVALID_PARAMETER);
408 AssertPtrReturn(pszMountDir, VERR_INVALID_PARAMETER);
409 AssertPtrReturn(pszSharePrefix, VERR_INVALID_PARAMETER);
410 AssertReturn(uClientID > 0, VERR_INVALID_PARAMETER);
411
412 int rc = VINF_SUCCESS;
413 for (uint32_t i = 0; i < cMappings && RT_SUCCESS(rc); i++)
414 {
415 char *pszShareName = NULL;
416 rc = VbglR3SharedFolderGetName(uClientID, paMappings[i].u32Root, &pszShareName);
417 if ( RT_SUCCESS(rc)
418 && *pszShareName)
419 {
420 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Connecting share %u (%s) ...\n", i+1, pszShareName);
421
422 char *pszShareNameFull = NULL;
423 if (RTStrAPrintf(&pszShareNameFull, "%s%s", pszSharePrefix, pszShareName) > 0)
424 {
425 char szMountPoint[RTPATH_MAX];
426 rc = RTPathJoin(szMountPoint, sizeof(szMountPoint), pszMountDir, pszShareNameFull);
427 if (RT_SUCCESS(rc))
428 {
429 VBoxServiceVerbose(4, "VBoxServiceAutoMountWorker: Processing mount point \"%s\"\n", szMountPoint);
430
431 struct group *grp_vboxsf = getgrnam("vboxsf");
432 if (grp_vboxsf)
433 {
434 struct vbsf_mount_opts mount_opts =
435 {
436 0, /* uid */
437 grp_vboxsf->gr_gid, /* gid */
438 0, /* ttl */
439 0770, /* dmode, owner and group "vboxsf" have full access */
440 0770, /* fmode, owner and group "vboxsf" have full access */
441 0, /* dmask */
442 0, /* fmask */
443 0, /* ronly */
444 0, /* noexec */
445 0, /* nodev */
446 0, /* nosuid */
447 0, /* remount */
448 "\0", /* nls_name */
449 NULL, /* convertcp */
450 };
451
452 rc = VBoxServiceAutoMountSharedFolder(pszShareName, szMountPoint, &mount_opts);
453 }
454 else
455 VBoxServiceError("VBoxServiceAutoMountWorker: Group \"vboxsf\" does not exist\n");
456 }
457 else
458 VBoxServiceError("VBoxServiceAutoMountWorker: Unable to join mount point/prefix/shrae, rc = %Rrc\n", rc);
459 RTStrFree(pszShareNameFull);
460 }
461 else
462 VBoxServiceError("VBoxServiceAutoMountWorker: Unable to allocate full share name\n");
463 RTStrFree(pszShareName);
464 }
465 else
466 VBoxServiceError("VBoxServiceAutoMountWorker: Error while getting the shared folder name for root node = %u, rc = %Rrc\n",
467 paMappings[i].u32Root, rc);
468 } /* for cMappings. */
469 return rc;
470}
471
472
473/** @copydoc VBOXSERVICE::pfnWorker */
474DECLCALLBACK(int) VBoxServiceAutoMountWorker(bool volatile *pfShutdown)
475{
476 /*
477 * Tell the control thread that it can continue
478 * spawning services.
479 */
480 RTThreadUserSignal(RTThreadSelf());
481
482 uint32_t cMappings;
483 PVBGLR3SHAREDFOLDERMAPPING paMappings;
484 int rc = VbglR3SharedFolderGetMappings(g_SharedFoldersSvcClientID, true /* Only process auto-mounted folders */,
485 &paMappings, &cMappings);
486 if ( RT_SUCCESS(rc)
487 && cMappings)
488 {
489 char *pszMountDir;
490 rc = VbglR3SharedFolderGetMountDir(&pszMountDir);
491 if (rc == VERR_NOT_FOUND)
492 rc = RTStrDupEx(&pszMountDir, VBOXSERVICE_AUTOMOUNT_DEFAULT_DIR);
493 if (RT_SUCCESS(rc))
494 {
495 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Shared folder mount dir set to \"%s\"\n", pszMountDir);
496
497 char *pszSharePrefix;
498 rc = VbglR3SharedFolderGetMountPrefix(&pszSharePrefix);
499 if (RT_SUCCESS(rc))
500 {
501 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Shared folder mount prefix set to \"%s\"\n", pszSharePrefix);
502#ifdef USE_VIRTUAL_SHARES
503 /* Check for a fixed/virtual auto-mount share. */
504 if (VbglR3SharedFolderExists(g_SharedFoldersSvcClientID, "vbsfAutoMount"))
505 {
506 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Host supports auto-mount root\n");
507 }
508 else
509 {
510#endif
511 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Got %u shared folder mappings\n", cMappings);
512 rc = VBoxServiceAutoMountProcessMappings(paMappings, cMappings, pszMountDir, pszSharePrefix, g_SharedFoldersSvcClientID);
513#ifdef USE_VIRTUAL_SHARES
514 }
515#endif
516 RTStrFree(pszSharePrefix);
517 } /* Mount share prefix. */
518 else
519 VBoxServiceError("VBoxServiceAutoMountWorker: Error while getting the shared folder mount prefix, rc = %Rrc\n", rc);
520 RTStrFree(pszMountDir);
521 }
522 else
523 VBoxServiceError("VBoxServiceAutoMountWorker: Error while getting the shared folder directory, rc = %Rrc\n", rc);
524 VbglR3SharedFolderFreeMappings(paMappings);
525 }
526 else
527 {
528 if (RT_FAILURE(rc))
529 VBoxServiceError("VBoxServiceAutoMountWorker: Error while getting the shared folder mappings, rc = %Rrc\n", rc);
530 else if (!cMappings)
531 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: No shared folder mappings fouund\n");
532 }
533
534 /*
535 * Because this thread is a one-timer at the moment we don't want to break/change
536 * the semantics of the main thread's start/stop sub-threads handling.
537 *
538 * This thread exits so fast while doing its own startup in VBoxServiceStartServices()
539 * that this->fShutdown flag is set to true in VBoxServiceThread() before we have the
540 * chance to check for a service failure in VBoxServiceStartServices() to indicate
541 * a VBoxService startup error.
542 *
543 * Therefore *no* service threads are allowed to quit themselves and need to wait
544 * for the pfShutdown flag to be set by the main thread.
545 */
546 for (;;)
547 {
548 /* Do we need to shutdown? */
549 if (*pfShutdown)
550 break;
551
552 /* Let's sleep for a bit and let others run ... */
553 RTThreadSleep(500);
554 }
555
556 RTSemEventMultiDestroy(g_AutoMountEvent);
557 g_AutoMountEvent = NIL_RTSEMEVENTMULTI;
558
559 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Finished with rc=%Rrc\n", rc);
560 return VINF_SUCCESS;
561}
562
563/** @copydoc VBOXSERVICE::pfnTerm */
564static DECLCALLBACK(void) VBoxServiceAutoMountTerm(void)
565{
566 VBoxServiceVerbose(3, "VBoxServiceAutoMountTerm\n");
567
568 VbglR3SharedFolderDisconnect(g_SharedFoldersSvcClientID);
569 g_SharedFoldersSvcClientID = 0;
570
571 if (g_AutoMountEvent != NIL_RTSEMEVENTMULTI)
572 {
573 RTSemEventMultiDestroy(g_AutoMountEvent);
574 g_AutoMountEvent = NIL_RTSEMEVENTMULTI;
575 }
576 return;
577}
578
579
580/** @copydoc VBOXSERVICE::pfnStop */
581static DECLCALLBACK(void) VBoxServiceAutoMountStop(void)
582{
583 /*
584 * We need this check because at the moment our auto-mount
585 * thread really is a one-timer which destroys the event itself
586 * after running.
587 */
588 if (g_AutoMountEvent != NIL_RTSEMEVENTMULTI)
589 RTSemEventMultiSignal(g_AutoMountEvent);
590}
591
592
593/**
594 * The 'automount' service description.
595 */
596VBOXSERVICE g_AutoMount =
597{
598 /* pszName. */
599 "automount",
600 /* pszDescription. */
601 "Auto-mount for Shared Folders",
602 /* pszUsage. */
603 NULL,
604 /* pszOptions. */
605 NULL,
606 /* methods */
607 VBoxServiceAutoMountPreInit,
608 VBoxServiceAutoMountOption,
609 VBoxServiceAutoMountInit,
610 VBoxServiceAutoMountWorker,
611 VBoxServiceAutoMountStop,
612 VBoxServiceAutoMountTerm
613};
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