VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/linux/vbox-libhal.cpp@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: vbox-libhal.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 *
4 * Module to dynamically load libhal and libdbus and load all symbols
5 * which are needed by VirtualBox.
6 */
7
8/*
9 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
10 *
11 * This file is part of VirtualBox base platform packages, as
12 * available from https://www.virtualbox.org.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation, in version 3 of the
17 * License.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see <https://www.gnu.org/licenses>.
26 *
27 * SPDX-License-Identifier: GPL-3.0-only
28 */
29
30#include "vbox-libhal.h"
31
32#include <iprt/errcore.h>
33#include <iprt/ldr.h>
34
35/**
36 * Whether we have tried to load libdbus and libhal yet. This flag should only be set
37 * to "true" after we have either loaded both libraries and all symbols which we need,
38 * or failed to load something and unloaded and set back to zero pLibDBus and pLibHal.
39 */
40static bool gCheckedForLibHal = false;
41/**
42 * Pointer to the libhal shared object. This should only be set once all needed libraries
43 * and symbols have been successfully loaded.
44 */
45static RTLDRMOD ghLibHal = 0;
46
47/** The following are the symbols which we need from libdbus and libhal. */
48void (*gDBusErrorInit)(DBusError *);
49DBusConnection *(*gDBusBusGet)(DBusBusType, DBusError *);
50void (*gDBusErrorFree)(DBusError *);
51void (*gDBusConnectionUnref)(DBusConnection *);
52LibHalContext *(*gLibHalCtxNew)(void);
53dbus_bool_t (*gLibHalCtxSetDBusConnection)(LibHalContext *, DBusConnection *);
54dbus_bool_t (*gLibHalCtxInit)(LibHalContext *, DBusError *);
55char **(*gLibHalFindDeviceStringMatch)(LibHalContext *, const char *, const char *, int *,
56 DBusError *);
57char *(*gLibHalDeviceGetPropertyString)(LibHalContext *, const char *, const char *, DBusError *);
58void (*gLibHalFreeString)(char *);
59void (*gLibHalFreeStringArray)(char **);
60dbus_bool_t (*gLibHalCtxShutdown)(LibHalContext *, DBusError *);
61dbus_bool_t (*gLibHalCtxFree)(LibHalContext *);
62
63bool gLibHalCheckPresence(void)
64{
65 RTLDRMOD hLibHal;
66
67 if (ghLibHal != 0 && gCheckedForLibHal == true)
68 return true;
69 if (gCheckedForLibHal == true)
70 return false;
71 if (!RT_SUCCESS(RTLdrLoad(LIB_HAL, &hLibHal)))
72 {
73 return false;
74 }
75 if ( RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_error_init", (void **) &gDBusErrorInit))
76 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_bus_get", (void **) &gDBusBusGet))
77 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_error_free", (void **) &gDBusErrorFree))
78 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_connection_unref",
79 (void **) &gDBusConnectionUnref))
80 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_new", (void **) &gLibHalCtxNew))
81 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_set_dbus_connection",
82 (void **) &gLibHalCtxSetDBusConnection))
83 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_init", (void **) &gLibHalCtxInit))
84 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_manager_find_device_string_match",
85 (void **) &gLibHalFindDeviceStringMatch))
86 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_device_get_property_string",
87 (void **) &gLibHalDeviceGetPropertyString))
88 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string", (void **) &gLibHalFreeString))
89 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string_array",
90 (void **) &gLibHalFreeStringArray))
91 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_shutdown", (void **) &gLibHalCtxShutdown))
92 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_free", (void **) &gLibHalCtxFree))
93 )
94 {
95 ghLibHal = hLibHal;
96 gCheckedForLibHal = true;
97 return true;
98 }
99 else
100 {
101 RTLdrClose(hLibHal);
102 gCheckedForLibHal = true;
103 return false;
104 }
105}
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