kmscon icon indicating copy to clipboard operation
kmscon copied to clipboard

Make sure the main thread gets SIGCHLD

Open Vogtinator opened this issue 10 months ago • 4 comments

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?

Vogtinator avatar Mar 05 '25 17:03 Vogtinator

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.

kdj0c avatar Mar 06 '25 10:03 kdj0c

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.

Vogtinator avatar Mar 06 '25 11:03 Vogtinator

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?

mcatanzaro avatar Mar 06 '25 12:03 mcatanzaro

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.

Vogtinator avatar Mar 06 '25 13:03 Vogtinator

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 avatar Jul 31 '25 23:07 kdj0c