VirtualBox

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

Last change on this file since 96313 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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