VirtualBox

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

Last change on this file since 78273 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1/* $Id: vbox-libhal.cpp 76553 2019-01-01 01:45:53Z 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-2019 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include "vbox-libhal.h"
21
22#include <iprt/errcore.h>
23#include <iprt/ldr.h>
24
25/**
26 * Whether we have tried to load libdbus and libhal yet. This flag should only be set
27 * to "true" after we have either loaded both libraries and all symbols which we need,
28 * or failed to load something and unloaded and set back to zero pLibDBus and pLibHal.
29 */
30static bool gCheckedForLibHal = false;
31/**
32 * Pointer to the libhal shared object. This should only be set once all needed libraries
33 * and symbols have been successfully loaded.
34 */
35static RTLDRMOD ghLibHal = 0;
36
37/** The following are the symbols which we need from libdbus and libhal. */
38void (*gDBusErrorInit)(DBusError *);
39DBusConnection *(*gDBusBusGet)(DBusBusType, DBusError *);
40void (*gDBusErrorFree)(DBusError *);
41void (*gDBusConnectionUnref)(DBusConnection *);
42LibHalContext *(*gLibHalCtxNew)(void);
43dbus_bool_t (*gLibHalCtxSetDBusConnection)(LibHalContext *, DBusConnection *);
44dbus_bool_t (*gLibHalCtxInit)(LibHalContext *, DBusError *);
45char **(*gLibHalFindDeviceStringMatch)(LibHalContext *, const char *, const char *, int *,
46 DBusError *);
47char *(*gLibHalDeviceGetPropertyString)(LibHalContext *, const char *, const char *, DBusError *);
48void (*gLibHalFreeString)(char *);
49void (*gLibHalFreeStringArray)(char **);
50dbus_bool_t (*gLibHalCtxShutdown)(LibHalContext *, DBusError *);
51dbus_bool_t (*gLibHalCtxFree)(LibHalContext *);
52
53bool gLibHalCheckPresence(void)
54{
55 RTLDRMOD hLibHal;
56
57 if (ghLibHal != 0 && gCheckedForLibHal == true)
58 return true;
59 if (gCheckedForLibHal == true)
60 return false;
61 if (!RT_SUCCESS(RTLdrLoad(LIB_HAL, &hLibHal)))
62 {
63 return false;
64 }
65 if ( RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_error_init", (void **) &gDBusErrorInit))
66 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_bus_get", (void **) &gDBusBusGet))
67 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_error_free", (void **) &gDBusErrorFree))
68 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "dbus_connection_unref",
69 (void **) &gDBusConnectionUnref))
70 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_new", (void **) &gLibHalCtxNew))
71 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_set_dbus_connection",
72 (void **) &gLibHalCtxSetDBusConnection))
73 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_init", (void **) &gLibHalCtxInit))
74 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_manager_find_device_string_match",
75 (void **) &gLibHalFindDeviceStringMatch))
76 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_device_get_property_string",
77 (void **) &gLibHalDeviceGetPropertyString))
78 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string", (void **) &gLibHalFreeString))
79 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_free_string_array",
80 (void **) &gLibHalFreeStringArray))
81 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_shutdown", (void **) &gLibHalCtxShutdown))
82 && RT_SUCCESS(RTLdrGetSymbol(hLibHal, "libhal_ctx_free", (void **) &gLibHalCtxFree))
83 )
84 {
85 ghLibHal = hLibHal;
86 gCheckedForLibHal = true;
87 return true;
88 }
89 else
90 {
91 RTLdrClose(hLibHal);
92 gCheckedForLibHal = true;
93 return false;
94 }
95}
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