diff --git a/Userland/Services/CrashDaemon/main.cpp b/Userland/Services/CrashDaemon/main.cpp index d14c33497d..5c82ccb0f6 100644 --- a/Userland/Services/CrashDaemon/main.cpp +++ b/Userland/Services/CrashDaemon/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -33,22 +34,12 @@ static void wait_until_coredump_is_ready(String const& coredump_path) static void launch_crash_reporter(String const& coredump_path, bool unlink_on_exit) { - pid_t child; - char const* argv[4] = { "CrashReporter" }; - if (unlink_on_exit) { - argv[1] = "--unlink"; - argv[2] = coredump_path.characters(); - argv[3] = nullptr; - } else { - argv[1] = coredump_path.characters(); - argv[2] = nullptr; - } - if ((errno = posix_spawn(&child, "/bin/CrashReporter", nullptr, nullptr, const_cast(argv), environ))) { - perror("posix_spawn"); - } else { - if (disown(child) < 0) - perror("disown"); - } + auto pid = Core::Process::spawn("/bin/CrashReporter", + unlink_on_exit + ? Array { "--unlink", coredump_path.characters() }.span() + : Array { coredump_path.characters() }.span()); + if (pid.is_error()) + warnln("Failed to launch CrashReporter"); } ErrorOr serenity_main(Main::Arguments) diff --git a/Userland/Services/LaunchServer/Launcher.cpp b/Userland/Services/LaunchServer/Launcher.cpp index 5eadeb180f..cd763080b9 100644 --- a/Userland/Services/LaunchServer/Launcher.cpp +++ b/Userland/Services/LaunchServer/Launcher.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -183,20 +184,7 @@ bool Launcher::open_with_handler_name(const URL& url, String const& handler_name bool spawn(String executable, Vector const& arguments) { - Vector argv { executable.characters() }; - for (auto& arg : arguments) - argv.append(arg.characters()); - argv.append(nullptr); - - pid_t child_pid; - if ((errno = posix_spawn(&child_pid, executable.characters(), nullptr, nullptr, const_cast(argv.data()), environ))) { - perror("posix_spawn"); - return false; - } else { - if (disown(child_pid) < 0) - perror("disown"); - } - return true; + return !Core::Process::spawn(executable, arguments).is_error(); } Handler Launcher::get_handler_for_executable(Handler::Type handler_type, String const& executable) const diff --git a/Userland/Services/WindowServer/KeymapSwitcher.cpp b/Userland/Services/WindowServer/KeymapSwitcher.cpp index f329c15bfa..e028b00759 100644 --- a/Userland/Services/WindowServer/KeymapSwitcher.cpp +++ b/Userland/Services/WindowServer/KeymapSwitcher.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -101,12 +102,9 @@ String KeymapSwitcher::get_current_keymap() const void KeymapSwitcher::setkeymap(const AK::String& keymap) { - pid_t child_pid; - char const* argv[] = { "/bin/keymap", "-m", keymap.characters(), nullptr }; - if ((errno = posix_spawn(&child_pid, "/bin/keymap", nullptr, nullptr, const_cast(argv), environ))) { - perror("posix_spawn"); + if (Core::Process::spawn("/bin/keymap", Array { "-m", keymap.characters() }).is_error()) dbgln("Failed to call /bin/keymap, error: {} ({})", errno, strerror(errno)); - } + if (on_keymap_change) on_keymap_change(keymap); }