diff --git a/ChangeLog b/ChangeLog index 21a7b40509..bef444b145 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-10-08 Tambet Ingo + + * src/NetworkManager.c (main): When dbus manager doesn't want to start, complain + about dbus manager, not named manager. + Make sure hal_manager and dbus_mgr are created before trying to unreference. + + * src/nm-dbus-manager.c: There was an issue with priv->proxy: We have a signal + handler for it's 'destroy' signal - we use it to catch disconnects from dbus. + However, the same signal is emitted when we destroy it and there's + nm_dbus_manager_cleanup -> destroy_cb -> nm_dbus_manager_cleanup cycle. + + (nm_dbus_manager_cleanup): Let go of the DBusGProxy before + releasing the DBusGConnection, since proxy needs a conneciton. + (destroy_cb): Set the private proxy to NULL before cleaning up the manager. + 2007-10-08 Dan Williams * src/NetworkManager.c diff --git a/src/NetworkManager.c b/src/NetworkManager.c index 6b628007e8..f368c6e99b 100644 --- a/src/NetworkManager.c +++ b/src/NetworkManager.c @@ -344,7 +344,7 @@ main (int argc, char *argv[]) /* Start our DBus service */ if (!nm_dbus_manager_start_service (dbus_mgr)) { - nm_warning ("Failed to start the named manager."); + nm_warning ("Failed to start the dbus manager."); goto done; } @@ -367,7 +367,9 @@ done: if (vpn_manager) g_object_unref (vpn_manager); - nm_hal_manager_destroy (hal_manager); + if (hal_manager) + nm_hal_manager_destroy (hal_manager); + if (policy) nm_policy_destroy (policy); @@ -377,7 +379,9 @@ done: if (sup_mgr) g_object_unref (sup_mgr); - g_object_unref (dbus_mgr); + if (dbus_mgr) + g_object_unref (dbus_mgr); + nm_logging_shutdown (); if (pidfile) diff --git a/src/nm-dbus-manager.c b/src/nm-dbus-manager.c index 7ffae9510d..2e126bf425 100644 --- a/src/nm-dbus-manager.c +++ b/src/nm-dbus-manager.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ /* * Copyright (C) 2006 Red Hat, Inc. * @@ -179,17 +180,17 @@ nm_dbus_manager_cleanup (NMDBusManager *self) { NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self); + if (priv->proxy) { + g_object_unref (priv->proxy); + priv->proxy = NULL; + } + if (priv->g_connection) { dbus_g_connection_unref (priv->g_connection); priv->g_connection = NULL; priv->connection = NULL; } - if (priv->proxy) { - g_object_unref (priv->proxy); - priv->proxy = NULL; - } - priv->started = FALSE; } @@ -556,6 +557,8 @@ destroy_cb (DBusGProxy *proxy, gpointer user_data) /* Clean up existing connection */ nm_info ("disconnected by the system bus."); + NM_DBUS_MANAGER_GET_PRIVATE (self)->proxy = NULL; + nm_dbus_manager_cleanup (self); g_signal_emit (G_OBJECT (self), @@ -687,8 +690,7 @@ nm_dbus_manager_start_service (NMDBusManager *self) } if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - nm_warning ("Could not acquire the NetworkManager service as it" - "is already taken. Return: %d", + nm_warning ("Could not acquire the NetworkManager service as it is already taken.", request_name_result); goto out; } diff --git a/vpn-daemons/openvpn/src/nm-utils.c b/vpn-daemons/openvpn/src/nm-utils.c deleted file mode 100644 index 5c66a77483..0000000000 --- a/vpn-daemons/openvpn/src/nm-utils.c +++ /dev/null @@ -1,133 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Ray Strode - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#include -#include -#include - -#include - -#include "nm-utils.h" - -gchar *nm_dbus_escape_object_path (const gchar *utf8_string) -{ - const gchar *p; - gchar *object_path; - GString *string; - - g_return_val_if_fail (utf8_string != NULL, NULL); - g_return_val_if_fail (g_utf8_validate (utf8_string, -1, NULL), NULL); - - string = g_string_sized_new ((strlen (utf8_string) + 1) * 6); - - for (p = utf8_string; *p != '\0'; p = g_utf8_next_char (p)) - { - gunichar character; - - character = g_utf8_get_char (p); - - if (((character >= ((gunichar) 'a')) && - (character <= ((gunichar) 'z'))) || - ((character >= ((gunichar) 'A')) && - (character <= ((gunichar) 'Z'))) || - ((character >= ((gunichar) '0')) && - (character <= ((gunichar) '9'))) || - (character == ((gunichar) '/'))) - { - g_string_append_c (string, (gchar) character); - continue; - } - - g_string_append_printf (string, "_%x_", character); - } - - object_path = string->str; - - g_string_free (string, FALSE); - - return object_path; -} - -gchar *nm_dbus_unescape_object_path (const gchar *object_path) -{ - const gchar *p; - gchar *utf8_string; - GString *string; - - g_return_val_if_fail (object_path != NULL, NULL); - - string = g_string_sized_new (strlen (object_path) + 1); - - for (p = object_path; *p != '\0'; p++) - { - const gchar *q; - gchar *hex_digits, *end, utf8_character[6] = { '\0' }; - gint utf8_character_size; - gunichar character; - gulong hex_value; - - if (*p != '_') - { - g_string_append_c (string, *p); - continue; - } - - q = strchr (p + 1, '_'); - - if ((q == NULL) || (q == p + 1)) - { - g_string_free (string, TRUE); - return NULL; - } - - hex_digits = g_strndup (p + 1, (q - 1) - p); - - hex_value = strtoul (hex_digits, &end, 16); - - character = (gunichar) hex_value; - - if (((hex_value == G_MAXLONG) && (errno == ERANGE)) || - (hex_value > G_MAXUINT32) || - (*end != '\0') || - (!g_unichar_validate (character))) - { - g_free (hex_digits); - g_string_free (string, TRUE); - return NULL; - } - - utf8_character_size = - g_unichar_to_utf8 (character, utf8_character); - - g_assert (utf8_character_size > 0); - - g_string_append_len (string, utf8_character, - utf8_character_size); - - p = q; - } - - utf8_string = string->str; - - g_string_free (string, FALSE); - - return utf8_string; -} diff --git a/vpn-daemons/openvpn/src/nm-utils.h b/vpn-daemons/openvpn/src/nm-utils.h deleted file mode 100644 index 7421804983..0000000000 --- a/vpn-daemons/openvpn/src/nm-utils.h +++ /dev/null @@ -1,152 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Ray Strode - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#ifndef NM_UTILS_H -#define NM_UTILS_H - -#include -#include - -#define nm_print_backtrace() \ -G_STMT_START \ -{ \ - void *_call_stack[512]; \ - int _call_stack_size; \ - char **_symbols; \ - _call_stack_size = backtrace (_call_stack, \ - G_N_ELEMENTS (_call_stack)); \ - _symbols = backtrace_symbols (_call_stack, _call_stack_size); \ - if (_symbols != NULL) \ - { \ - int _i; \ - _i = 0; \ - g_critical ("traceback:\n"); \ - while (_i < _call_stack_size) \ - { \ - g_critical ("\t%s\n", _symbols[_i]); \ - _i++; \ - } \ - free (_symbols); \ - } \ -} \ -G_STMT_END - -#define nm_get_timestamp(timestamp) \ -G_STMT_START \ -{ \ - GTimeVal _tv; \ - g_get_current_time (&_tv); \ - *timestamp = (_tv.tv_sec * (1.0 * G_USEC_PER_SEC) + \ - _tv.tv_usec) / G_USEC_PER_SEC; \ -} \ -G_STMT_END - -#define nm_info(fmt, args...) \ -G_STMT_START \ -{ \ - g_message ("\t" fmt "\n", ##args); \ -} G_STMT_END - -#define nm_info_str(fmt_str, args...) \ -G_STMT_START \ -{ \ - g_message ("\t%s\n", fmt_str, ##args); \ -} G_STMT_END - -#define nm_debug(fmt, args...) \ -G_STMT_START \ -{ \ - gdouble _timestamp; \ - nm_get_timestamp (&_timestamp); \ - g_debug ("\t[%f] %s (): " fmt "\n", _timestamp, \ - G_STRFUNC, ##args); \ -} G_STMT_END - -#define nm_debug_str(fmt_str, args...) \ -G_STMT_START \ -{ \ - gdouble _timestamp; \ - nm_get_timestamp (&_timestamp); \ - g_debug ("\t[%f] %s (): %s\n", _timestamp, \ - G_STRFUNC, fmt_str, ##args); \ -} G_STMT_END - -#define nm_warning(fmt, args...) \ -G_STMT_START \ -{ \ - g_warning ("\t %s (): " fmt "\n", \ - G_STRFUNC, ##args); \ -} G_STMT_END - -#define nm_warning_str(fmt_str, args...) \ -G_STMT_START \ -{ \ - g_warning ("\t %s (): %s\n", \ - G_STRFUNC, fmt_str, ##args); \ -} G_STMT_END - -#define nm_error(fmt, args...) \ -G_STMT_START \ -{ \ - gdouble _timestamp; \ - nm_get_timestamp (&_timestamp); \ - g_critical ("\t[%f] %s (): " fmt "\n", _timestamp, \ - G_STRFUNC, ##args); \ - nm_print_backtrace (); \ - G_BREAKPOINT (); \ -} G_STMT_END - -#define nm_error_str(fmt_str, args...) \ -G_STMT_START \ -{ \ - gdouble _timestamp; \ - nm_get_timestamp (&_timestamp); \ - g_critical ("\t[%f] %s (): %s\n", _timestamp, \ - G_STRFUNC, fmt_str, ##args); \ - nm_print_backtrace (); \ - G_BREAKPOINT (); \ -} G_STMT_END - -gchar *nm_dbus_escape_object_path (const gchar *utf8_string); -gchar *nm_dbus_unescape_object_path (const gchar *object_path); - -static inline const char *nm_find_openvpn (void) -{ - static const char *openvpn_binary_paths[] = - { - "/usr/sbin/openvpn", - "/sbin/openvpn", - NULL - }; - - const char **openvpn_binary = openvpn_binary_paths; - - while (*openvpn_binary != NULL) { - if (g_file_test (*openvpn_binary, G_FILE_TEST_EXISTS)) - break; - openvpn_binary++; - } - - return *openvpn_binary; -} - - -#endif /* NM_UTILS_H */