Skip to content

Commit

Permalink
Flush the merge-wait queue on SIGUSR2
Browse files Browse the repository at this point in the history
If portage receives SIGUSR2, then flush the merge-wait queue on the
next possible occasion (typically after all running "install" jobs
are finished).

Signed-off-by: Florian Schmaus <[email protected]>
Closes: #1406
Signed-off-by: Sam James <[email protected]>
  • Loading branch information
Flowdalic authored and thesamesam committed Jan 16, 2025
1 parent b64e798 commit 7734202
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/_emerge/Scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def __init__(
# empty.
self._merge_wait_scheduled = []

self._flush_merge_wait_queue = False

# Holds system packages and their deep runtime dependencies. Before
# being merged, these packages go to merge_wait_queue, to be merged
# when no other packages are building.
Expand Down Expand Up @@ -1170,12 +1172,16 @@ def sighandler(signum, frame):
self.terminate()
received_signal.append(128 + signum)

def sigusr2handler(signum, frame):
self._flush_merge_wait_queue = True

earlier_sigint_handler = signal.signal(signal.SIGINT, sighandler)
earlier_sigterm_handler = signal.signal(signal.SIGTERM, sighandler)
earlier_sigcont_handler = signal.signal(
signal.SIGCONT, self._sigcont_handler
)
signal.siginterrupt(signal.SIGCONT, False)
earlier_sigusr2_handler = signal.signal(signal.SIGUSR2, sigusr2handler)

earlier_sigwinch_handler = signal.signal(
signal.SIGWINCH, self._sigwinch_handler
Expand All @@ -1196,6 +1202,10 @@ def sighandler(signum, frame):
signal.signal(signal.SIGCONT, earlier_sigcont_handler)
else:
signal.signal(signal.SIGCONT, signal.SIG_DFL)
if earlier_sigusr2_handler is not None:
signal.signal(signal.SIGUSR2, earlier_sigusr2_handler)
else:
signal.signal(signal.SIGUSR2, signal.SIG_DFL)

if earlier_sigwinch_handler is not None:
signal.signal(signal.SIGWINCH, earlier_sigwinch_handler)
Expand Down Expand Up @@ -1817,11 +1827,16 @@ def _schedule_tasks(self):
# special packages and we want to ensure that
# parallel-install does not cause more than one of
# them to install at the same time.
if (
self._merge_wait_queue
and not self._jobs
and not self._task_queues.merge
if self._merge_wait_queue and (
(not self._jobs and not self._task_queues.merge)
or self._flush_merge_wait_queue
):
if self._flush_merge_wait_queue:
self._status_msg(
"Manual flush of the merge-wait queue requested (e.g., via SIGUSR2)"
)
self._flush_merge_wait_queue = False

while self._merge_wait_queue:
# If we added non-system packages to the merge queue in a
# previous iteration of this loop, then for system packages we
Expand Down

0 comments on commit 7734202

Please sign in to comment.