Page MenuHomeFreeBSD

init: fix shutdown race
ClosedPublic

Authored by corvink on Aug 26 2022, 9:23 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 15 2024, 6:55 PM
Unknown Object (File)
Mar 15 2024, 6:55 PM
Unknown Object (File)
Mar 15 2024, 6:55 PM
Unknown Object (File)
Mar 8 2024, 4:05 AM
Unknown Object (File)
Feb 8 2024, 3:53 AM
Unknown Object (File)
Jan 19 2024, 6:45 PM
Unknown Object (File)
Jan 4 2024, 5:49 AM
Unknown Object (File)
Dec 26 2023, 4:15 PM

Details

Summary

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

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
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.