2005-06-23 Dan Williams <dcbw@redhat.com>
* src/NetworkManager.c src/NetworkManagerMain.h - (nm_get_hal_ctx): new function, move Hal initialization code here - (nm_hal_init): new function, init libhal context then add devices - (nm_hal_deinit): new function, clean up libhal context - (nm_data_free): Move Hal cleanup here - (main): check whether Hal is running, and if so, get a list of network devices from it * src/NetworkManagerDbus.c - (nm_dbus_signal_filter): trap NameOwnerChanged signals for Hal, and when it appears, get a list of network devices from it. If Hal goes away, clean up the libhal context git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@738 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
16
ChangeLog
16
ChangeLog
@@ -1,3 +1,19 @@
|
||||
2005-06-23 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* src/NetworkManager.c
|
||||
src/NetworkManagerMain.h
|
||||
- (nm_get_hal_ctx): new function, move Hal initialization code here
|
||||
- (nm_hal_init): new function, init libhal context then add devices
|
||||
- (nm_hal_deinit): new function, clean up libhal context
|
||||
- (nm_data_free): Move Hal cleanup here
|
||||
- (main): check whether Hal is running, and if so, get a list of
|
||||
network devices from it
|
||||
|
||||
* src/NetworkManagerDbus.c
|
||||
- (nm_dbus_signal_filter): trap NameOwnerChanged signals for Hal,
|
||||
and when it appears, get a list of network devices from it. If
|
||||
Hal goes away, clean up the libhal context
|
||||
|
||||
2005-06-22 Robert Love <rml@novell.com>
|
||||
|
||||
* dispatcher-daemon/NetworkManagerDispatcher.c: fix FIXME: check
|
||||
|
@@ -490,6 +490,8 @@ static void nm_data_free (NMData *data)
|
||||
|
||||
g_io_channel_unref(data->sigterm_iochannel);
|
||||
|
||||
nm_hal_deinit (data);
|
||||
|
||||
memset (data, 0, sizeof (NMData));
|
||||
}
|
||||
|
||||
@@ -744,20 +746,95 @@ nm_set_up_log_handlers (gboolean become_daemon)
|
||||
GINT_TO_POINTER (become_daemon));
|
||||
}
|
||||
|
||||
|
||||
static LibHalContext *nm_get_hal_ctx (NMData *data)
|
||||
{
|
||||
LibHalContext * ctx = NULL;
|
||||
DBusError error;
|
||||
|
||||
g_return_val_if_fail (data != NULL, NULL);
|
||||
|
||||
/* Initialize libhal. We get a connection to the hal daemon here. */
|
||||
if ((ctx = libhal_ctx_new()) == NULL)
|
||||
{
|
||||
nm_error ("libhal_ctx_new() failed, exiting...");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nm_hal_mainloop_integration (ctx, data->dbus_connection);
|
||||
libhal_ctx_set_dbus_connection (ctx, data->dbus_connection);
|
||||
dbus_error_init (&error);
|
||||
if(!libhal_ctx_init (ctx, &error))
|
||||
{
|
||||
nm_error ("libhal_ctx_init() failed: %s\n"
|
||||
"Make sure the hal daemon is running?",
|
||||
error.message);
|
||||
|
||||
dbus_error_free (&error);
|
||||
libhal_ctx_free (ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
libhal_ctx_set_user_data (ctx, data);
|
||||
libhal_ctx_set_device_added (ctx, nm_hal_device_added);
|
||||
libhal_ctx_set_device_removed (ctx, nm_hal_device_removed);
|
||||
libhal_ctx_set_device_new_capability (ctx, nm_hal_device_new_capability);
|
||||
|
||||
dbus_error_init (&error);
|
||||
libhal_device_property_watch_all (ctx, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
{
|
||||
nm_error ("libhal_device_property_watch_all(): %s", error.message);
|
||||
dbus_error_free (&error);
|
||||
libhal_ctx_free (ctx);
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
void nm_hal_init (NMData *data)
|
||||
{
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
if ((data->hal_ctx = nm_get_hal_ctx (data)))
|
||||
nm_add_initial_devices (data);
|
||||
}
|
||||
|
||||
|
||||
void nm_hal_deinit (NMData *data)
|
||||
{
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
if (data->hal_ctx)
|
||||
{
|
||||
DBusError error;
|
||||
|
||||
dbus_error_init (&error);
|
||||
libhal_ctx_shutdown (data->hal_ctx, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
{
|
||||
nm_warning ("libhal shutdown failed - %s", error.message);
|
||||
dbus_error_free (&error);
|
||||
}
|
||||
libhal_ctx_free (data->hal_ctx);
|
||||
data->hal_ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* main
|
||||
*
|
||||
*/
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
LibHalContext *ctx = NULL;
|
||||
guint link_source_id;
|
||||
GSource * link_source;
|
||||
gboolean become_daemon = TRUE;
|
||||
gboolean enable_test_devices = FALSE;
|
||||
GError * error = NULL;
|
||||
DBusError dbus_error;
|
||||
|
||||
char * owner;
|
||||
|
||||
if ((int)getuid() != 0)
|
||||
{
|
||||
@@ -872,42 +949,9 @@ int main( int argc, char *argv[] )
|
||||
*/
|
||||
main_context = nm_data->main_context;
|
||||
|
||||
/* Initialize libhal. We get a connection to the hal daemon here. */
|
||||
if ((ctx = libhal_ctx_new()) == NULL)
|
||||
{
|
||||
nm_error ("libhal_ctx_new() failed, exiting...");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nm_hal_mainloop_integration (ctx, nm_data->dbus_connection);
|
||||
libhal_ctx_set_dbus_connection (ctx, nm_data->dbus_connection);
|
||||
dbus_error_init (&dbus_error);
|
||||
if(!libhal_ctx_init (ctx, &dbus_error))
|
||||
{
|
||||
nm_error ("libhal_ctx_init() failed: %s\n"
|
||||
"Make sure the hal daemon is running?",
|
||||
dbus_error.message);
|
||||
|
||||
dbus_error_free (&dbus_error);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nm_data->hal_ctx = ctx;
|
||||
libhal_ctx_set_user_data (nm_data->hal_ctx, nm_data);
|
||||
libhal_ctx_set_device_added (ctx, nm_hal_device_added);
|
||||
libhal_ctx_set_device_removed (ctx, nm_hal_device_removed);
|
||||
libhal_ctx_set_device_new_capability (ctx, nm_hal_device_new_capability);
|
||||
libhal_device_property_watch_all (nm_data->hal_ctx, &dbus_error);
|
||||
if (dbus_error_is_set (&dbus_error))
|
||||
{
|
||||
nm_error ("libhal_device_property_watch_all(): %s", dbus_error.message);
|
||||
dbus_error_free (&dbus_error);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Grab network devices that are already present and add them to our
|
||||
* list */
|
||||
nm_add_initial_devices (nm_data);
|
||||
/* If Hal is around, grab a device list from it */
|
||||
if ((owner = get_name_owner (nm_data->dbus_connection, "org.freedesktop.Hal")))
|
||||
nm_hal_init (nm_data);
|
||||
|
||||
/* We run dhclient when we need to, and we don't want any stray ones
|
||||
* lying around upon launch.
|
||||
@@ -934,16 +978,6 @@ int main( int argc, char *argv[] )
|
||||
g_main_loop_run (nm_data->main_loop);
|
||||
|
||||
nm_print_open_socks ();
|
||||
|
||||
/* Cleanup */
|
||||
libhal_ctx_shutdown (nm_data->hal_ctx, &dbus_error);
|
||||
if (dbus_error_is_set (&dbus_error))
|
||||
{
|
||||
nm_warning ("libhal shutdown failed - %s", dbus_error.message);
|
||||
dbus_error_free (&dbus_error);
|
||||
}
|
||||
libhal_ctx_free (nm_data->hal_ctx);
|
||||
|
||||
nm_data_free (nm_data);
|
||||
|
||||
exit (0);
|
||||
|
@@ -1060,12 +1060,12 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus
|
||||
|
||||
if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &service, DBUS_TYPE_STRING, &old_owner,
|
||||
DBUS_TYPE_STRING, &new_owner, DBUS_TYPE_INVALID))
|
||||
{
|
||||
if (strcmp (service, NMI_DBUS_SERVICE) == 0)
|
||||
{
|
||||
gboolean old_owner_good = (old_owner && (strlen (old_owner) > 0));
|
||||
gboolean new_owner_good = (new_owner && (strlen (new_owner) > 0));
|
||||
|
||||
if (strcmp (service, NMI_DBUS_SERVICE) == 0)
|
||||
{
|
||||
if (!old_owner_good && new_owner_good) /* NMI just appeared */
|
||||
{
|
||||
char *match = get_nmi_match_string (new_owner);
|
||||
@@ -1083,6 +1083,13 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus
|
||||
g_free (match);
|
||||
}
|
||||
}
|
||||
else if (strcmp (service, "org.freedesktop.Hal") == 0)
|
||||
{
|
||||
if (!old_owner_good && new_owner_good) /* Hal just appeared */
|
||||
nm_hal_init (data);
|
||||
else if (old_owner_good && !new_owner_good) /* Hal went away */
|
||||
nm_hal_deinit (data);
|
||||
}
|
||||
else if (nm_dhcp_manager_process_name_owner_changed (data->dhcp_manager, service, old_owner, new_owner) == TRUE)
|
||||
{
|
||||
/* Processed by the DHCP manager */
|
||||
@@ -1273,7 +1280,6 @@ char *get_name_owner (DBusConnection *con, const char *name)
|
||||
dbus_message_unref (message);
|
||||
}
|
||||
|
||||
fprintf (stderr, "GetNameOwner returning owner '%s' for name '%s'.\n", owner, name);
|
||||
return owner;
|
||||
}
|
||||
|
||||
|
@@ -98,4 +98,8 @@ void nm_remove_device_from_list (NMData *data, const char *udi);
|
||||
|
||||
void nm_schedule_state_change_signal_broadcast (NMData *data);
|
||||
|
||||
void nm_hal_init (NMData *data);
|
||||
|
||||
void nm_hal_deinit (NMData *data);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user