From b27e5d53f3c1fefc8bfa6c6bde3c975fa5f7b5e0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 18 May 2021 16:12:02 +0900 Subject: [PATCH] sd-dhcp-server: make sd_dhcp_server_start() no-op if it is already running --- src/libsystemd-network/sd-dhcp-server.c | 4 ++++ src/libsystemd-network/test-dhcp-server.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index 81de2ef7fc..e2ea79f584 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -1202,6 +1202,10 @@ int sd_dhcp_server_start(sd_dhcp_server *server) { assert_return(server, -EINVAL); assert_return(server->event, -EINVAL); + + if (sd_dhcp_server_is_running(server)) + return 0; + assert_return(!server->receive_message, -EBUSY); assert_return(server->fd_raw < 0, -EBUSY); assert_return(server->fd < 0, -EBUSY); diff --git a/src/libsystemd-network/test-dhcp-server.c b/src/libsystemd-network/test-dhcp-server.c index f051420708..a5c9bfeafb 100644 --- a/src/libsystemd-network/test-dhcp-server.c +++ b/src/libsystemd-network/test-dhcp-server.c @@ -61,7 +61,7 @@ static int test_basic(sd_event *event, bool bind_to_interface) { return log_info_errno(r, "sd_dhcp_server_start failed: %m"); assert_se(r >= 0); - assert_se(sd_dhcp_server_start(server) == -EBUSY); + assert_se(sd_dhcp_server_start(server) >= 0); assert_se(sd_dhcp_server_stop(server) >= 0); assert_se(sd_dhcp_server_stop(server) >= 0); assert_se(sd_dhcp_server_start(server) >= 0);