mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 11:04:59 +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
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…
Add table
Add a link
Reference in a new issue