-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlibvirt_generated_dlopen.go
113 lines (100 loc) · 3.24 KB
/
libvirt_generated_dlopen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//go:build libvirt_dlopen
// +build libvirt_dlopen
/*
* This file is part of the libvirt-go-module project
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Copyright (C) 2022 Red Hat, Inc.
*
*/
/****************************************************************************
* THIS CODE HAS BEEN GENERATED. DO NOT CHANGE IT DIRECTLY *
****************************************************************************/
package libvirt
/*
#cgo libvirt_dlopen LDFLAGS: -ldl
#cgo libvirt_dlopen CFLAGS: -DLIBVIRT_DLOPEN
#include <dlfcn.h>
#include <stdbool.h>
#include <stdio.h>
#include "libvirt_generated_dlopen.h"
#include "error_helper.h"
static void *handle;
static bool once;
virConnectAuthPtr *virConnectAuthPtrDefaultVar;
static void *
libvirtLoad(virErrorPtr err)
{
char *errMsg;
if (once) {
if (handle == NULL) {
setVirError(err, "Failed to open libvirt.so.0");
}
return handle;
}
handle = dlopen("libvirt.so.0", RTLD_NOW|RTLD_LOCAL);
once = true;
if (handle == NULL) {
setVirError(err, dlerror());
return handle;
}
virConnectAuthPtrDefaultVar = dlsym(handle, "virConnectAuthPtrDefault");
if ((errMsg = dlerror()) != NULL) {
setVirError(err, errMsg);
dlclose(handle);
return NULL;
}
return handle;
}
bool
libvirtSymbol(const char *name,
void **symbol,
bool *once,
bool *success,
virErrorPtr err)
{
char *errMsg;
if (!libvirtLoad(err)) {
return *success;
}
if (*once) {
if (!*success) {
// Set error for successive calls
char msg[100];
snprintf(msg, 100, "Failed to load %s", name);
setVirError(err, msg);
}
return *success;
}
// Documentation of dlsym says we should use dlerror() to check for failure
// in dlsym() as a NULL might be the right address for a given symbol.
// This is also the reason to have the @success argument.
*symbol = dlsym(handle, name);
if ((errMsg = dlerror()) != NULL) {
setVirError(err, errMsg);
*once = true;
return *success;
}
*once = true;
*success = true;
return *success;
}
*/
import "C"