mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 17:30:16 +01:00
We use clang-format for automatic formatting of our source files. Since clang-format is actively maintained software, the actual formatting depends on the used version of clang-format. That is unfortunate and painful, but really unavoidable unless clang-format would be strictly bug-compatible. So the version that we must use is from the current Fedora release, which is also tested by our gitlab-ci. Previously, we were using Fedora 34 with clang-tools-extra-12.0.1-1.fc34.x86_64. As Fedora 35 comes along, we need to update our formatting as Fedora 35 comes with version "13.0.0~rc1-1.fc35". An alternative would be to freeze on version 12, but that has different problems (like, it's cumbersome to rebuild clang 12 on Fedora 35 and it would be cumbersome for our developers which are on Fedora 35 to use a clang that they cannot easily install). The (differently painful) solution is to reformat from time to time, as we switch to a new Fedora (and thus clang) version. Usually we would expect that such a reformatting brings minor changes. But this time, the changes are huge. That is mentioned in the release notes [1] as Makes PointerAligment: Right working with AlignConsecutiveDeclarations. (Fixes https://llvm.org/PR27353) [1] https://releases.llvm.org/13.0.0/tools/clang/docs/ReleaseNotes.html#clang-format
138 lines
5.3 KiB
C
138 lines
5.3 KiB
C
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2016, 2018 Red Hat, Inc.
|
|
*/
|
|
|
|
#include "libnm-client-aux-extern/nm-default-client.h"
|
|
|
|
#include "nm-vpn-plugin-utils.h"
|
|
|
|
#include <dlfcn.h>
|
|
|
|
/*****************************************************************************/
|
|
|
|
NMVpnEditor *
|
|
nm_vpn_plugin_utils_load_editor(const char *module_name,
|
|
const char *factory_name,
|
|
NMVpnPluginUtilsEditorFactory editor_factory,
|
|
NMVpnEditorPlugin *editor_plugin,
|
|
NMConnection *connection,
|
|
gpointer user_data,
|
|
GError **error)
|
|
|
|
{
|
|
static struct {
|
|
gpointer factory;
|
|
void *dl_module;
|
|
char *module_name;
|
|
char *factory_name;
|
|
} cached = {0};
|
|
NMVpnEditor *editor;
|
|
gs_free char *module_path = NULL;
|
|
gs_free char *dirname = NULL;
|
|
Dl_info plugin_info;
|
|
|
|
g_return_val_if_fail(module_name, NULL);
|
|
g_return_val_if_fail(factory_name && factory_name[0], NULL);
|
|
g_return_val_if_fail(editor_factory, NULL);
|
|
g_return_val_if_fail(NM_IS_VPN_EDITOR_PLUGIN(editor_plugin), NULL);
|
|
g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
|
|
g_return_val_if_fail(!error || !*error, NULL);
|
|
|
|
if (!g_path_is_absolute(module_name)) {
|
|
/*
|
|
* Load an editor from the same directory this plugin is in.
|
|
* Ideally, we'd get our .so name from the NMVpnEditorPlugin if it
|
|
* would just have a property with it...
|
|
*/
|
|
if (!dladdr(nm_vpn_plugin_utils_load_editor, &plugin_info)) {
|
|
/* Really a "can not happen" scenario. */
|
|
g_set_error(error,
|
|
NM_VPN_PLUGIN_ERROR,
|
|
NM_VPN_PLUGIN_ERROR_FAILED,
|
|
_("unable to get editor plugin name: %s"),
|
|
dlerror());
|
|
}
|
|
|
|
dirname = g_path_get_dirname(plugin_info.dli_fname);
|
|
module_path = g_build_filename(dirname, module_name, NULL);
|
|
} else {
|
|
module_path = g_strdup(module_name);
|
|
}
|
|
|
|
/* we really expect this function to be called with unchanging @module_name
|
|
* and @factory_name. And we only want to load the module once, hence it would
|
|
* be more complicated to accept changing @module_name/@factory_name arguments.
|
|
*
|
|
* The reason for only loading once is that due to glib types, we cannot create a
|
|
* certain type-name more then once, so loading the same module or another version
|
|
* of the same module will fail horribly as both try to create a GType with the same
|
|
* name.
|
|
*
|
|
* Only support loading once, any future calls will reuse the handle. To simplify
|
|
* that, we enforce that the @factory_name and @module_name is the same. */
|
|
if (cached.factory) {
|
|
g_return_val_if_fail(cached.dl_module, NULL);
|
|
g_return_val_if_fail(cached.factory_name && nm_streq0(cached.factory_name, factory_name),
|
|
NULL);
|
|
g_return_val_if_fail(cached.module_name && nm_streq0(cached.module_name, module_name),
|
|
NULL);
|
|
} else {
|
|
gpointer factory;
|
|
void *dl_module;
|
|
|
|
dl_module = dlopen(module_path, RTLD_LAZY | RTLD_LOCAL);
|
|
if (!dl_module) {
|
|
if (!g_file_test(module_path, G_FILE_TEST_EXISTS)) {
|
|
g_set_error(error,
|
|
G_FILE_ERROR,
|
|
G_FILE_ERROR_NOENT,
|
|
_("missing plugin file \"%s\""),
|
|
module_path);
|
|
return NULL;
|
|
}
|
|
g_set_error(error,
|
|
NM_VPN_PLUGIN_ERROR,
|
|
NM_VPN_PLUGIN_ERROR_FAILED,
|
|
_("cannot load editor plugin: %s"),
|
|
dlerror());
|
|
return NULL;
|
|
}
|
|
|
|
factory = dlsym(dl_module, factory_name);
|
|
if (!factory) {
|
|
g_set_error(error,
|
|
NM_VPN_PLUGIN_ERROR,
|
|
NM_VPN_PLUGIN_ERROR_FAILED,
|
|
_("cannot load factory %s from plugin: %s"),
|
|
factory_name,
|
|
dlerror());
|
|
dlclose(dl_module);
|
|
return NULL;
|
|
}
|
|
|
|
/* we cannot ever unload the module because it creates glib types, which
|
|
* cannot be unregistered.
|
|
*
|
|
* Thus we just leak the dl_module handle indefinitely. */
|
|
cached.factory = factory;
|
|
cached.dl_module = dl_module;
|
|
cached.module_name = g_strdup(module_name);
|
|
cached.factory_name = g_strdup(factory_name);
|
|
}
|
|
|
|
editor = editor_factory(cached.factory, editor_plugin, connection, user_data, error);
|
|
if (!editor) {
|
|
if (error && !*error) {
|
|
g_set_error_literal(error,
|
|
NM_VPN_PLUGIN_ERROR,
|
|
NM_VPN_PLUGIN_ERROR_FAILED,
|
|
_("unknown error creating editor instance"));
|
|
g_return_val_if_reached(NULL);
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
g_return_val_if_fail(NM_IS_VPN_EDITOR(editor), NULL);
|
|
return editor;
|
|
}
|