2008-10-08 Dan Williams <dcbw@redhat.com>
authorDan Williams <dcbw@redhat.com>
Wed, 8 Oct 2008 22:40:42 +0000 (22:40 +0000)
committerDan Williams <dcbw@redhat.com>
Wed, 8 Oct 2008 22:40:42 +0000 (22:40 +0000)
Add a 'hostname' dispatcher action triggered on hostname changes (bgo #552983)

* src/NetworkManagerUtils.c
- (nm_utils_call_dispatcher): add a 'hostname' action

* src/NetworkManagerPolicy.c
- (set_system_hostname): dispatch hostname changes

* callouts/nm-dispatcher-action.c
- (nm_dispatcher_action): handle 'hostname' actions

git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4158 4912f4e0-d625-0410-9fb7-b9a5a253dbdc

ChangeLog
callouts/nm-dispatcher-action.c
src/NetworkManagerPolicy.c
src/NetworkManagerUtils.c

index b52cb66..2aa1612 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2008-10-08  Dan Williams  <dcbw@redhat.com>
+
+       Add a 'hostname' dispatcher action triggered on hostname changes (bgo #552983)
+
+       * src/NetworkManagerUtils.c
+               - (nm_utils_call_dispatcher): add a 'hostname' action
+
+       * src/NetworkManagerPolicy.c
+               - (set_system_hostname): dispatch hostname changes
+
+       * callouts/nm-dispatcher-action.c
+               - (nm_dispatcher_action): handle 'hostname' actions
+
 2008-10-08  Dan Williams  <dcbw@redhat.com>
 
        * src/NetworkManagerSystem.c
index 1c47ca2..ef082dc 100644 (file)
@@ -361,7 +361,7 @@ construct_envp (NMIP4Config *ip4_config, NMDHCP4Config *dhcp4_config)
        if (debug) {
                char **p;
 
-               g_message ("-----------------------------------------");
+               g_message ("------------ Script Environment ------------");
                for (p = envp; *p; p++)
                        g_message ("  %s", *p);
                g_message ("\n");
@@ -427,10 +427,13 @@ dispatch_scripts (const char *action,
                gint status = -1;
 
                argv[0] = (char *) iter->data;
-               argv[1] = (char *) iface;
+               argv[1] = iface ? (char *) iface : "none";
                argv[2] = (char *) action;
                argv[3] = NULL;
 
+               if (debug)
+                       g_message ("Script: %s %s %s", (char *) iter->data, iface ? (char *) iface : "(none)", (char *) action);
+
                error = NULL;
                if (g_spawn_sync ("/", argv, envp, 0, child_setup, NULL, NULL, NULL, &status, &error)) {
                        if (WIFEXITED (status)) {
@@ -488,6 +491,10 @@ nm_dispatcher_action (Handler *h,
                *error = NULL;
        }
 
+       /* Hostname changes don't require a device */
+       if (!strcmp (action, "hostname"))
+               goto dispatch;
+
        /* interface name */
        value = g_hash_table_lookup (device_props, NMD_DEVICE_PROPS_INTERFACE);
        if (!value || !G_VALUE_HOLDS_STRING (value)) {
@@ -537,6 +544,7 @@ nm_dispatcher_action (Handler *h,
                ip4_config = nm_device_get_ip4_config (device);
        }
 
+dispatch:
        dispatch_scripts (action, iface, parent_iface, type, ip4_config, dhcp4_config);
 
        if (device)
index 103fdc0..25024c2 100644 (file)
@@ -351,6 +351,7 @@ set_system_hostname (const char *new_hostname, const char *msg)
                                            __func__, FALLBACK_HOSTNAME, errno, strerror (errno));
                        }
                }
+               nm_utils_call_dispatcher ("hostname", NULL, NULL, NULL);
        } else {
                nm_warning ("%s: couldn't set the system hostname to '%s': (%d) %s",
                            __func__, name, errno, strerror (errno));
index 739480d..c08a4c4 100644 (file)
@@ -427,7 +427,10 @@ nm_utils_call_dispatcher (const char *action,
        GHashTable *device_props;
 
        g_return_if_fail (action != NULL);
-       g_return_if_fail (NM_IS_DEVICE (device));
+
+       /* All actions except 'hostname' require a device */
+       if (strcmp (action, "hostname"))
+               g_return_if_fail (NM_IS_DEVICE (device));
 
        dbus_mgr = nm_dbus_manager_get ();
        g_connection = nm_dbus_manager_get_connection (dbus_mgr);
@@ -470,29 +473,32 @@ nm_utils_call_dispatcher (const char *action,
        device_props = g_hash_table_new_full (g_str_hash, g_str_equal,
                                              NULL, nm_gvalue_destroy);
 
-       /* interface */
-       g_hash_table_insert (device_props, NMD_DEVICE_PROPS_INTERFACE,
-                            str_to_gvalue (nm_device_get_iface (device)));
-
-       /* IP interface */
-       if (vpn_iface) {
-               g_hash_table_insert (device_props, NMD_DEVICE_PROPS_IP_INTERFACE,
-                                    str_to_gvalue (vpn_iface));
-       } else if (nm_device_get_ip_iface (device)) {
-               g_hash_table_insert (device_props, NMD_DEVICE_PROPS_IP_INTERFACE,
-                                    str_to_gvalue (nm_device_get_ip_iface (device)));
-       }
+       /* Hostname actions do not require a device */
+       if (strcmp (action, "hostname")) {
+               /* interface */
+               g_hash_table_insert (device_props, NMD_DEVICE_PROPS_INTERFACE,
+                                    str_to_gvalue (nm_device_get_iface (device)));
+
+               /* IP interface */
+               if (vpn_iface) {
+                       g_hash_table_insert (device_props, NMD_DEVICE_PROPS_IP_INTERFACE,
+                                            str_to_gvalue (vpn_iface));
+               } else if (nm_device_get_ip_iface (device)) {
+                       g_hash_table_insert (device_props, NMD_DEVICE_PROPS_IP_INTERFACE,
+                                            str_to_gvalue (nm_device_get_ip_iface (device)));
+               }
 
-       /* type */
-       g_hash_table_insert (device_props, NMD_DEVICE_PROPS_TYPE,
-                            uint_to_gvalue (nm_device_get_device_type (device)));
+               /* type */
+               g_hash_table_insert (device_props, NMD_DEVICE_PROPS_TYPE,
+                                    uint_to_gvalue (nm_device_get_device_type (device)));
 
-       /* state */
-       g_hash_table_insert (device_props, NMD_DEVICE_PROPS_STATE,
-                            uint_to_gvalue (nm_device_get_state (device)));
+               /* state */
+               g_hash_table_insert (device_props, NMD_DEVICE_PROPS_STATE,
+                                    uint_to_gvalue (nm_device_get_state (device)));
 
-       g_hash_table_insert (device_props, NMD_DEVICE_PROPS_PATH,
-                            op_to_gvalue (nm_device_get_udi (device)));
+               g_hash_table_insert (device_props, NMD_DEVICE_PROPS_PATH,
+                                    op_to_gvalue (nm_device_get_udi (device)));
+       }
 
        dbus_g_proxy_call_no_reply (proxy, "Action",
                                    G_TYPE_STRING, action,