From 125145c6828ac3eff333cf717bcc0952945eef2e Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Mon, 17 Jul 2023 16:39:31 +1200 Subject: [PATCH] LibCore: Port Command::write_lines to ErrorOr Keeping this in line with Command::write. --- Tests/LibJS/test-test262.cpp | 3 ++- Userland/Libraries/LibCore/Command.cpp | 9 +++------ Userland/Libraries/LibCore/Command.h | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Tests/LibJS/test-test262.cpp b/Tests/LibJS/test-test262.cpp index 60f91a98947..43e5d481fa2 100644 --- a/Tests/LibJS/test-test262.cpp +++ b/Tests/LibJS/test-test262.cpp @@ -126,7 +126,8 @@ static ErrorOr> run_test_files(Spanwrite_lines(files.slice(test_index))) { + if (auto maybe_error = runner_process->write_lines(files.slice(test_index)); maybe_error.is_error()) { + warnln("Runner process failed writing writing file input: {}", maybe_error.error()); fail_all_after(); return results; } diff --git a/Userland/Libraries/LibCore/Command.cpp b/Userland/Libraries/LibCore/Command.cpp index 9173b5616b4..e7e8d257f68 100644 --- a/Userland/Libraries/LibCore/Command.cpp +++ b/Userland/Libraries/LibCore/Command.cpp @@ -63,7 +63,7 @@ ErrorOr Command::write(StringView input) return {}; } -bool Command::write_lines(Span lines) +ErrorOr Command::write_lines(Span lines) { // It's possible the process dies before we can write everything to the // stdin. So make sure that we don't crash but just stop writing. @@ -72,10 +72,7 @@ bool Command::write_lines(Span lines) action_handler.sa_handler = SIG_IGN; struct sigaction old_action_handler; - if (sigaction(SIGPIPE, &action_handler, &old_action_handler) < 0) { - perror("sigaction"); - return false; - } + TRY(Core::System::sigaction(SIGPIPE, &action_handler, &old_action_handler)); for (DeprecatedString const& line : lines) { if (m_stdin->write_until_depleted(DeprecatedString::formatted("{}\n", line).bytes()).is_error()) @@ -89,7 +86,7 @@ bool Command::write_lines(Span lines) if (sigaction(SIGPIPE, &old_action_handler, nullptr) < 0) perror("sigaction"); - return true; + return {}; } ErrorOr Command::read_all() diff --git a/Userland/Libraries/LibCore/Command.h b/Userland/Libraries/LibCore/Command.h index e670c61efdb..88ba2d43791 100644 --- a/Userland/Libraries/LibCore/Command.h +++ b/Userland/Libraries/LibCore/Command.h @@ -41,7 +41,7 @@ public: ErrorOr write(StringView input); - bool write_lines(Span lines); + ErrorOr write_lines(Span lines); ErrorOr read_all();