diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/util/test_os_start_process.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/util/test_os_start_process.c')
-rw-r--r-- | src/util/test_os_start_process.c | 279 |
1 files changed, 139 insertions, 140 deletions
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c index 826e5744c..4efbe91af 100644 --- a/src/util/test_os_start_process.c +++ b/src/util/test_os_start_process.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file util/test_os_start_process.c | 21 | * @file util/test_os_start_process.c |
22 | * @brief testcase for os start process code | 22 | * @brief testcase for os start process code |
@@ -48,8 +48,7 @@ static struct GNUNET_DISK_PipeHandle *hello_pipe_stdout; | |||
48 | 48 | ||
49 | static struct GNUNET_SCHEDULER_Task * die_task; | 49 | static struct GNUNET_SCHEDULER_Task * die_task; |
50 | 50 | ||
51 | struct read_context | 51 | struct read_context { |
52 | { | ||
53 | char buf[16]; | 52 | char buf[16]; |
54 | int buf_offset; | 53 | int buf_offset; |
55 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; | 54 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; |
@@ -60,126 +59,126 @@ static struct read_context rc; | |||
60 | 59 | ||
61 | 60 | ||
62 | static void | 61 | static void |
63 | end_task (void *cls) | 62 | end_task(void *cls) |
64 | { | 63 | { |
65 | if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) | 64 | if (0 != GNUNET_OS_process_kill(proc, GNUNET_TERM_SIG)) |
66 | { | 65 | { |
67 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 66 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); |
68 | } | 67 | } |
69 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc)); | 68 | GNUNET_assert(GNUNET_OK == GNUNET_OS_process_wait(proc)); |
70 | GNUNET_OS_process_destroy (proc); | 69 | GNUNET_OS_process_destroy(proc); |
71 | proc = NULL; | 70 | proc = NULL; |
72 | GNUNET_DISK_pipe_close (hello_pipe_stdout); | 71 | GNUNET_DISK_pipe_close(hello_pipe_stdout); |
73 | GNUNET_DISK_pipe_close (hello_pipe_stdin); | 72 | GNUNET_DISK_pipe_close(hello_pipe_stdin); |
74 | } | 73 | } |
75 | 74 | ||
76 | 75 | ||
77 | static void | 76 | static void |
78 | read_call (void *cls) | 77 | read_call(void *cls) |
79 | { | 78 | { |
80 | int bytes; | 79 | int bytes; |
81 | 80 | ||
82 | bytes = GNUNET_DISK_file_read (rc.stdout_read_handle, | 81 | bytes = GNUNET_DISK_file_read(rc.stdout_read_handle, |
83 | &rc.buf[rc.buf_offset], | 82 | &rc.buf[rc.buf_offset], |
84 | sizeof (rc.buf) - rc.buf_offset); | 83 | sizeof(rc.buf) - rc.buf_offset); |
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 84 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
86 | "bytes is %d\n", | 85 | "bytes is %d\n", |
87 | bytes); | 86 | bytes); |
88 | 87 | ||
89 | if (bytes < 1) | 88 | if (bytes < 1) |
90 | { | 89 | { |
91 | GNUNET_break (0); | 90 | GNUNET_break(0); |
92 | ok = 1; | 91 | ok = 1; |
93 | GNUNET_SCHEDULER_cancel (die_task); | 92 | GNUNET_SCHEDULER_cancel(die_task); |
94 | (void) GNUNET_SCHEDULER_add_now (&end_task, NULL); | 93 | (void)GNUNET_SCHEDULER_add_now(&end_task, NULL); |
95 | return; | 94 | return; |
96 | } | 95 | } |
97 | 96 | ||
98 | ok = strncmp (rc.buf, test_phrase, strlen (test_phrase)); | 97 | ok = strncmp(rc.buf, test_phrase, strlen(test_phrase)); |
99 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 98 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
100 | "read %s\n", | 99 | "read %s\n", |
101 | &rc.buf[rc.buf_offset]); | 100 | &rc.buf[rc.buf_offset]); |
102 | rc.buf_offset += bytes; | 101 | rc.buf_offset += bytes; |
103 | 102 | ||
104 | if (0 == ok) | 103 | if (0 == ok) |
105 | { | 104 | { |
106 | GNUNET_SCHEDULER_cancel (die_task); | 105 | GNUNET_SCHEDULER_cancel(die_task); |
107 | (void) GNUNET_SCHEDULER_add_now (&end_task, NULL); | 106 | (void)GNUNET_SCHEDULER_add_now(&end_task, NULL); |
108 | return; | 107 | return; |
109 | } | 108 | } |
110 | 109 | ||
111 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 110 | GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
112 | rc.stdout_read_handle, | 111 | rc.stdout_read_handle, |
113 | &read_call, | 112 | &read_call, |
114 | NULL); | 113 | NULL); |
115 | } | 114 | } |
116 | 115 | ||
117 | 116 | ||
118 | static void | 117 | static void |
119 | run_task (void *cls) | 118 | run_task(void *cls) |
120 | { | 119 | { |
121 | char *fn; | 120 | char *fn; |
122 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; | 121 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; |
123 | const struct GNUNET_DISK_FileHandle *wh; | 122 | const struct GNUNET_DISK_FileHandle *wh; |
124 | 123 | ||
125 | #if !WINDOWS | 124 | #if !WINDOWS |
126 | GNUNET_asprintf (&fn, "cat"); | 125 | GNUNET_asprintf(&fn, "cat"); |
127 | #else | 126 | #else |
128 | GNUNET_asprintf (&fn, "w32cat"); | 127 | GNUNET_asprintf(&fn, "w32cat"); |
129 | #endif | 128 | #endif |
130 | 129 | ||
131 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); | 130 | hello_pipe_stdin = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); |
132 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); | 131 | hello_pipe_stdout = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); |
133 | 132 | ||
134 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) | 133 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) |
135 | { | 134 | { |
136 | GNUNET_break (0); | 135 | GNUNET_break(0); |
137 | ok = 1; | 136 | ok = 1; |
138 | GNUNET_free (fn); | 137 | GNUNET_free(fn); |
139 | return; | 138 | return; |
140 | } | 139 | } |
141 | 140 | ||
142 | proc = | 141 | proc = |
143 | GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, | 142 | GNUNET_OS_start_process(GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, |
144 | hello_pipe_stdin, hello_pipe_stdout, NULL, | 143 | hello_pipe_stdin, hello_pipe_stdout, NULL, |
145 | fn, | 144 | fn, |
146 | "test_gnunet_echo_hello", "-", NULL); | 145 | "test_gnunet_echo_hello", "-", NULL); |
147 | GNUNET_free (fn); | 146 | GNUNET_free(fn); |
148 | 147 | ||
149 | /* Close the write end of the read pipe */ | 148 | /* Close the write end of the read pipe */ |
150 | GNUNET_DISK_pipe_close_end (hello_pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); | 149 | GNUNET_DISK_pipe_close_end(hello_pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); |
151 | /* Close the read end of the write pipe */ | 150 | /* Close the read end of the write pipe */ |
152 | GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_READ); | 151 | GNUNET_DISK_pipe_close_end(hello_pipe_stdin, GNUNET_DISK_PIPE_END_READ); |
153 | 152 | ||
154 | wh = GNUNET_DISK_pipe_handle (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); | 153 | wh = GNUNET_DISK_pipe_handle(hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); |
155 | 154 | ||
156 | /* Write the test_phrase to the cat process */ | 155 | /* Write the test_phrase to the cat process */ |
157 | if (GNUNET_DISK_file_write (wh, test_phrase, strlen (test_phrase) + 1) != | 156 | if (GNUNET_DISK_file_write(wh, test_phrase, strlen(test_phrase) + 1) != |
158 | strlen (test_phrase) + 1) | 157 | strlen(test_phrase) + 1) |
159 | { | 158 | { |
160 | GNUNET_break (0); | 159 | GNUNET_break(0); |
161 | ok = 1; | 160 | ok = 1; |
162 | return; | 161 | return; |
163 | } | 162 | } |
164 | 163 | ||
165 | /* Close the write end to end the cycle! */ | 164 | /* Close the write end to end the cycle! */ |
166 | GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); | 165 | GNUNET_DISK_pipe_close_end(hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); |
167 | 166 | ||
168 | stdout_read_handle = | 167 | stdout_read_handle = |
169 | GNUNET_DISK_pipe_handle (hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ); | 168 | GNUNET_DISK_pipe_handle(hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ); |
170 | 169 | ||
171 | die_task = | 170 | die_task = |
172 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 171 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
173 | (GNUNET_TIME_UNIT_MINUTES, 1), | 172 | (GNUNET_TIME_UNIT_MINUTES, 1), |
174 | &end_task, | 173 | &end_task, |
175 | NULL); | 174 | NULL); |
176 | 175 | ||
177 | memset (&rc, 0, sizeof (rc)); | 176 | memset(&rc, 0, sizeof(rc)); |
178 | rc.stdout_read_handle = stdout_read_handle; | 177 | rc.stdout_read_handle = stdout_read_handle; |
179 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 178 | GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
180 | stdout_read_handle, | 179 | stdout_read_handle, |
181 | &read_call, | 180 | &read_call, |
182 | NULL); | 181 | NULL); |
183 | } | 182 | } |
184 | 183 | ||
185 | 184 | ||
@@ -188,10 +187,10 @@ run_task (void *cls) | |||
188 | * checks that "ok" is correct at the end. | 187 | * checks that "ok" is correct at the end. |
189 | */ | 188 | */ |
190 | static int | 189 | static int |
191 | check_run () | 190 | check_run() |
192 | { | 191 | { |
193 | ok = 1; | 192 | ok = 1; |
194 | GNUNET_SCHEDULER_run (&run_task, &ok); | 193 | GNUNET_SCHEDULER_run(&run_task, &ok); |
195 | return ok; | 194 | return ok; |
196 | } | 195 | } |
197 | 196 | ||
@@ -200,40 +199,40 @@ check_run () | |||
200 | * Test killing via pipe. | 199 | * Test killing via pipe. |
201 | */ | 200 | */ |
202 | static int | 201 | static int |
203 | check_kill () | 202 | check_kill() |
204 | { | 203 | { |
205 | char *fn; | 204 | char *fn; |
206 | 205 | ||
207 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); | 206 | hello_pipe_stdin = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); |
208 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); | 207 | hello_pipe_stdout = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); |
209 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) | 208 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) |
210 | { | 209 | { |
211 | return 1; | 210 | return 1; |
212 | } | 211 | } |
213 | fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); | 212 | fn = GNUNET_OS_get_libexec_binary_path("gnunet-service-resolver"); |
214 | proc = | 213 | proc = |
215 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, | 214 | GNUNET_OS_start_process(GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, |
216 | hello_pipe_stdin, | 215 | hello_pipe_stdin, |
217 | hello_pipe_stdout, | 216 | hello_pipe_stdout, |
218 | NULL, | 217 | NULL, |
219 | fn, | 218 | fn, |
220 | "gnunet-service-resolver", "-", | 219 | "gnunet-service-resolver", "-", |
221 | NULL); | 220 | NULL); |
222 | if (NULL == proc) | 221 | if (NULL == proc) |
223 | { | 222 | { |
224 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 223 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
225 | "Failed to launch gnunet-service-resolver. Is your system setup correct?\n"); | 224 | "Failed to launch gnunet-service-resolver. Is your system setup correct?\n"); |
226 | return 77; | 225 | return 77; |
227 | } | 226 | } |
228 | sleep (1); /* give process time to start, so we actually use the pipe-kill mechanism! */ | 227 | sleep(1); /* give process time to start, so we actually use the pipe-kill mechanism! */ |
229 | GNUNET_free (fn); | 228 | GNUNET_free(fn); |
230 | if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) | 229 | if (0 != GNUNET_OS_process_kill(proc, GNUNET_TERM_SIG)) |
231 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 230 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); |
232 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc)); | 231 | GNUNET_assert(GNUNET_OK == GNUNET_OS_process_wait(proc)); |
233 | GNUNET_OS_process_destroy (proc); | 232 | GNUNET_OS_process_destroy(proc); |
234 | proc = NULL; | 233 | proc = NULL; |
235 | GNUNET_DISK_pipe_close (hello_pipe_stdout); | 234 | GNUNET_DISK_pipe_close(hello_pipe_stdout); |
236 | GNUNET_DISK_pipe_close (hello_pipe_stdin); | 235 | GNUNET_DISK_pipe_close(hello_pipe_stdin); |
237 | return 0; | 236 | return 0; |
238 | } | 237 | } |
239 | 238 | ||
@@ -242,55 +241,55 @@ check_kill () | |||
242 | * Test killing via pipe. | 241 | * Test killing via pipe. |
243 | */ | 242 | */ |
244 | static int | 243 | static int |
245 | check_instant_kill () | 244 | check_instant_kill() |
246 | { | 245 | { |
247 | char *fn; | 246 | char *fn; |
248 | 247 | ||
249 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); | 248 | hello_pipe_stdin = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); |
250 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); | 249 | hello_pipe_stdout = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); |
251 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) | 250 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) |
252 | { | 251 | { |
253 | return 1; | 252 | return 1; |
254 | } | 253 | } |
255 | fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); | 254 | fn = GNUNET_OS_get_libexec_binary_path("gnunet-service-resolver"); |
256 | proc = | 255 | proc = |
257 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, | 256 | GNUNET_OS_start_process(GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, |
258 | hello_pipe_stdin, hello_pipe_stdout, NULL, | 257 | hello_pipe_stdin, hello_pipe_stdout, NULL, |
259 | fn, | 258 | fn, |
260 | "gnunet-service-resolver", "-", NULL); | 259 | "gnunet-service-resolver", "-", NULL); |
261 | if (NULL == proc) | 260 | if (NULL == proc) |
262 | { | 261 | { |
263 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 262 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
264 | "Failed to launch gnunet-service-resolver. Is your system setup correct?\n"); | 263 | "Failed to launch gnunet-service-resolver. Is your system setup correct?\n"); |
265 | return 77; | 264 | return 77; |
266 | } | 265 | } |
267 | if (0 != GNUNET_OS_process_kill (proc, | 266 | if (0 != GNUNET_OS_process_kill(proc, |
268 | GNUNET_TERM_SIG)) | 267 | GNUNET_TERM_SIG)) |
269 | { | 268 | { |
270 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 269 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); |
271 | } | 270 | } |
272 | GNUNET_free (fn); | 271 | GNUNET_free(fn); |
273 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc)); | 272 | GNUNET_assert(GNUNET_OK == GNUNET_OS_process_wait(proc)); |
274 | GNUNET_OS_process_destroy (proc); | 273 | GNUNET_OS_process_destroy(proc); |
275 | proc = NULL; | 274 | proc = NULL; |
276 | GNUNET_DISK_pipe_close (hello_pipe_stdout); | 275 | GNUNET_DISK_pipe_close(hello_pipe_stdout); |
277 | GNUNET_DISK_pipe_close (hello_pipe_stdin); | 276 | GNUNET_DISK_pipe_close(hello_pipe_stdin); |
278 | return 0; | 277 | return 0; |
279 | } | 278 | } |
280 | 279 | ||
281 | 280 | ||
282 | int | 281 | int |
283 | main (int argc, char *argv[]) | 282 | main(int argc, char *argv[]) |
284 | { | 283 | { |
285 | int ret; | 284 | int ret; |
286 | 285 | ||
287 | GNUNET_log_setup ("test-os-start-process", | 286 | GNUNET_log_setup("test-os-start-process", |
288 | "WARNING", | 287 | "WARNING", |
289 | NULL); | 288 | NULL); |
290 | ret = 0; | 289 | ret = 0; |
291 | ret |= check_run (); | 290 | ret |= check_run(); |
292 | ret |= check_kill (); | 291 | ret |= check_kill(); |
293 | ret |= check_instant_kill (); | 292 | ret |= check_instant_kill(); |
294 | return ret; | 293 | return ret; |
295 | } | 294 | } |
296 | 295 | ||