1 | /* $Id: VBoxZoneAccess.c 17324 2009-03-04 08:09:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxZoneAccess - Hack that keeps vboxdrv referenced for granting zone access, Solaris hosts.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*******************************************************************************
|
---|
23 | * Header Files *
|
---|
24 | *******************************************************************************/
|
---|
25 | #include <stdio.h>
|
---|
26 | #include <signal.h>
|
---|
27 | #include <unistd.h>
|
---|
28 | #include <fcntl.h>
|
---|
29 | #include <errno.h>
|
---|
30 |
|
---|
31 | #include <iprt/process.h>
|
---|
32 |
|
---|
33 | #define DEVICE_NAME "/dev/vboxdrv"
|
---|
34 |
|
---|
35 | int main(int argc, char *argv[])
|
---|
36 | {
|
---|
37 | int hDevice = -1;
|
---|
38 |
|
---|
39 | /* Check root permissions. */
|
---|
40 | if (geteuid() != 0)
|
---|
41 | {
|
---|
42 | fprintf(stderr, "This program needs administrator privileges.\n");
|
---|
43 | return -1;
|
---|
44 | }
|
---|
45 |
|
---|
46 | /* Daemonize... */
|
---|
47 | RTProcDaemonize(false /* fNoChDir */,
|
---|
48 | false /* fNoClose */,
|
---|
49 | NULL /* pszPidfile */);
|
---|
50 |
|
---|
51 | /* Open the device */
|
---|
52 | hDevice = open(DEVICE_NAME, O_RDWR, 0);
|
---|
53 | if (hDevice < 0)
|
---|
54 | {
|
---|
55 | fprintf(stderr, "Failed to open '%s'. errno=%d\n", DEVICE_NAME, errno);
|
---|
56 | return errno;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /* Mark the file handle close on exec. */
|
---|
60 | if (fcntl(hDevice, F_SETFD, FD_CLOEXEC) != 0)
|
---|
61 | {
|
---|
62 | fprintf(stderr, "Failed to set close on exec. errno=%d\n", errno);
|
---|
63 | close(hDevice);
|
---|
64 | return errno;
|
---|
65 | }
|
---|
66 |
|
---|
67 | /* Go to interruptible sleep for ~15 years... */
|
---|
68 | /* avoid > 2^31 for Year 2038 32-bit overflow (Solaris 10) */
|
---|
69 | sleep(500000000U);
|
---|
70 |
|
---|
71 | close(hDevice);
|
---|
72 |
|
---|
73 | return 0;
|
---|
74 | }
|
---|
75 |
|
---|