mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
LibSQL: Block signals while forking SQLServer in Lagom
When debugging in Xcode, the waitpid() for the initial forked process would always return EINTR or ECHILD. Work around this by blocking all signals until we're ready to wait for the initial child.
This commit is contained in:
parent
af118abdf0
commit
afb3a4a030
Notes:
sideshowbarker
2024-07-16 23:05:02 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/afb3a4a030 Pull-request: https://github.com/SerenityOS/serenity/pull/18052 Reviewed-by: https://github.com/linusg
1 changed files with 11 additions and 1 deletions
|
@ -15,6 +15,7 @@
|
|||
# include <LibCore/StandardPaths.h>
|
||||
# include <LibCore/System.h>
|
||||
# include <LibFileSystem/FileSystem.h>
|
||||
# include <signal.h>
|
||||
#endif
|
||||
|
||||
namespace SQL {
|
||||
|
@ -58,9 +59,14 @@ static ErrorOr<void> launch_server(DeprecatedString const& socket_path, Deprecat
|
|||
return server_fd_or_error.release_error();
|
||||
}
|
||||
auto server_fd = server_fd_or_error.value();
|
||||
sigset_t original_set;
|
||||
sigset_t setting_set;
|
||||
sigfillset(&setting_set);
|
||||
(void)pthread_sigmask(SIG_BLOCK, &setting_set, &original_set);
|
||||
auto server_pid = TRY(Core::System::fork());
|
||||
|
||||
if (server_pid == 0) {
|
||||
(void)pthread_sigmask(SIG_SETMASK, &original_set, nullptr);
|
||||
TRY(Core::System::setsid());
|
||||
TRY(Core::System::signal(SIGCHLD, SIG_IGN));
|
||||
server_pid = TRY(Core::System::fork());
|
||||
|
@ -95,8 +101,12 @@ static ErrorOr<void> launch_server(DeprecatedString const& socket_path, Deprecat
|
|||
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
VERIFY(server_pid > 0);
|
||||
|
||||
TRY(Core::System::waitpid(server_pid));
|
||||
auto wait_err = Core::System::waitpid(server_pid);
|
||||
(void)pthread_sigmask(SIG_SETMASK, &original_set, nullptr);
|
||||
if (wait_err.is_error())
|
||||
return wait_err.release_error();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue