Lines Matching full:child
48 struct child { struct
50 int c2p[2]; /* child -> parent channel */ argument
57 static void release_child(struct child *child) in release_child() argument
61 if (!child) in release_child()
63 close(child->go[1]); in release_child()
64 close(child->go[0]); in release_child()
65 if (child->thread) in release_child()
66 pthread_join(child->thread, NULL); in release_child()
67 close(child->c2p[0]); in release_child()
68 close(child->c2p[1]); in release_child()
69 if (child->pid > 0) in release_child()
70 waitpid(child->pid, &child_status, 0); in release_child()
73 static void kick_child(struct child *child) in kick_child() argument
77 if (child) { in kick_child()
78 write(child->go[1], &c, 1); in kick_child()
79 release_child(child); in kick_child()
86 struct child *child = arg; in child_func() local
89 close(child->go[1]); in child_func()
92 err = read(child->go[0], &c, 1); in child_func()
104 static int spawn_child_flag(struct child *child, bool clone_vm) in spawn_child_flag() argument
106 /* pipe to notify child to execute the trigger functions */ in spawn_child_flag()
107 if (pipe(child->go)) in spawn_child_flag()
111 child->pid = child->tid = clone(child_func, child->stack + sizeof(child->stack)/2, in spawn_child_flag()
112 CLONE_VM|SIGCHLD, child); in spawn_child_flag()
114 child->pid = child->tid = fork(); in spawn_child_flag()
116 if (child->pid < 0) { in spawn_child_flag()
117 release_child(child); in spawn_child_flag()
122 /* fork-ed child */ in spawn_child_flag()
123 if (!clone_vm && child->pid == 0) in spawn_child_flag()
124 child_func(child); in spawn_child_flag()
129 static int spawn_child(struct child *child) in spawn_child() argument
131 return spawn_child_flag(child, false); in spawn_child()
136 struct child *child = ctx; in child_thread() local
139 child->tid = sys_gettid(); in child_thread()
142 err = write(child->c2p[1], &c, 1); in child_thread()
147 err = read(child->go[0], &c, 1); in child_thread()
160 static int spawn_thread(struct child *child) in spawn_thread() argument
164 /* pipe to notify child to execute the trigger functions */ in spawn_thread()
165 if (pipe(child->go)) in spawn_thread()
167 /* pipe to notify parent that child thread is ready */ in spawn_thread()
168 if (pipe(child->c2p)) { in spawn_thread()
169 close(child->go[0]); in spawn_thread()
170 close(child->go[1]); in spawn_thread()
174 child->pid = getpid(); in spawn_thread()
176 err = pthread_create(&child->thread, NULL, child_thread, child); in spawn_thread()
179 close(child->go[0]); in spawn_thread()
180 close(child->go[1]); in spawn_thread()
181 close(child->c2p[0]); in spawn_thread()
182 close(child->c2p[1]); in spawn_thread()
187 err = read(child->c2p[0], &c, 1); in spawn_thread()
194 static void uprobe_multi_test_run(struct uprobe_multi *skel, struct child *child) in uprobe_multi_test_run() argument
204 * because the probe should be executed only by child->pid in uprobe_multi_test_run()
207 skel->bss->pid = child ? 0 : getpid(); in uprobe_multi_test_run()
208 skel->bss->expect_pid = child ? child->pid : 0; in uprobe_multi_test_run()
210 /* trigger all probes, if we are testing child *process*, just to make in uprobe_multi_test_run()
212 * PIDs; when we test child *thread*, we don't want to do this to in uprobe_multi_test_run()
215 if (!child || !child->thread) { in uprobe_multi_test_run()
222 if (child) in uprobe_multi_test_run()
223 kick_child(child); in uprobe_multi_test_run()
241 if (child) { in uprobe_multi_test_run()
242 ASSERT_EQ(skel->bss->child_pid, child->pid, "uprobe_multi_child_pid"); in uprobe_multi_test_run()
243 ASSERT_EQ(skel->bss->child_tid, child->tid, "uprobe_multi_child_tid"); in uprobe_multi_test_run()
268 struct child *child) in __test_attach_api() argument
270 pid_t pid = child ? child->pid : -1; in __test_attach_api()
318 uprobe_multi_test_run(skel, child); in __test_attach_api()
321 if (child) { in __test_attach_api()
322 ASSERT_EQ(skel->bss->child_pid_usdt, child->pid, "usdt_multi_child_pid"); in __test_attach_api()
323 ASSERT_EQ(skel->bss->child_tid_usdt, child->tid, "usdt_multi_child_tid"); in __test_attach_api()
332 static struct child child; in test_attach_api() local
338 if (!ASSERT_OK(spawn_child(&child), "spawn_child")) in test_attach_api()
341 __test_attach_api(binary, pattern, opts, &child); in test_attach_api()
344 if (!ASSERT_OK(spawn_thread(&child), "spawn_thread")) in test_attach_api()
347 __test_attach_api(binary, pattern, opts, &child); in test_attach_api()
659 static void __test_link_api(struct child *child) in __test_link_api() argument
681 opts.uprobe_multi.pid = child ? child->pid : 0; in __test_link_api()
718 uprobe_multi_test_run(skel, child); in __test_link_api()
738 static struct child child; in test_link_api() local
744 if (!ASSERT_OK(spawn_child(&child), "spawn_child")) in test_link_api()
747 __test_link_api(&child); in test_link_api()
750 if (!ASSERT_OK(spawn_thread(&child), "spawn_thread")) in test_link_api()
753 __test_link_api(&child); in test_link_api()
1073 struct child child[TASKS] = {}; in run_pid_filter() local
1079 if (!ASSERT_OK(spawn_child_flag(&child[i], clone_vm), "spawn_child")) in run_pid_filter()
1081 skel->bss->pids[i] = child[i].pid; in run_pid_filter()
1086 child[i].pid, "/proc/self/exe", in run_pid_filter()
1093 kick_child(&child[i]); in run_pid_filter()
1104 release_child(&child[i]); in run_pid_filter()