libnm: remove nm_utils_init() from the public API

Remove nm_utils_init() from the public API, and just do it as a
constructor instead.
This commit is contained in:
Dan Winship
2014-12-01 14:43:01 -05:00
parent bddc0de51e
commit 3b86cc047e
11 changed files with 15 additions and 71 deletions

View File

@@ -164,7 +164,6 @@ inline static void
__nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_level, const char *log_domains)
{
static gsize atexit_registered = 0;
GError *error = NULL;
const char *nmtst_debug;
gboolean is_debug = FALSE;
char *c_log_level = NULL, *c_log_domains = NULL;
@@ -300,10 +299,6 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
}
if (!nm_utils_init (&error))
g_error ("failed to initialize libnm-util: %s", error->message);
g_assert (!error);
/* Delay messages until we setup logging. */
for (i = 0; i < debug_messages->len; i++)
__NMTST_LOG (g_message, "%s", g_array_index (debug_messages, const char *, i));

View File

@@ -212,41 +212,29 @@ get_encodings_for_lang (const char *lang,
/* init libnm */
static gboolean initialized = FALSE;
static void __attribute__((constructor))
_check_symbols (void)
_nm_utils_init (void)
{
GModule *self;
gpointer func;
if (initialized)
return;
initialized = TRUE;
self = g_module_open (NULL, 0);
if (g_module_symbol (self, "nm_util_get_private", &func))
g_error ("libnm-util symbols detected; Mixing libnm with libnm-util/libnm-glib is not supported");
g_module_close (self);
}
static gboolean initialized = FALSE;
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
/**
* nm_utils_init:
* @error: location to store error, or %NULL
*
* Initializes libnm; should be called when starting and program that
* uses libnm. This function can be called more than once.
*
* Returns: %TRUE if the initialization was successful, %FALSE on failure.
**/
gboolean
nm_utils_init (GError **error)
{
if (!initialized) {
initialized = TRUE;
g_type_init ();
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
_nm_dbus_errors_init ();
}
return TRUE;
_nm_dbus_errors_init ();
}
gboolean _nm_utils_is_manager_process;

View File

@@ -39,9 +39,6 @@
G_BEGIN_DECLS
/* init libnm */
gboolean nm_utils_init (GError **error);
/* SSID helpers */
gboolean nm_utils_is_empty_ssid (const guint8 *ssid, gsize len);
const char *nm_utils_escape_ssid (const guint8 *ssid, gsize len);

View File

@@ -302,21 +302,15 @@ test_dcb_bandwidth_sums (void)
#define TPATH "/libnm/settings/dcb/"
int main (int argc, char **argv)
int
main (int argc, char **argv)
{
GError *error = NULL;
gboolean success;
g_test_init (&argc, &argv, NULL);
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
success = nm_utils_init (&error);
g_assert_no_error (error);
g_assert (success);
#if !GLIB_CHECK_VERSION(2,34,0)
g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
#endif

View File

@@ -101,18 +101,15 @@ test_defaults (GType type, const char *name)
g_object_unref (setting);
}
int main (int argc, char **argv)
int
main (int argc, char **argv)
{
GError *error = NULL;
char *base;
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
if (!nm_utils_init (&error))
FAIL ("nm-utils-init", "failed to initialize libnm: %s", error->message);
/* The tests */
test_defaults (NM_TYPE_SETTING_CONNECTION, NM_SETTING_CONNECTION_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_802_1X, NM_SETTING_802_1X_SETTING_NAME);

View File

@@ -159,8 +159,6 @@ args = parser.parse_args()
if args.gir is None or args.output is None:
usage()
NM.utils_init()
girxml = ET.parse(args.gir).getroot()
outfile = open(args.output, mode='w')

View File

@@ -770,7 +770,6 @@ global:
nm_utils_iface_valid_name;
nm_utils_inet4_ntop;
nm_utils_inet6_ntop;
nm_utils_init;
nm_utils_ip4_addresses_from_variant;
nm_utils_ip4_addresses_to_variant;
nm_utils_ip4_dns_from_variant;

View File

@@ -1788,13 +1788,6 @@ init_async (GAsyncInitable *initable, int io_priority,
{
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (initable);
NMClientInitData *init_data;
GError *error = NULL;
if (!nm_utils_init (&error)) {
g_simple_async_report_take_gerror_in_idle (G_OBJECT (initable),
callback, user_data, error);
return;
}
init_data = g_slice_new0 (NMClientInitData);
init_data->client = NM_CLIENT (initable);

View File

@@ -1306,9 +1306,6 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
{
NMManager *manager = NM_MANAGER (initable);
if (!nm_utils_init (error))
return FALSE;
if (!nm_manager_parent_initable_iface->init (initable, cancellable, error))
return FALSE;
@@ -1380,13 +1377,6 @@ init_async (GAsyncInitable *initable, int io_priority,
gpointer user_data)
{
NMManagerInitData *init_data;
GError *error = NULL;
if (!nm_utils_init (&error)) {
g_simple_async_report_take_gerror_in_idle (G_OBJECT (initable),
callback, user_data, error);
return;
}
init_data = g_slice_new0 (NMManagerInitData);
init_data->manager = NM_MANAGER (initable);

View File

@@ -242,9 +242,6 @@ nm_main_utils_early_setup (const char *progname,
/* Ensure gettext() gets the right environment (bgo #666516) */
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, NMLOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
if (getuid () != 0) {

View File

@@ -847,14 +847,10 @@ test20_source_stanza (const char *path)
int
main (int argc, char **argv)
{
GError *error = NULL;
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
if (!nm_utils_init (&error))
FAIL ("nm-utils-init", "failed to initialize libnm: %s", error->message);
nm_logging_setup ("WARN", "DEFAULT", NULL, NULL);
g_test_init (&argc, &argv, NULL);