Skip to content

Make sure the main thread gets SIGCHLD#106

Merged
kdj0c merged 1 commit intoAetf:mainfrom
Vogtinator:sigchld
Aug 4, 2025
Merged

Make sure the main thread gets SIGCHLD#106
kdj0c merged 1 commit intoAetf:mainfrom
Vogtinator:sigchld

Conversation

@Vogtinator
Copy link

font_pango triggers creation of a glib thread which might capture SIGCHLD from child processes. Make sure those get blocked by blocking them in the parent process before thread creation.

Draft because this isn't really elegant and other signals might be affected as well?

font_pango triggers creation of a glib thread which might capture SIGCHLD
from child processes. Make sure those get blocked by blocking them in the
parent process before thread creation.
@kdj0c
Copy link
Collaborator

kdj0c commented Mar 6, 2025

Hi, thanks for finding the real root cause.

It looks like it's a known issue of glib:
https://gitlab.gnome.org/GNOME/glib/-/issues/2216

It might be fixed in latest version of glib:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2408

But I've tested #96 on Fedora 41, that should have this fix, so I'll need to investigate a bit more.

@Vogtinator
Copy link
Author

It might be fixed in latest version of glib:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2408

That change won't help, glib still installs a custom SIGCHLD handler and leaves it unblocked.

@mcatanzaro
Copy link

Notable risk here is that trying to figure out where libraries might create threads is probably hopeless. Even if this works today, it's hard to be confident that threads won't be unexpectedly created someplace else in the future. Maybe it'd be better to block signals at the top of main, and then unblock where you're ready to handle them? Still, I would worry that a thread might be created anywhere.

I think the fundamental problem here is you're using GChildWatch (otherwise, GLib would not install a SIGCHLD handler) but you also want to manually monitor for child processes exiting without GChildWatch. Why not just do it one way or the other instead of mixing both?

That change won't help, glib still installs a custom SIGCHLD handler and leaves it unblocked.

I think this merge request removes the only place GLib installs a SIGCHLD handler (although only if pidfd is supported by the kernel), so why wouldn't it help?

@Vogtinator
Copy link
Author

Vogtinator commented Mar 6, 2025

Maybe it'd be better to block signals at the top of main, and then unblock where you're ready to handle them?

Yes, that might be the a better option.

I think the fundamental problem here is you're using GChildWatch (otherwise, GLib would not install a SIGCHLD handler) but you also want to manually monitor for child processes exiting without GChildWatch. Why not just do it one way or the other instead of mixing both?

kmscon does not even use glib. It just uses pango for rendering, which uses glib with threads internally...

I think this merge request removes the only place GLib installs a SIGCHLD handler (although only if pidfd is supported by the kernel), so why wouldn't it help?

I only had a quick look, but AFAICT it uses pidfd but still installs a SIGCHLD handler unconditionally anyway.

@kdj0c kdj0c marked this pull request as ready for review July 31, 2025 16:07
@kdj0c
Copy link
Collaborator

kdj0c commented Jul 31, 2025

Font_pango is the only dependency that register a sigchild handler, so I think it's not a problem to put this workaround when loading font_pango.
This allows to revert my workaround, and will better fix #107

@kdj0c kdj0c merged commit f68276a into Aetf:main Aug 4, 2025
@Vogtinator Vogtinator deleted the sigchld branch August 4, 2025 08:53
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.

3 participants