Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SEGFAULT at terminal resize #222

Merged
merged 2 commits into from
Sep 29, 2023
Merged

Conversation

Phikimon
Copy link
Contributor

this_cli is a thread-local variable used by functions within SIGWINCH signal handler. This means that it can only be accessed by the main thread (that created it). Previosly however this signal could be handled by any thread of the process, thus occasionally causing SEGFAULTs.
In a multithreaded process if a signal is blocked by all threads but one, then the signal will be delivered to the thread expecting it. Using the fact that signal masks are inherited by pthreads this commit blocks SIGWINCH in the beginning of main(before the workers and the screen timer are spawned) and unblocks it just before cli_start().
The unblocking could be moved to scrn_start() function.
An alternative to this could be adding a 'handle_winch' atomic to struct cli_scrn.

Fixes #220

Copy link
Collaborator

@KeithWiles KeithWiles left a comment

Choose a reason for hiding this comment

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

Thank you.

* can handle screen resizes */
sigemptyset(&set);
sigaddset(&set, SIGWINCH);
pthread_sigmask(SIG_BLOCK, &set, NULL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just noticed this code looks exactly like the code at line 440, but this one states unblock and the other states block. Should line 582 use SIG_UNBLOCK instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, thank you.

this_cli is a thread-local variable used by functions within
SIGWINCH signal handler. This means that it can only be accessed by the
main thread (that created it). Previosly however this signal could be
handled by any thread of the process, thus occasionally causing
SEGFAULTs.
In a multithreaded process if a signal is blocked by all threads but
one, then the signal will be delivered to the thread expecting it. Using
the fact that signal masks are inherited by pthreads this commit blocks
SIGWINCH in the beginning of main(before the workers and the screen
timer are spawned) and unblocks it just before cli_start(). The
unblocking could be moved to scrn_start() function.
An alternative to this could be adding a 'handle_winch' atomic to struct
cli_scrn.

Signed-off-by: Philipp <phila775@gmail.com>
@Phikimon
Copy link
Contributor Author

Corrected the typo.

Copy link
Collaborator

@KeithWiles KeithWiles left a comment

Choose a reason for hiding this comment

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

Thank you.

@KeithWiles KeithWiles merged commit 6a86e1a into pktgen:main Sep 29, 2023
2 checks passed
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.

Crush when resize terminal
2 participants