Skip to content

Commit

Permalink
Try to retrieve exit code of a failed service call
Browse files Browse the repository at this point in the history
When service call fails, the remote (service) side sends EOF + exit code
and closes the vchan immediately. If the client side tries to send
something, it will fail and exit immediately (with code 1). But reading
data that was queued in the vchan before its closing is still possible.
So, on send error check if there is anything interesting to receive
(especially exit code, but potentially also some service output) and, if
yes, don't exit immediately. Since the service exit code is sent last
(after all stdout/stderr data and their EOF), it's okay to check just
for remote_status.
This is relevant only to the service client side, as exit status of the
service-handling process is not relevant.

Fixes QubesOS/qubes-issues#9618
  • Loading branch information
marmarek committed Dec 3, 2024
1 parent 5c028c0 commit 66c1519
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion libqrexec/process_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,16 @@ int qrexec_process_io(const struct process_io_request *req,
vchan, stdout_fd, stdout_msg_type,
&prefix, &remote_buffer)) {
case REMOTE_ERROR:
handle_vchan_error("send(handle_input stdout)");
if (!is_service && remote_status == -1) {

Check warning on line 349 in libqrexec/process_io.c

View check run for this annotation

Codecov / codecov/patch

libqrexec/process_io.c#L349

Added line #L349 was not covered by tests
/* Even if sending fails, still try to read remaining
* data, if any - especially the exit code. But don't
* send anything anymore.
*/
LOG(ERROR, "Error while vchan send (handle_input stdout), reading remaining data");
close_stdout();

Check warning on line 355 in libqrexec/process_io.c

View check run for this annotation

Codecov / codecov/patch

libqrexec/process_io.c#L354-L355

Added lines #L354 - L355 were not covered by tests
} else {
handle_vchan_error("send(handle_input stdout)");

Check warning on line 357 in libqrexec/process_io.c

View check run for this annotation

Codecov / codecov/patch

libqrexec/process_io.c#L357

Added line #L357 was not covered by tests
}
break;
case REMOTE_EOF:
close_stdout();
Expand Down

0 comments on commit 66c1519

Please sign in to comment.