Skip to content

initctl stop restarts completed remain-after-exit tasks after exec-stop-post #520

Closed

Description

@zhangxiaohui1

Description

A completed task with remain-after-exit = true and an exec-stop-post command starts again immediately after initctl stop when it is enabled in the current runlevel. This makes an explicit stop ineffective.

This report tracks the behavior described in #511. The reproducer below is adapted from that PR's regression test.

Steps to reproduce

On a Finit system without the fix in #511, in runlevel 2, 3, 4, or 5, create /etc/finit.d/remain-task.conf:

task remain-task {
    description       = "Remain task control"
    runlevel          = "2345"
    remain-after-exit = true
    command           = "/bin/touch /run/remain-task.state"
    exec-stop-post    = "/bin/rm -f /run/remain-task.state"
}
  1. Run initctl reload.
  2. Wait until initctl status remain-task shows done and the state file exists.
  3. Run initctl stop remain-task.
  4. Check the task status and whether /run/remain-task.state still exists.

Expected behavior

The post command removes the state file, and the task remains stopped. The explicit user stop must not trigger another execution.

Actual behavior

The post command runs, but the task starts again and recreates the state file instead of remaining stopped.

Cause and related fix

In the teardown path in src/service.c, remain tasks are unconditionally unblocked after the post command. This clears SVC_BLOCK_USER, allowing a task enabled in the current runlevel to run again.

PR #511 preserves the explicit stop block, distinguishes restart transitions from user stops, and adds regression coverage for stop, start, restart, reload, and runlevel transitions.

Source: #511

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions