mirror of
https://github.com/systemd/systemd.git
synced 2025-02-25 21:57:32 +03:00
sd-dhcp-client: make client initially in stopped state
Previously, DHCP_STATE_STOPPED and DHCP_STATE_INIT are both handled as not-running. Moreover, previously after sd_dhcp_client_start() is called, the client still in INIT state (and thus handled as not-running) even if its internal timer event sources are initialized. Let's make only STOPPED state handled as not-running, and make the client initially in STOPPED state. Prompted by #28896.
This commit is contained in:
parent
c91d636fad
commit
b2851e8d62
@ -55,15 +55,15 @@ enum {
|
||||
};
|
||||
|
||||
enum DHCPState {
|
||||
DHCP_STATE_INIT = 0,
|
||||
DHCP_STATE_SELECTING = 1,
|
||||
DHCP_STATE_INIT_REBOOT = 2,
|
||||
DHCP_STATE_REBOOTING = 3,
|
||||
DHCP_STATE_REQUESTING = 4,
|
||||
DHCP_STATE_BOUND = 5,
|
||||
DHCP_STATE_RENEWING = 6,
|
||||
DHCP_STATE_REBINDING = 7,
|
||||
DHCP_STATE_STOPPED = 8,
|
||||
DHCP_STATE_STOPPED = 0,
|
||||
DHCP_STATE_INIT = 1,
|
||||
DHCP_STATE_SELECTING = 2,
|
||||
DHCP_STATE_INIT_REBOOT = 3,
|
||||
DHCP_STATE_REBOOTING = 4,
|
||||
DHCP_STATE_REQUESTING = 5,
|
||||
DHCP_STATE_BOUND = 6,
|
||||
DHCP_STATE_RENEWING = 7,
|
||||
DHCP_STATE_REBINDING = 8,
|
||||
};
|
||||
|
||||
typedef enum DHCPState DHCPState;
|
||||
|
@ -753,7 +753,7 @@ static int client_initialize(sd_dhcp_client *client) {
|
||||
|
||||
client->attempt = 0;
|
||||
|
||||
client->state = DHCP_STATE_INIT;
|
||||
client->state = DHCP_STATE_STOPPED;
|
||||
client->xid = 0;
|
||||
|
||||
client->lease = sd_dhcp_lease_unref(client->lease);
|
||||
@ -1434,7 +1434,7 @@ static int client_start_delayed(sd_dhcp_client *client) {
|
||||
assert_return(client->ifindex > 0, -EINVAL);
|
||||
assert_return(client->fd < 0, -EBUSY);
|
||||
assert_return(client->xid == 0, -EINVAL);
|
||||
assert_return(IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_INIT_REBOOT), -EBUSY);
|
||||
assert_return(IN_SET(client->state, DHCP_STATE_STOPPED, DHCP_STATE_INIT_REBOOT), -EBUSY);
|
||||
|
||||
client->xid = random_u32();
|
||||
|
||||
@ -1448,8 +1448,10 @@ static int client_start_delayed(sd_dhcp_client *client) {
|
||||
}
|
||||
client->fd = r;
|
||||
|
||||
if (IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_INIT_REBOOT))
|
||||
client->start_time = now(CLOCK_BOOTTIME);
|
||||
client->start_time = now(CLOCK_BOOTTIME);
|
||||
|
||||
if (client->state == DHCP_STATE_STOPPED)
|
||||
client->state = DHCP_STATE_INIT;
|
||||
|
||||
return client_initialize_events(client, client_receive_message_raw);
|
||||
}
|
||||
@ -2061,7 +2063,7 @@ int sd_dhcp_client_is_running(sd_dhcp_client *client) {
|
||||
if (!client)
|
||||
return 0;
|
||||
|
||||
return !IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_STOPPED);
|
||||
return client->state != DHCP_STATE_STOPPED;
|
||||
}
|
||||
|
||||
int sd_dhcp_client_start(sd_dhcp_client *client) {
|
||||
@ -2263,7 +2265,7 @@ int sd_dhcp_client_new(sd_dhcp_client **ret, int anonymize) {
|
||||
|
||||
*client = (sd_dhcp_client) {
|
||||
.n_ref = 1,
|
||||
.state = DHCP_STATE_INIT,
|
||||
.state = DHCP_STATE_STOPPED,
|
||||
.ifindex = -1,
|
||||
.fd = -EBADF,
|
||||
.mtu = DHCP_MIN_PACKET_SIZE,
|
||||
|
Loading…
x
Reference in New Issue
Block a user