Skip to content

canlogserver: fix infinite loops during signal handling#628

Open
olerem wants to merge 1 commit intolinux-can:masterfrom
olerem:canlogserver-fix
Open

canlogserver: fix infinite loops during signal handling#628
olerem wants to merge 1 commit intolinux-can:masterfrom
olerem:canlogserver-fix

Conversation

@olerem
Copy link
Copy Markdown
Contributor

@olerem olerem commented May 6, 2026

Fix infinite loops that prevent graceful termination when the server receives SIGINT or SIGTERM signals. Without this fix, Ctrl-C and kill commands are ignored, making it impossible to stop the server cleanly.

Two scenarios cause the infinite loops:

  1. The bind() retry loop: When the port is busy, the loop retries
    indefinitely without checking the running flag set by the signal
    handler.

  2. The accept() loop: The loop is unconditional, so when accept() is
    interrupted by a signal and returns EINTR, the loop immediately
    restarts, ignoring the shutdown request.

Fix infinite loops that prevent graceful termination when the server
receives SIGINT or SIGTERM signals. Without this fix, Ctrl-C and kill
commands are ignored, making it impossible to stop the server cleanly.

Two scenarios cause the infinite loops:

1) The bind() retry loop: When the port is busy, the loop retries
   indefinitely without checking the running flag set by the signal
   handler.

2) The accept() loop: The loop is unconditional, so when accept() is
   interrupted by a signal and returns EINTR, the loop immediately
   restarts, ignoring the shutdown request.

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
Comment thread canlogserver.c
nanosleep(&f, NULL);
}

if (!running) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The while() statement checks for running to be 1 so this check seems to be wrong inside the function.
I would suggest some comment here that running might be set to 0 due to an external signal.

Comment thread canlogserver.c
}
}

if (!running) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here

@hartkopp
Copy link
Copy Markdown
Member

hartkopp commented May 6, 2026

Btw. thanks for the fix!

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