NetworkManager r4047 - in trunk: . libnm-util
- From: dcbw svn gnome org
- To: svn-commits-list gnome org
- Subject: NetworkManager r4047 - in trunk: . libnm-util
- Date: Mon, 8 Sep 2008 18:35:21 +0000 (UTC)
Author: dcbw
Date: Mon Sep 8 18:35:21 2008
New Revision: 4047
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=4047&view=rev
Log:
2008-09-08 Dan Williams <dcbw redhat com>
Patch from Alexander Sack <asac ubuntu com>
* libnm-util/crypto_gnutls.c
libnm-util/crypto_nss.c
- (crypto_init, crypto_deinit): just use a boolean instead of a refcount
* libnm-util/nm-utils.c
libnm-util/nm-utils.h
libnm-util/libnm-util.ver
- (nm_utils_init): initialize libnm-util
- (nm_utils_deinit): de-initialize libnm-util and clean up resources
* libnm-util/nm-setting-8021x.c
- (nm_setting_802_1x_class_init): init libnm-util when needed
Modified:
trunk/ChangeLog
trunk/libnm-util/crypto_gnutls.c
trunk/libnm-util/crypto_nss.c
trunk/libnm-util/libnm-util.ver
trunk/libnm-util/nm-setting-8021x.c
trunk/libnm-util/nm-utils.c
trunk/libnm-util/nm-utils.h
Modified: trunk/libnm-util/crypto_gnutls.c
==============================================================================
--- trunk/libnm-util/crypto_gnutls.c (original)
+++ trunk/libnm-util/crypto_gnutls.c Mon Sep 8 18:35:21 2008
@@ -29,30 +29,31 @@
#include "crypto.h"
-static guint32 refcount = 0;
+static gboolean initialized = FALSE;
gboolean
crypto_init (GError **error)
{
- if (refcount == 0) {
- if (gnutls_global_init() != 0) {
- gnutls_global_deinit();
- g_set_error (error, NM_CRYPTO_ERROR,
- NM_CRYPTO_ERR_INIT_FAILED,
- "%s",
- _("Failed to initialize the crypto engine."));
- return FALSE;
- }
+ if (initialized)
+ return TRUE;
+
+ if (gnutls_global_init() != 0) {
+ gnutls_global_deinit();
+ g_set_error (error, NM_CRYPTO_ERROR,
+ NM_CRYPTO_ERR_INIT_FAILED,
+ "%s",
+ _("Failed to initialize the crypto engine."));
+ return FALSE;
}
- refcount++;
+
+ initialized = TRUE;
return TRUE;
}
void
crypto_deinit (void)
{
- refcount--;
- if (refcount == 0)
+ if (initialized)
gnutls_global_deinit();
}
Modified: trunk/libnm-util/crypto_nss.c
==============================================================================
--- trunk/libnm-util/crypto_nss.c (original)
+++ trunk/libnm-util/crypto_nss.c Mon Sep 8 18:35:21 2008
@@ -33,33 +33,35 @@
#include "crypto.h"
-static guint32 refcount = 0;
+static gboolean initialized = FALSE;
gboolean
crypto_init (GError **error)
{
- if (refcount == 0) {
- SECStatus ret;
+ SECStatus ret;
- PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 1);
- ret = NSS_NoDB_Init (NULL);
- if (ret != SECSuccess) {
- g_set_error (error, NM_CRYPTO_ERROR,
- NM_CRYPTO_ERR_INIT_FAILED,
- _("Failed to initialize the crypto engine: %d."),
- PR_GetError ());
- return FALSE;
- }
+ if (initialized)
+ return TRUE;
+
+ PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 1);
+ ret = NSS_NoDB_Init (NULL);
+ if (ret != SECSuccess) {
+ PR_Cleanup ();
+ g_set_error (error, NM_CRYPTO_ERROR,
+ NM_CRYPTO_ERR_INIT_FAILED,
+ _("Failed to initialize the crypto engine: %d."),
+ PR_GetError ());
+ return FALSE;
}
- refcount++;
+
+ initialized = TRUE;
return TRUE;
}
void
crypto_deinit (void)
{
- refcount--;
- if (refcount == 0) {
+ if (initialized) {
NSS_Shutdown ();
PR_Cleanup ();
}
Modified: trunk/libnm-util/libnm-util.ver
==============================================================================
--- trunk/libnm-util/libnm-util.ver (original)
+++ trunk/libnm-util/libnm-util.ver Mon Sep 8 18:35:21 2008
@@ -99,8 +99,10 @@
nm_setting_wireless_security_error_quark;
nm_setting_wireless_security_get_type;
nm_setting_wireless_security_new;
+ nm_utils_deinit;
nm_utils_escape_ssid;
nm_utils_gvalue_hash_dup;
+ nm_utils_init;
nm_utils_ip4_addresses_from_gvalue;
nm_utils_ip4_addresses_to_gvalue;
nm_utils_ip4_netmask_to_prefix;
Modified: trunk/libnm-util/nm-setting-8021x.c
==============================================================================
--- trunk/libnm-util/nm-setting-8021x.c (original)
+++ trunk/libnm-util/nm-setting-8021x.c Mon Sep 8 18:35:21 2008
@@ -902,8 +902,8 @@
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
/* Initialize crypto lbrary. */
- if (!crypto_init (&error)) {
- g_warning ("Couldn't initilize crypto system: %d %s",
+ if (!nm_utils_init (&error)) {
+ g_warning ("Couldn't initilize nm-utils/crypto system: %d %s",
error->code, error->message);
g_error_free (error);
}
Modified: trunk/libnm-util/nm-utils.c
==============================================================================
--- trunk/libnm-util/nm-utils.c (original)
+++ trunk/libnm-util/nm-utils.c Mon Sep 8 18:35:21 2008
@@ -242,6 +242,34 @@
return converted;
}
+/* init, deinit for libnm_util */
+
+static gboolean initialized = FALSE;
+
+gboolean
+nm_utils_init (GError **error)
+{
+ if (!initialized) {
+ if (!crypto_init (error)) {
+ return FALSE;
+ }
+ atexit (nm_utils_deinit);
+ initialized = TRUE;
+ }
+ return TRUE;
+}
+
+void
+nm_utils_deinit (void)
+{
+ if (initialized) {
+ crypto_deinit ();
+ initialized = FALSE;
+ }
+}
+
+/* ssid helpers */
+
char *
nm_utils_ssid_to_utf8 (const char *ssid, guint32 len)
{
@@ -1128,7 +1156,7 @@
uuid_t *uuid;
char *buf = NULL;
- if (!crypto_init (&error)) {
+ if (!nm_utils_init (&error)) {
nm_warning ("error initializing crypto: (%d) %s",
error ? error->code : 0,
error ? error->message : "unknown");
@@ -1152,7 +1180,6 @@
out:
g_free (uuid);
- crypto_deinit ();
return buf;
}
Modified: trunk/libnm-util/nm-utils.h
==============================================================================
--- trunk/libnm-util/nm-utils.h (original)
+++ trunk/libnm-util/nm-utils.h Mon Sep 8 18:35:21 2008
@@ -136,6 +136,10 @@
G_BREAKPOINT (); \
} G_STMT_END
+/* init, deinit nm_utils */
+gboolean nm_utils_init (GError **error);
+void nm_utils_deinit (void);
+
/* SSID helpers */
gboolean nm_utils_is_empty_ssid (const guint8 * ssid, int len);
const char *nm_utils_escape_ssid (const guint8 *ssid, guint32 len);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]