VirtualBox

source: vbox/trunk/src/VBox/Installer/solaris/VBoxZoneAccess.c@ 101351

Last change on this file since 101351 was 98103, checked in by vboxsync, 21 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 3.3 KB
Line 
1/* $Id: VBoxZoneAccess.c 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBoxZoneAccess - Hack that keeps vboxdrv referenced for granting zone access, Solaris hosts.
4 */
5
6/*
7 * Copyright (C) 2006-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
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#include <stdio.h>
33#include <signal.h>
34#include <unistd.h>
35#include <fcntl.h>
36#include <errno.h>
37
38#include <iprt/process.h>
39
40
41/*********************************************************************************************************************************
42* Defined Constants And Macros *
43*********************************************************************************************************************************/
44#define DEVICE_NAME "/devices/pseudo/vboxdrv@0:vboxdrv"
45#define DEVICE_NAME_USR "/devices/pseudo/vboxdrv@0:vboxdrvu"
46
47int main(int argc, char *argv[])
48{
49 int hDevice = -1;
50 int hDeviceUsr = -1;
51
52 /* Check root permissions. */
53 if (geteuid() != 0)
54 {
55 fprintf(stderr, "This program needs administrator privileges.\n");
56 return -1;
57 }
58
59 /* Daemonize... */
60 RTProcDaemonizeUsingFork(false /* fNoChDir */,
61 false /* fNoClose */,
62 NULL /* pszPidfile */);
63
64 /* Open the device */
65 hDevice = open(DEVICE_NAME, O_RDWR, 0);
66 if (hDevice < 0)
67 {
68 fprintf(stderr, "Failed to open '%s'. errno=%d\n", DEVICE_NAME, errno);
69 return errno;
70 }
71
72 /* Open the user device. */
73 hDeviceUsr = open(DEVICE_NAME_USR, O_RDWR, 0);
74 if (hDeviceUsr < 0)
75 {
76 fprintf(stderr, "Failed to open '%s'. errno=%d\n", DEVICE_NAME_USR, errno);
77 close(hDevice);
78 return errno;
79 }
80
81 /* Mark the file handle close on exec. */
82 if ( fcntl(hDevice, F_SETFD, FD_CLOEXEC) != 0
83 || fcntl(hDeviceUsr, F_SETFD, FD_CLOEXEC) != 0)
84 {
85 fprintf(stderr, "Failed to set close on exec. errno=%d\n", errno);
86 close(hDevice);
87 close(hDeviceUsr);
88 return errno;
89 }
90
91 /* Go to interruptible sleep for ~15 years... */
92 /* avoid > 2^31 for Year 2038 32-bit overflow (Solaris 10) */
93 sleep(500000000U);
94
95 close(hDevice);
96 close(hDeviceUsr);
97
98 return 0;
99}
100
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