@@ -68,29 +68,27 @@ static void kick_child(struct child *child)
68
68
fflush (NULL );
69
69
}
70
70
71
- static struct child * spawn_child ( void )
71
+ static int spawn_child ( struct child * child )
72
72
{
73
- static struct child child ;
74
- int err ;
75
- int c ;
73
+ int err , c ;
76
74
77
75
/* pipe to notify child to execute the trigger functions */
78
- if (pipe (child . go ))
79
- return NULL ;
76
+ if (pipe (child -> go ))
77
+ return -1 ;
80
78
81
- child . pid = child . tid = fork ();
82
- if (child . pid < 0 ) {
83
- release_child (& child );
79
+ child -> pid = child -> tid = fork ();
80
+ if (child -> pid < 0 ) {
81
+ release_child (child );
84
82
errno = EINVAL ;
85
- return NULL ;
83
+ return -1 ;
86
84
}
87
85
88
86
/* child */
89
- if (child . pid == 0 ) {
90
- close (child . go [1 ]);
87
+ if (child -> pid == 0 ) {
88
+ close (child -> go [1 ]);
91
89
92
90
/* wait for parent's kick */
93
- err = read (child . go [0 ], & c , 1 );
91
+ err = read (child -> go [0 ], & c , 1 );
94
92
if (err != 1 )
95
93
exit (err );
96
94
@@ -102,7 +100,7 @@ static struct child *spawn_child(void)
102
100
exit (errno );
103
101
}
104
102
105
- return & child ;
103
+ return 0 ;
106
104
}
107
105
108
106
static void * child_thread (void * ctx )
@@ -131,39 +129,38 @@ static void *child_thread(void *ctx)
131
129
pthread_exit (& err );
132
130
}
133
131
134
- static struct child * spawn_thread ( void )
132
+ static int spawn_thread ( struct child * child )
135
133
{
136
- static struct child child ;
137
134
int c , err ;
138
135
139
136
/* pipe to notify child to execute the trigger functions */
140
- if (pipe (child . go ))
141
- return NULL ;
137
+ if (pipe (child -> go ))
138
+ return -1 ;
142
139
/* pipe to notify parent that child thread is ready */
143
- if (pipe (child . c2p )) {
144
- close (child . go [0 ]);
145
- close (child . go [1 ]);
146
- return NULL ;
140
+ if (pipe (child -> c2p )) {
141
+ close (child -> go [0 ]);
142
+ close (child -> go [1 ]);
143
+ return -1 ;
147
144
}
148
145
149
- child . pid = getpid ();
146
+ child -> pid = getpid ();
150
147
151
- err = pthread_create (& child . thread , NULL , child_thread , & child );
148
+ err = pthread_create (& child -> thread , NULL , child_thread , child );
152
149
if (err ) {
153
150
err = - errno ;
154
- close (child . go [0 ]);
155
- close (child . go [1 ]);
156
- close (child . c2p [0 ]);
157
- close (child . c2p [1 ]);
151
+ close (child -> go [0 ]);
152
+ close (child -> go [1 ]);
153
+ close (child -> c2p [0 ]);
154
+ close (child -> c2p [1 ]);
158
155
errno = - err ;
159
- return NULL ;
156
+ return -1 ;
160
157
}
161
158
162
- err = read (child . c2p [0 ], & c , 1 );
159
+ err = read (child -> c2p [0 ], & c , 1 );
163
160
if (!ASSERT_EQ (err , 1 , "child_thread_ready" ))
164
- return NULL ;
161
+ return -1 ;
165
162
166
- return & child ;
163
+ return 0 ;
167
164
}
168
165
169
166
static void uprobe_multi_test_run (struct uprobe_multi * skel , struct child * child )
@@ -304,24 +301,22 @@ __test_attach_api(const char *binary, const char *pattern, struct bpf_uprobe_mul
304
301
static void
305
302
test_attach_api (const char * binary , const char * pattern , struct bpf_uprobe_multi_opts * opts )
306
303
{
307
- struct child * child ;
304
+ static struct child child ;
308
305
309
306
/* no pid filter */
310
307
__test_attach_api (binary , pattern , opts , NULL );
311
308
312
309
/* pid filter */
313
- child = spawn_child ();
314
- if (!ASSERT_OK_PTR (child , "spawn_child" ))
310
+ if (!ASSERT_OK (spawn_child (& child ), "spawn_child" ))
315
311
return ;
316
312
317
- __test_attach_api (binary , pattern , opts , child );
313
+ __test_attach_api (binary , pattern , opts , & child );
318
314
319
315
/* pid filter (thread) */
320
- child = spawn_thread ();
321
- if (!ASSERT_OK_PTR (child , "spawn_thread" ))
316
+ if (!ASSERT_OK (spawn_thread (& child ), "spawn_thread" ))
322
317
return ;
323
318
324
- __test_attach_api (binary , pattern , opts , child );
319
+ __test_attach_api (binary , pattern , opts , & child );
325
320
}
326
321
327
322
static void test_attach_api_pattern (void )
@@ -712,24 +707,22 @@ static void __test_link_api(struct child *child)
712
707
713
708
static void test_link_api (void )
714
709
{
715
- struct child * child ;
710
+ static struct child child ;
716
711
717
712
/* no pid filter */
718
713
__test_link_api (NULL );
719
714
720
715
/* pid filter */
721
- child = spawn_child ();
722
- if (!ASSERT_OK_PTR (child , "spawn_child" ))
716
+ if (!ASSERT_OK (spawn_child (& child ), "spawn_child" ))
723
717
return ;
724
718
725
- __test_link_api (child );
719
+ __test_link_api (& child );
726
720
727
721
/* pid filter (thread) */
728
- child = spawn_thread ();
729
- if (!ASSERT_OK_PTR (child , "spawn_thread" ))
722
+ if (!ASSERT_OK (spawn_thread (& child ), "spawn_thread" ))
730
723
return ;
731
724
732
- __test_link_api (child );
725
+ __test_link_api (& child );
733
726
}
734
727
735
728
static struct bpf_program *
0 commit comments