2 * This file is part of attach-f-p strace test.
4 * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2016-2019 The strace developers.
8 * SPDX-License-Identifier: GPL-2.0-or-later
28 static const char text_parent[] = "attach-f-p.test parent";
29 static const char *child[N] = {
30 "attach-f-p.test child 0",
31 "attach-f-p.test child 1",
32 "attach-f-p.test child 2"
34 typedef int pipefd[2];
35 static pipefd pipes[N];
40 unsigned int no = (long) a;
43 if (read(pipes[no][0], &i, sizeof(i)) != (int) sizeof(i))
44 perror_msg_and_fail("read[%u]", no);
45 assert(chdir(child[no]) == -1);
46 retval_t retval = { .pid = syscall(__NR_gettid) };
56 if (write(1, "", 0) != 0)
57 perror_msg_and_fail("write");
59 for (i = 0; i < N; ++i) {
61 perror_msg_and_fail("pipe");
63 errno = pthread_create(&t[i], NULL, thread, (void *) (long) i);
65 perror_msg_and_fail("pthread_create");
68 if (write(1, "\n", 1) != 1)
69 perror_msg_and_fail("write");
71 /* wait for the peer to write to stdout */
75 perror_msg_and_fail("fstat");
76 if (st.st_size >= 103)
80 for (i = 0; i < N; ++i) {
81 /* sleep a bit to let the tracer catch up */
83 if (write(pipes[i][1], &i, sizeof(i)) != (int) sizeof(i))
84 perror_msg_and_fail("write[%u]", i);
86 errno = pthread_join(t[i], &retval.ptr);
88 perror_msg_and_fail("pthread_join");
90 printf("%-5d chdir(\"%s\") = %s\n"
91 "%-5d +++ exited with 0 +++\n",
92 retval.pid, child[i], sprintrc(-1), retval.pid);
95 /* sleep a bit more to let the tracer catch up */
99 assert(chdir(text_parent) == -1);
101 printf("%-5d chdir(\"%s\") = -1 ENOENT (%m)\n"
102 "%-5d +++ exited with 0 +++\n", pid, text_parent, pid);