Skip to content

Commit 8120940

Browse files
committed
Document the file descriptrs for struct process_io_request
They make sense for local processes, but for remote processes, stdin_fd and stdout_fd are backwards, and stderr_fd is -1.
1 parent a3bbcb5 commit 8120940

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

libqrexec/libqrexec-utils.h

+5
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ struct process_io_request {
276276
libvchan_t *vchan;
277277
struct buffer *stdin_buf;
278278

279+
/* Note that stdin_fd, stdout_fd, and stderr_fd are named assuming a
280+
* *local* process. For a *remote* process, stdin_fd is the standard
281+
* *output*, stdout_fd is the standard *input*, and stderr_fd must be -1. */
279282
// stderr_fd can be -1
280283
int stdin_fd, stdout_fd, stderr_fd;
281284
// 0 if no child process
@@ -284,12 +287,14 @@ struct process_io_request {
284287
/*
285288
is_service true (this is a service):
286289
- send local data as MSG_DATA_STDOUT
290+
- send local stderr as MSG_DATA_STDERR, unless in dom0
287291
- send exit code
288292
- wait just for local end
289293
- return local exit code
290294
291295
is_service false (this is a client):
292296
- send local data as MSG_DATA_STDIN
297+
- stderr_fd is always -1
293298
- don't send exit code
294299
- wait for local and remote end
295300
- return remote exit code

libqrexec/process_io.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*
2020
*/
2121

22+
#include <assert.h>
2223
#include <signal.h>
2324
#include <sys/wait.h>
2425
#include <sys/socket.h>
@@ -110,8 +111,10 @@ int process_io(const struct process_io_request *req) {
110111
set_nonblock(stdin_fd);
111112
if (stdout_fd != stdin_fd)
112113
set_nonblock(stdout_fd);
113-
if (stderr_fd >= 0)
114+
if (stderr_fd >= 0) {
115+
assert(is_service); // if this is a client, stderr_fd is *always* -1
114116
set_nonblock(stderr_fd);
117+
}
115118

116119
/* Convenience macros that eliminate a ton of error-prone boilerplate */
117120
#define close_stdin() do { \

0 commit comments

Comments
 (0)