dhcp/systemd: honor timeout

This commit is contained in:
Beniamino Galvani
2016-01-25 09:46:58 +01:00
parent 2ef70653fb
commit 37d0833a15
3 changed files with 19 additions and 7 deletions

View 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);
@@ -392,6 +392,18 @@ daemon_watch_cb (GPid pid, gint status, gpointer user_data)
nm_dhcp_client_set_state (self, new_state, NULL, NULL);
}
void
nm_dhcp_client_start_timeout (NMDhcpClient *self)
{
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
/* 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,
transaction_timeout,
self);
}
void
nm_dhcp_client_watch_child (NMDhcpClient *self, pid_t pid)
{
@@ -400,11 +412,8 @@ nm_dhcp_client_watch_child (NMDhcpClient *self, pid_t pid)
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,
self);
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);
}

View 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,

View 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: