mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
LibCore: Error on a fail to write in Command::write_lines
This commit is contained in:
parent
125145c682
commit
06a44ac2ff
1 changed files with 9 additions and 9 deletions
|
@ -74,17 +74,17 @@ ErrorOr<void> Command::write_lines(Span<DeprecatedString> lines)
|
||||||
struct sigaction old_action_handler;
|
struct sigaction old_action_handler;
|
||||||
TRY(Core::System::sigaction(SIGPIPE, &action_handler, &old_action_handler));
|
TRY(Core::System::sigaction(SIGPIPE, &action_handler, &old_action_handler));
|
||||||
|
|
||||||
for (DeprecatedString const& line : lines) {
|
auto close_stdin = ScopeGuard([this, &old_action_handler] {
|
||||||
if (m_stdin->write_until_depleted(DeprecatedString::formatted("{}\n", line).bytes()).is_error())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure that the input stream ends here, whether we were able to write all lines or not
|
// Ensure that the input stream ends here, whether we were able to write all lines or not
|
||||||
m_stdin->close();
|
m_stdin->close();
|
||||||
|
|
||||||
// It's not really a problem if this signal failed
|
// It's not really a problem if this signal failed
|
||||||
if (sigaction(SIGPIPE, &old_action_handler, nullptr) < 0)
|
if (sigaction(SIGPIPE, &old_action_handler, nullptr) < 0)
|
||||||
perror("sigaction");
|
perror("sigaction");
|
||||||
|
});
|
||||||
|
|
||||||
|
for (DeprecatedString const& line : lines)
|
||||||
|
TRY(m_stdin->write_until_depleted(DeprecatedString::formatted("{}\n", line).bytes()));
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue