Skip to content

Exit with the intended status before the signal handler is installed - #138

Open
BKPepe wants to merge 1 commit into
OLSR:masterfrom
BKPepe:exit-status-before-signal-handler
Open

Exit with the intended status before the signal handler is installed#138
BKPepe wants to merge 1 commit into
OLSR:masterfrom
BKPepe:exit-status-before-signal-handler

Conversation

@BKPepe

@BKPepe BKPepe commented Aug 10, 2026

Copy link
Copy Markdown

olsr_exit() calls raise(SIGTERM) so that olsr_shutdown() can perform an orderly shutdown, then falls through to exit(val) "in case the signal handler was not setup yet". With the default SIGTERM disposition, however, raise() terminates the process, so exit(val) is never reached.

main() calls olsr_exit() before installing the SIGTERM handler, causing these paths to exit with 143 instead of their intended status. For example, olsrd -f /nonexistent.conf currently exits with 143 instead of EXIT_FAILURE.

The patch tracks whether the handler has been installed and only uses the signal path afterwards. Behaviour after handler installation is unchanged.

Verified on macOS (make/Makefile.osx): -v and -h now exit 0, and an invalid configuration exits 1.

Noticed while adding a CI version check for the OpenWrt package (openwrt/routing#1191).

olsr_exit() ends the process with raise(SIGTERM) so that the orderly
shutdown in olsr_shutdown() runs, and falls through to exit(val) "in
case the signal handler was not setup yet". That fall-through is
unreachable: raise() with the default disposition terminates the
process, so exit(val) never executes.

main() calls olsr_exit() twenty times before signal(SIGTERM,
olsr_shutdown) is installed, so all of those paths report 143
instead of the value they pass:

    $ olsrd -v; echo $?
     *** olsr.org - pre-0.9.9-git_3653c47-hash_426688c ***
    Terminated: 15
    143

    $ olsrd -f /nonexistent.conf; echo $?
    Terminated: 15
    143

The second one matters beyond cosmetics: a configuration error is
indistinguishable from a successful run for anything that checks the
exit status, and EXIT_FAILURE never reaches the caller.

Record whether the handler has been installed and only take the
signal path once it has. With this, -v and -h exit 0 and the early
error paths exit with EXIT_FAILURE; behaviour after the handler is
installed is unchanged.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Copilot AI lite review requested due to automatic review settings August 10, 2026 08:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants