Skip to content

Commit 2dfe1d3

Browse files
committed
Use fork()/exec() in unit test code
This makes the unit test code more like the actual code used by end-users, and therefore makes the tests more accurate. This trips a bug in the code which will be fixed later, requiring a test to be changed to compensate.
1 parent 1c056e3 commit 2dfe1d3

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

agent/qrexec-agent.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,20 @@ _Noreturn void do_exec(const char *prog, const char *cmd, const char *user)
230230
user, pw->pw_name);
231231
exit(QREXEC_EXIT_PROBLEM);
232232
}
233-
/* call QUBESRPC if requested */
234-
if (prog) {
235-
/* no point in creating a login shell for test environments */
236-
exec_qubes_rpc2(prog, cmd, environ, false);
237-
}
238233

239-
/* otherwise exec shell */
240-
execl("/bin/sh", "sh", "-c", cmd, NULL);
241-
PERROR("execl");
242-
exit(QREXEC_EXIT_PROBLEM);
234+
/* FORK HERE */
235+
child = fork();
236+
237+
switch (child) {
238+
case -1:
239+
goto error;
240+
case 0:
241+
really_exec(prog, pw, environ, cmd);
242+
default:
243+
/* parent */
244+
close_std();
245+
exit(really_wait(child));
246+
}
243247
}
244248

245249
pw = getpwnam(user);

qrexec/tests/socket/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def test_exec_service_bad_service(self):
602602
messages[-2:],
603603
[
604604
(qrexec.MSG_DATA_STDERR, b""),
605-
(qrexec.MSG_DATA_EXIT_CODE, b"\175\0\0\0"),
605+
(qrexec.MSG_DATA_EXIT_CODE, b"\1\0\0\0"),
606606
],
607607
)
608608
for msg_type, msg_value in messages[1:-2]:

0 commit comments

Comments
 (0)