Commit 4f5c289e authored by Andrei Vagin's avatar Andrei Vagin Committed by Christian Brauner

selftests/clone3: flush stdout and stderr before clone3() and _exit()

Buffers have to be flushed before clone3() to avoid double messages in
the log.

Fixes: 41585bbe ("selftests: add tests for clone3() with *set_tid")
Signed-off-by: default avatarAndrei Vagin <avagin@gmail.com>
Link: https://lore.kernel.org/r/20191118064750.408003-1-avagin@gmail.comSigned-off-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 41585bbe
...@@ -29,6 +29,8 @@ struct clone_args { ...@@ -29,6 +29,8 @@ struct clone_args {
static pid_t sys_clone3(struct clone_args *args, size_t size) static pid_t sys_clone3(struct clone_args *args, size_t size)
{ {
fflush(stdout);
fflush(stderr);
return syscall(__NR_clone3, args, size); return syscall(__NR_clone3, args, size);
} }
......
...@@ -30,6 +30,13 @@ ...@@ -30,6 +30,13 @@
static int pipe_1[2]; static int pipe_1[2];
static int pipe_2[2]; static int pipe_2[2];
static void child_exit(int ret)
{
fflush(stdout);
fflush(stderr);
_exit(ret);
}
static int call_clone3_set_tid(pid_t *set_tid, static int call_clone3_set_tid(pid_t *set_tid,
size_t set_tid_size, size_t set_tid_size,
int flags, int flags,
...@@ -84,8 +91,8 @@ static int call_clone3_set_tid(pid_t *set_tid, ...@@ -84,8 +91,8 @@ static int call_clone3_set_tid(pid_t *set_tid,
} }
if (set_tid[0] != getpid()) if (set_tid[0] != getpid())
_exit(EXIT_FAILURE); child_exit(EXIT_FAILURE);
_exit(exit_code); child_exit(exit_code);
} }
if (expected_pid == 0 || expected_pid == pid) { if (expected_pid == 0 || expected_pid == pid) {
...@@ -249,7 +256,7 @@ int main(int argc, char *argv[]) ...@@ -249,7 +256,7 @@ int main(int argc, char *argv[])
pid = fork(); pid = fork();
if (pid == 0) { if (pid == 0) {
ksft_print_msg("Child has PID %d\n", getpid()); ksft_print_msg("Child has PID %d\n", getpid());
_exit(EXIT_SUCCESS); child_exit(EXIT_SUCCESS);
} }
if (waitpid(pid, &status, 0) < 0) if (waitpid(pid, &status, 0) < 0)
ksft_exit_fail_msg("Waiting for child %d failed", pid); ksft_exit_fail_msg("Waiting for child %d failed", pid);
...@@ -309,7 +316,7 @@ int main(int argc, char *argv[]) ...@@ -309,7 +316,7 @@ int main(int argc, char *argv[])
*/ */
test_clone3_set_tid(set_tid, 3, CLONE_NEWPID, 0, 42, true); test_clone3_set_tid(set_tid, 3, CLONE_NEWPID, 0, 42, true);
_exit(ksft_cnt.ksft_pass); child_exit(ksft_cnt.ksft_pass);
} }
close(pipe_1[1]); close(pipe_1[1]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment