Skip to content

canlogserver: fix infinite loops during signal handling#628

Merged
hartkopp merged 1 commit into
linux-can:masterfrom
olerem:canlogserver-fix
May 12, 2026
Merged

canlogserver: fix infinite loops during signal handling#628
hartkopp merged 1 commit into
linux-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.

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!

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>
@olerem olerem force-pushed the canlogserver-fix branch from f6ccef1 to e5fd45a Compare May 12, 2026 06:50
@hartkopp hartkopp merged commit bf5fe73 into linux-can:master May 12, 2026
12 checks passed
@hartkopp
Copy link
Copy Markdown
Member

Thanks @olerem

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