Skip to content

Commit 4f5c289

Browse files
avaginChristian Brauner
authored andcommitted
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: 41585bb ("selftests: add tests for clone3() with *set_tid") Signed-off-by: Andrei Vagin <avagin@gmail.com> Link: https://lore.kernel.org/r/20191118064750.408003-1-avagin@gmail.com Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
1 parent 41585bb commit 4f5c289

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

tools/testing/selftests/clone3/clone3_selftests.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ struct clone_args {
2929

3030
static pid_t sys_clone3(struct clone_args *args, size_t size)
3131
{
32+
fflush(stdout);
33+
fflush(stderr);
3234
return syscall(__NR_clone3, args, size);
3335
}
3436

tools/testing/selftests/clone3/clone3_set_tid.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
static int pipe_1[2];
3131
static int pipe_2[2];
3232

33+
static void child_exit(int ret)
34+
{
35+
fflush(stdout);
36+
fflush(stderr);
37+
_exit(ret);
38+
}
39+
3340
static int call_clone3_set_tid(pid_t *set_tid,
3441
size_t set_tid_size,
3542
int flags,
@@ -84,8 +91,8 @@ static int call_clone3_set_tid(pid_t *set_tid,
8491
}
8592

8693
if (set_tid[0] != getpid())
87-
_exit(EXIT_FAILURE);
88-
_exit(exit_code);
94+
child_exit(EXIT_FAILURE);
95+
child_exit(exit_code);
8996
}
9097

9198
if (expected_pid == 0 || expected_pid == pid) {
@@ -249,7 +256,7 @@ int main(int argc, char *argv[])
249256
pid = fork();
250257
if (pid == 0) {
251258
ksft_print_msg("Child has PID %d\n", getpid());
252-
_exit(EXIT_SUCCESS);
259+
child_exit(EXIT_SUCCESS);
253260
}
254261
if (waitpid(pid, &status, 0) < 0)
255262
ksft_exit_fail_msg("Waiting for child %d failed", pid);
@@ -309,7 +316,7 @@ int main(int argc, char *argv[])
309316
*/
310317
test_clone3_set_tid(set_tid, 3, CLONE_NEWPID, 0, 42, true);
311318

312-
_exit(ksft_cnt.ksft_pass);
319+
child_exit(ksft_cnt.ksft_pass);
313320
}
314321

315322
close(pipe_1[1]);

0 commit comments

Comments
 (0)