2 * This file is part of attach-f-p strace test.
4 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
7 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include <asm/unistd.h>
27 static const char text_parent[] = "attach-f-p.test parent";
28 static const char *child[N] = {
29 "attach-f-p.test child 0",
30 "attach-f-p.test child 1",
31 "attach-f-p.test child 2"
33 typedef int pipefd[2];
34 static pipefd pipes[N];
39 unsigned int no = (long) a;
42 if (read(pipes[no][0], &i, sizeof(i)) != (int) sizeof(i))
43 perror_msg_and_fail("read[%u]", no);
44 assert(chdir(child[no]) == -1);
45 retval_t retval = { .pid = syscall(__NR_gettid) };
55 if (write(1, "", 0) != 0)
56 perror_msg_and_fail("write");
58 for (i = 0; i < N; ++i) {
60 perror_msg_and_fail("pipe");
62 errno = pthread_create(&t[i], NULL, thread, (void *) (long) i);
64 perror_msg_and_fail("pthread_create");
67 if (write(1, "\n", 1) != 1)
68 perror_msg_and_fail("write");
70 /* wait for the peer to write to stdout */
74 perror_msg_and_fail("fstat");
75 if (st.st_size >= 103)
79 for (i = 0; i < N; ++i) {
80 /* sleep a bit to let the tracer catch up */
82 if (write(pipes[i][1], &i, sizeof(i)) != (int) sizeof(i))
83 perror_msg_and_fail("write[%u]", i);
85 errno = pthread_join(t[i], &retval.ptr);
87 perror_msg_and_fail("pthread_join");
89 printf("%-5d chdir(\"%s\") = %s\n"
90 "%-5d +++ exited with 0 +++\n",
91 retval.pid, child[i], sprintrc(-1), retval.pid);
94 /* sleep a bit more to let the tracer catch up */
98 assert(chdir(text_parent) == -1);
100 printf("%-5d chdir(\"%s\") = -1 ENOENT (%m)\n"
101 "%-5d +++ exited with 0 +++\n", pid, text_parent, pid);