dhcp/systemd: honor timeout
authorBeniamino Galvani <bgalvani@redhat.com>
Mon, 25 Jan 2016 08:46:58 +0000 (09:46 +0100)
committerBeniamino Galvani <bgalvani@redhat.com>
Mon, 25 Jan 2016 16:46:01 +0000 (17:46 +0100)
src/dhcp-manager/nm-dhcp-client.c
src/dhcp-manager/nm-dhcp-client.h
src/dhcp-manager/nm-dhcp-systemd.c

index 862bde7..2c210be 100644 (file)
@@ -338,7 +338,7 @@ nm_dhcp_client_set_state (NMDhcpClient *self,
 }
 
 static gboolean
-daemon_timeout (gpointer user_data)
+transaction_timeout (gpointer user_data)
 {
        NMDhcpClient *self = NM_DHCP_CLIENT (user_data);
        NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
@@ -393,18 +393,27 @@ daemon_watch_cb (GPid pid, gint status, gpointer user_data)
 }
 
 void
-nm_dhcp_client_watch_child (NMDhcpClient *self, pid_t pid)
+nm_dhcp_client_start_timeout (NMDhcpClient *self)
 {
        NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
 
-       g_return_if_fail (priv->pid == -1);
-       priv->pid = pid;
-
        /* Set up a timeout on the transaction to kill it after the timeout */
        g_assert (priv->timeout_id == 0);
        priv->timeout_id = g_timeout_add_seconds (priv->timeout,
-                                                 daemon_timeout,
+                                                 transaction_timeout,
                                                  self);
+}
+
+void
+nm_dhcp_client_watch_child (NMDhcpClient *self, pid_t pid)
+{
+       NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
+
+       g_return_if_fail (priv->pid == -1);
+       priv->pid = pid;
+
+       nm_dhcp_client_start_timeout (self);
+
        g_return_if_fail (priv->watch_id == 0);
        priv->watch_id = g_child_watch_add (pid, daemon_watch_cb, self);
 }
index 7e28391..1c78c5b 100644 (file)
@@ -154,6 +154,8 @@ void nm_dhcp_client_stop_existing (const char *pid_file, const char *binary_name
 
 void nm_dhcp_client_stop_pid (pid_t pid, const char *iface);
 
+void nm_dhcp_client_start_timeout (NMDhcpClient *self);
+
 void nm_dhcp_client_watch_child (NMDhcpClient *self, pid_t pid);
 
 void nm_dhcp_client_set_state (NMDhcpClient *self,
index bafc7c9..ca4027e 100644 (file)
@@ -51,7 +51,6 @@ typedef struct {
        struct sd_dhcp6_client *client6;
        char *lease_file;
 
-       guint timeout_id;
        guint request_count;
 
        gboolean privacy;
@@ -668,6 +667,8 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
                goto error;
        }
 
+       nm_dhcp_client_start_timeout (client);
+
        success = TRUE;
 
 error: