Page MenuHomeFreeBSD

init: fix shutdown race

Authored by corvink on Aug 26 2022, 9:23 AM.
Referenced Files
Unknown Object (File)
Feb 17 2023, 4:20 PM
Unknown Object (File)
Feb 9 2023, 5:01 AM
Unknown Object (File)
Jan 17 2023, 10:59 AM
Unknown Object (File)
Jan 16 2023, 4:12 AM
Unknown Object (File)
Dec 17 2022, 7:14 AM
Unknown Object (File)
Dec 15 2022, 7:43 PM
Unknown Object (File)
Dec 15 2022, 1:12 AM
Unknown Object (File)
Dec 2 2022, 5:30 AM



When calling shutdown, shutdown sends a signal to init and exits. This
causes a race condition for the waitpid function. If the signal wins the
race, wpid will be set to -1 and init calls death_single. If shutdown
wins the race, wpid will be set to the pid of the shutdown process and
the requested_transition will be ignored.

Diff Detail

rG FreeBSD src repository
Lint Not Applicable
Tests Not Applicable

Event Timeline

corvink added subscribers: rgrimes, trasz, des.

@trasz @imp @des @rgrimes I add you as reviewer because I found you in the git history.

The single_user function checks for requested_transition in it's while condition:

do {
} while (wpid != pid && !requested_transition);

if (requested_transition)
  return (state_funct_t) requested_transition

Does it make sense to use it here too?

how does this fix the rate?

The race is still there. However, it's not an issue any more. This patch checks requested_transition on each exit of waitpid and not only when the signal wins the race (wpid == -1).

Ah, it makes the race not matter. I think I understand and I agree that the change is good.

This revision is now accepted and ready to land.Sep 5 2022, 8:04 PM
This revision was automatically updated to reflect the committed changes.