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/arm | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/arm')
-rw-r--r-- | src/arm/arm.h | 18 | ||||
-rw-r--r-- | src/arm/arm_api.c | 710 | ||||
-rw-r--r-- | src/arm/arm_monitor_api.c | 150 | ||||
-rw-r--r-- | src/arm/gnunet-arm.c | 840 | ||||
-rw-r--r-- | src/arm/gnunet-service-arm.c | 2268 | ||||
-rw-r--r-- | src/arm/mockup-service.c | 75 | ||||
-rw-r--r-- | src/arm/test_arm_api.c | 241 | ||||
-rw-r--r-- | src/arm/test_exponential_backoff.c | 386 | ||||
-rw-r--r-- | src/arm/test_gnunet_service_arm.c | 252 |
9 files changed, 2477 insertions, 2463 deletions
diff --git a/src/arm/arm.h b/src/arm/arm.h index 937cca1e7..983586060 100644 --- a/src/arm/arm.h +++ b/src/arm/arm.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
@@ -38,9 +38,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
38 | /** | 38 | /** |
39 | * Status update from ARM to client. | 39 | * Status update from ARM to client. |
40 | */ | 40 | */ |
41 | struct GNUNET_ARM_StatusMessage | 41 | struct GNUNET_ARM_StatusMessage { |
42 | { | ||
43 | |||
44 | /** | 42 | /** |
45 | * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_STATUS. | 43 | * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_STATUS. |
46 | */ | 44 | */ |
@@ -54,8 +52,7 @@ struct GNUNET_ARM_StatusMessage | |||
54 | /* followed by a 0-terminated service name */ | 52 | /* followed by a 0-terminated service name */ |
55 | }; | 53 | }; |
56 | 54 | ||
57 | struct GNUNET_ARM_Message | 55 | struct GNUNET_ARM_Message { |
58 | { | ||
59 | /** | 56 | /** |
60 | * Reply to client, type is #GNUNET_MESSAGE_TYPE_ARM_RESULT or | 57 | * Reply to client, type is #GNUNET_MESSAGE_TYPE_ARM_RESULT or |
61 | * #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT. | 58 | * #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT. |
@@ -84,9 +81,7 @@ struct GNUNET_ARM_Message | |||
84 | /** | 81 | /** |
85 | * Reply from ARM to client. | 82 | * Reply from ARM to client. |
86 | */ | 83 | */ |
87 | struct GNUNET_ARM_ResultMessage | 84 | struct GNUNET_ARM_ResultMessage { |
88 | { | ||
89 | |||
90 | /** | 85 | /** |
91 | * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_RESULT, with an ID. | 86 | * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_RESULT, with an ID. |
92 | */ | 87 | */ |
@@ -104,8 +99,7 @@ struct GNUNET_ARM_ResultMessage | |||
104 | * '\0' terminated strings. header->size contains the | 99 | * '\0' terminated strings. header->size contains the |
105 | * total size (including all strings). | 100 | * total size (including all strings). |
106 | */ | 101 | */ |
107 | struct GNUNET_ARM_ListResultMessage | 102 | struct GNUNET_ARM_ListResultMessage { |
108 | { | ||
109 | /** | 103 | /** |
110 | * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, | 104 | * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, |
111 | * with an ID. | 105 | * with an ID. |
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index bf0acbcb9..b42c95dc0 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file arm/arm_api.c | 22 | * @file arm/arm_api.c |
@@ -30,15 +30,14 @@ | |||
30 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
31 | #include "arm.h" | 31 | #include "arm.h" |
32 | 32 | ||
33 | #define LOG(kind, ...) GNUNET_log_from (kind, "arm-api", __VA_ARGS__) | 33 | #define LOG(kind, ...) GNUNET_log_from(kind, "arm-api", __VA_ARGS__) |
34 | 34 | ||
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Entry in a doubly-linked list of operations awaiting for replies | 37 | * Entry in a doubly-linked list of operations awaiting for replies |
38 | * (in-order) from the ARM service. | 38 | * (in-order) from the ARM service. |
39 | */ | 39 | */ |
40 | struct GNUNET_ARM_Operation | 40 | struct GNUNET_ARM_Operation { |
41 | { | ||
42 | /** | 41 | /** |
43 | * This is a doubly-linked list. | 42 | * This is a doubly-linked list. |
44 | */ | 43 | */ |
@@ -94,8 +93,7 @@ struct GNUNET_ARM_Operation | |||
94 | /** | 93 | /** |
95 | * Handle for interacting with ARM. | 94 | * Handle for interacting with ARM. |
96 | */ | 95 | */ |
97 | struct GNUNET_ARM_Handle | 96 | struct GNUNET_ARM_Handle { |
98 | { | ||
99 | /** | 97 | /** |
100 | * Our connection to the ARM service. | 98 | * Our connection to the ARM service. |
101 | */ | 99 | */ |
@@ -166,7 +164,7 @@ struct GNUNET_ARM_Handle | |||
166 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 164 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
167 | */ | 165 | */ |
168 | static int | 166 | static int |
169 | reconnect_arm (struct GNUNET_ARM_Handle *h); | 167 | reconnect_arm(struct GNUNET_ARM_Handle *h); |
170 | 168 | ||
171 | 169 | ||
172 | /** | 170 | /** |
@@ -175,12 +173,12 @@ reconnect_arm (struct GNUNET_ARM_Handle *h); | |||
175 | * @param cls the `struct GNUNET_ARM_Handle` | 173 | * @param cls the `struct GNUNET_ARM_Handle` |
176 | */ | 174 | */ |
177 | static void | 175 | static void |
178 | reconnect_arm_task (void *cls) | 176 | reconnect_arm_task(void *cls) |
179 | { | 177 | { |
180 | struct GNUNET_ARM_Handle *h = cls; | 178 | struct GNUNET_ARM_Handle *h = cls; |
181 | 179 | ||
182 | h->reconnect_task = NULL; | 180 | h->reconnect_task = NULL; |
183 | reconnect_arm (h); | 181 | reconnect_arm(h); |
184 | } | 182 | } |
185 | 183 | ||
186 | 184 | ||
@@ -191,31 +189,31 @@ reconnect_arm_task (void *cls) | |||
191 | * @param h our handle | 189 | * @param h our handle |
192 | */ | 190 | */ |
193 | static void | 191 | static void |
194 | reconnect_arm_later (struct GNUNET_ARM_Handle *h) | 192 | reconnect_arm_later(struct GNUNET_ARM_Handle *h) |
195 | { | 193 | { |
196 | struct GNUNET_ARM_Operation *op; | 194 | struct GNUNET_ARM_Operation *op; |
197 | 195 | ||
198 | if (NULL != h->mq) | 196 | if (NULL != h->mq) |
199 | { | 197 | { |
200 | GNUNET_MQ_destroy (h->mq); | 198 | GNUNET_MQ_destroy(h->mq); |
201 | h->mq = NULL; | 199 | h->mq = NULL; |
202 | } | 200 | } |
203 | h->currently_up = GNUNET_NO; | 201 | h->currently_up = GNUNET_NO; |
204 | GNUNET_assert (NULL == h->reconnect_task); | 202 | GNUNET_assert(NULL == h->reconnect_task); |
205 | h->reconnect_task = | 203 | h->reconnect_task = |
206 | GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h); | 204 | GNUNET_SCHEDULER_add_delayed(h->retry_backoff, &reconnect_arm_task, h); |
207 | while (NULL != (op = h->operation_pending_head)) | 205 | while (NULL != (op = h->operation_pending_head)) |
208 | { | 206 | { |
209 | if (NULL != op->result_cont) | 207 | if (NULL != op->result_cont) |
210 | op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); | 208 | op->result_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); |
211 | if (NULL != op->list_cont) | 209 | if (NULL != op->list_cont) |
212 | op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); | 210 | op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); |
213 | GNUNET_ARM_operation_cancel (op); | 211 | GNUNET_ARM_operation_cancel(op); |
214 | } | 212 | } |
215 | GNUNET_assert (NULL == h->operation_pending_head); | 213 | GNUNET_assert(NULL == h->operation_pending_head); |
216 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); | 214 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF(h->retry_backoff); |
217 | if (NULL != h->conn_status) | 215 | if (NULL != h->conn_status) |
218 | h->conn_status (h->conn_status_cls, GNUNET_NO); | 216 | h->conn_status(h->conn_status_cls, GNUNET_NO); |
219 | } | 217 | } |
220 | 218 | ||
221 | 219 | ||
@@ -227,7 +225,7 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h) | |||
227 | * @return NULL if not found | 225 | * @return NULL if not found |
228 | */ | 226 | */ |
229 | static struct GNUNET_ARM_Operation * | 227 | static struct GNUNET_ARM_Operation * |
230 | find_op_by_id (struct GNUNET_ARM_Handle *h, uint64_t id) | 228 | find_op_by_id(struct GNUNET_ARM_Handle *h, uint64_t id) |
231 | { | 229 | { |
232 | struct GNUNET_ARM_Operation *result; | 230 | struct GNUNET_ARM_Operation *result; |
233 | 231 | ||
@@ -246,7 +244,7 @@ find_op_by_id (struct GNUNET_ARM_Handle *h, uint64_t id) | |||
246 | * @param res the message received from the arm service | 244 | * @param res the message received from the arm service |
247 | */ | 245 | */ |
248 | static void | 246 | static void |
249 | handle_arm_result (void *cls, const struct GNUNET_ARM_ResultMessage *res) | 247 | handle_arm_result(void *cls, const struct GNUNET_ARM_ResultMessage *res) |
250 | { | 248 | { |
251 | struct GNUNET_ARM_Handle *h = cls; | 249 | struct GNUNET_ARM_Handle *h = cls; |
252 | struct GNUNET_ARM_Operation *op; | 250 | struct GNUNET_ARM_Operation *op; |
@@ -255,43 +253,43 @@ handle_arm_result (void *cls, const struct GNUNET_ARM_ResultMessage *res) | |||
255 | GNUNET_ARM_ResultCallback result_cont; | 253 | GNUNET_ARM_ResultCallback result_cont; |
256 | void *result_cont_cls; | 254 | void *result_cont_cls; |
257 | 255 | ||
258 | id = GNUNET_ntohll (res->arm_msg.request_id); | 256 | id = GNUNET_ntohll(res->arm_msg.request_id); |
259 | op = find_op_by_id (h, id); | 257 | op = find_op_by_id(h, id); |
260 | if (NULL == op) | 258 | if (NULL == op) |
261 | { | 259 | { |
262 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 260 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
263 | "Message with unknown id %llu\n", | 261 | "Message with unknown id %llu\n", |
264 | (unsigned long long) id); | 262 | (unsigned long long)id); |
265 | return; | 263 | return; |
266 | } | 264 | } |
267 | 265 | ||
268 | result = (enum GNUNET_ARM_Result) ntohl (res->result); | 266 | result = (enum GNUNET_ARM_Result)ntohl(res->result); |
269 | if ((GNUNET_YES == op->is_arm_stop) && (GNUNET_ARM_RESULT_STOPPING == result)) | 267 | if ((GNUNET_YES == op->is_arm_stop) && (GNUNET_ARM_RESULT_STOPPING == result)) |
270 | { | ||
271 | /* special case: if we are stopping 'gnunet-service-arm', we do not just | ||
272 | wait for the result message, but also wait for the service to close | ||
273 | the connection (and then we have to close our client handle as well); | ||
274 | this is done by installing a different receive handler, waiting for | ||
275 | the connection to go down */ | ||
276 | if (NULL != h->thm) | ||
277 | { | 268 | { |
278 | GNUNET_break (0); | 269 | /* special case: if we are stopping 'gnunet-service-arm', we do not just |
279 | op->result_cont (h->thm->cont_cls, | 270 | wait for the result message, but also wait for the service to close |
280 | GNUNET_ARM_REQUEST_SENT_OK, | 271 | the connection (and then we have to close our client handle as well); |
281 | GNUNET_ARM_RESULT_IS_NOT_KNOWN); | 272 | this is done by installing a different receive handler, waiting for |
282 | GNUNET_free (h->thm); | 273 | the connection to go down */ |
274 | if (NULL != h->thm) | ||
275 | { | ||
276 | GNUNET_break(0); | ||
277 | op->result_cont(h->thm->cont_cls, | ||
278 | GNUNET_ARM_REQUEST_SENT_OK, | ||
279 | GNUNET_ARM_RESULT_IS_NOT_KNOWN); | ||
280 | GNUNET_free(h->thm); | ||
281 | } | ||
282 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, | ||
283 | h->operation_pending_tail, | ||
284 | op); | ||
285 | h->thm = op; | ||
286 | return; | ||
283 | } | 287 | } |
284 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | ||
285 | h->operation_pending_tail, | ||
286 | op); | ||
287 | h->thm = op; | ||
288 | return; | ||
289 | } | ||
290 | result_cont = op->result_cont; | 288 | result_cont = op->result_cont; |
291 | result_cont_cls = op->cont_cls; | 289 | result_cont_cls = op->cont_cls; |
292 | GNUNET_ARM_operation_cancel (op); | 290 | GNUNET_ARM_operation_cancel(op); |
293 | if (NULL != result_cont) | 291 | if (NULL != result_cont) |
294 | result_cont (result_cont_cls, GNUNET_ARM_REQUEST_SENT_OK, result); | 292 | result_cont(result_cont_cls, GNUNET_ARM_REQUEST_SENT_OK, result); |
295 | } | 293 | } |
296 | 294 | ||
297 | 295 | ||
@@ -303,27 +301,27 @@ handle_arm_result (void *cls, const struct GNUNET_ARM_ResultMessage *res) | |||
303 | * @return #GNUNET_OK if message is well-formed | 301 | * @return #GNUNET_OK if message is well-formed |
304 | */ | 302 | */ |
305 | static int | 303 | static int |
306 | check_arm_list_result (void *cls, | 304 | check_arm_list_result(void *cls, |
307 | const struct GNUNET_ARM_ListResultMessage *lres) | 305 | const struct GNUNET_ARM_ListResultMessage *lres) |
308 | { | 306 | { |
309 | const char *pos = (const char *) &lres[1]; | 307 | const char *pos = (const char *)&lres[1]; |
310 | uint16_t rcount = ntohs (lres->count); | 308 | uint16_t rcount = ntohs(lres->count); |
311 | uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof (*lres); | 309 | uint16_t msize = ntohs(lres->arm_msg.header.size) - sizeof(*lres); |
312 | uint16_t size_check; | 310 | uint16_t size_check; |
313 | 311 | ||
314 | (void) cls; | 312 | (void)cls; |
315 | size_check = 0; | 313 | size_check = 0; |
316 | for (unsigned int i = 0; i < rcount; i++) | 314 | for (unsigned int i = 0; i < rcount; i++) |
317 | { | ||
318 | const char *end = memchr (pos, 0, msize - size_check); | ||
319 | if (NULL == end) | ||
320 | { | 315 | { |
321 | GNUNET_break (0); | 316 | const char *end = memchr(pos, 0, msize - size_check); |
322 | return GNUNET_SYSERR; | 317 | if (NULL == end) |
318 | { | ||
319 | GNUNET_break(0); | ||
320 | return GNUNET_SYSERR; | ||
321 | } | ||
322 | size_check += (end - pos) + 1; | ||
323 | pos = end + 1; | ||
323 | } | 324 | } |
324 | size_check += (end - pos) + 1; | ||
325 | pos = end + 1; | ||
326 | } | ||
327 | return GNUNET_OK; | 325 | return GNUNET_OK; |
328 | } | 326 | } |
329 | 327 | ||
@@ -335,41 +333,41 @@ check_arm_list_result (void *cls, | |||
335 | * @param lres the message received from the arm service | 333 | * @param lres the message received from the arm service |
336 | */ | 334 | */ |
337 | static void | 335 | static void |
338 | handle_arm_list_result (void *cls, | 336 | handle_arm_list_result(void *cls, |
339 | const struct GNUNET_ARM_ListResultMessage *lres) | 337 | const struct GNUNET_ARM_ListResultMessage *lres) |
340 | { | 338 | { |
341 | struct GNUNET_ARM_Handle *h = cls; | 339 | struct GNUNET_ARM_Handle *h = cls; |
342 | uint16_t rcount = ntohs (lres->count); | 340 | uint16_t rcount = ntohs(lres->count); |
343 | const char *list[rcount]; | 341 | const char *list[rcount]; |
344 | const char *pos = (const char *) &lres[1]; | 342 | const char *pos = (const char *)&lres[1]; |
345 | uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof (*lres); | 343 | uint16_t msize = ntohs(lres->arm_msg.header.size) - sizeof(*lres); |
346 | struct GNUNET_ARM_Operation *op; | 344 | struct GNUNET_ARM_Operation *op; |
347 | uint16_t size_check; | 345 | uint16_t size_check; |
348 | uint64_t id; | 346 | uint64_t id; |
349 | 347 | ||
350 | id = GNUNET_ntohll (lres->arm_msg.request_id); | 348 | id = GNUNET_ntohll(lres->arm_msg.request_id); |
351 | op = find_op_by_id (h, id); | 349 | op = find_op_by_id(h, id); |
352 | if (NULL == op) | 350 | if (NULL == op) |
353 | { | 351 | { |
354 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 352 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
355 | "Message with unknown id %llu\n", | 353 | "Message with unknown id %llu\n", |
356 | (unsigned long long) id); | 354 | (unsigned long long)id); |
357 | return; | 355 | return; |
358 | } | 356 | } |
359 | size_check = 0; | 357 | size_check = 0; |
360 | for (unsigned int i = 0; i < rcount; i++) | 358 | for (unsigned int i = 0; i < rcount; i++) |
361 | { | 359 | { |
362 | const char *end = memchr (pos, 0, msize - size_check); | 360 | const char *end = memchr(pos, 0, msize - size_check); |
363 | 361 | ||
364 | /* Assert, as this was already checked in #check_arm_list_result() */ | 362 | /* Assert, as this was already checked in #check_arm_list_result() */ |
365 | GNUNET_assert (NULL != end); | 363 | GNUNET_assert(NULL != end); |
366 | list[i] = pos; | 364 | list[i] = pos; |
367 | size_check += (end - pos) + 1; | 365 | size_check += (end - pos) + 1; |
368 | pos = end + 1; | 366 | pos = end + 1; |
369 | } | 367 | } |
370 | if (NULL != op->list_cont) | 368 | if (NULL != op->list_cont) |
371 | op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount, list); | 369 | op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount, list); |
372 | GNUNET_ARM_operation_cancel (op); | 370 | GNUNET_ARM_operation_cancel(op); |
373 | } | 371 | } |
374 | 372 | ||
375 | 373 | ||
@@ -380,18 +378,18 @@ handle_arm_list_result (void *cls, | |||
380 | * @param msg message received | 378 | * @param msg message received |
381 | */ | 379 | */ |
382 | static void | 380 | static void |
383 | handle_confirm (void *cls, const struct GNUNET_MessageHeader *msg) | 381 | handle_confirm(void *cls, const struct GNUNET_MessageHeader *msg) |
384 | { | 382 | { |
385 | struct GNUNET_ARM_Handle *h = cls; | 383 | struct GNUNET_ARM_Handle *h = cls; |
386 | 384 | ||
387 | (void) msg; | 385 | (void)msg; |
388 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Got confirmation from ARM that we are up!\n"); | 386 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Got confirmation from ARM that we are up!\n"); |
389 | if (GNUNET_NO == h->currently_up) | 387 | if (GNUNET_NO == h->currently_up) |
390 | { | 388 | { |
391 | h->currently_up = GNUNET_YES; | 389 | h->currently_up = GNUNET_YES; |
392 | if (NULL != h->conn_status) | 390 | if (NULL != h->conn_status) |
393 | h->conn_status (h->conn_status_cls, GNUNET_YES); | 391 | h->conn_status(h->conn_status_cls, GNUNET_YES); |
394 | } | 392 | } |
395 | } | 393 | } |
396 | 394 | ||
397 | 395 | ||
@@ -404,22 +402,22 @@ handle_confirm (void *cls, const struct GNUNET_MessageHeader *msg) | |||
404 | * @param error error code | 402 | * @param error error code |
405 | */ | 403 | */ |
406 | static void | 404 | static void |
407 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 405 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
408 | { | 406 | { |
409 | struct GNUNET_ARM_Handle *h = cls; | 407 | struct GNUNET_ARM_Handle *h = cls; |
410 | struct GNUNET_ARM_Operation *op; | 408 | struct GNUNET_ARM_Operation *op; |
411 | 409 | ||
412 | (void) error; | 410 | (void)error; |
413 | h->currently_up = GNUNET_NO; | 411 | h->currently_up = GNUNET_NO; |
414 | if (NULL != (op = h->thm)) | 412 | if (NULL != (op = h->thm)) |
415 | { | 413 | { |
416 | h->thm = NULL; | 414 | h->thm = NULL; |
417 | op->result_cont (op->cont_cls, | 415 | op->result_cont(op->cont_cls, |
418 | GNUNET_ARM_REQUEST_SENT_OK, | 416 | GNUNET_ARM_REQUEST_SENT_OK, |
419 | GNUNET_ARM_RESULT_STOPPED); | 417 | GNUNET_ARM_RESULT_STOPPED); |
420 | GNUNET_free (op); | 418 | GNUNET_free(op); |
421 | } | 419 | } |
422 | reconnect_arm_later (h); | 420 | reconnect_arm_later(h); |
423 | } | 421 | } |
424 | 422 | ||
425 | 423 | ||
@@ -430,39 +428,39 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
430 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 428 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
431 | */ | 429 | */ |
432 | static int | 430 | static int |
433 | reconnect_arm (struct GNUNET_ARM_Handle *h) | 431 | reconnect_arm(struct GNUNET_ARM_Handle *h) |
434 | { | 432 | { |
435 | struct GNUNET_MQ_MessageHandler handlers[] = | 433 | struct GNUNET_MQ_MessageHandler handlers[] = |
436 | {GNUNET_MQ_hd_fixed_size (arm_result, | 434 | { GNUNET_MQ_hd_fixed_size(arm_result, |
437 | GNUNET_MESSAGE_TYPE_ARM_RESULT, | 435 | GNUNET_MESSAGE_TYPE_ARM_RESULT, |
438 | struct GNUNET_ARM_ResultMessage, | 436 | struct GNUNET_ARM_ResultMessage, |
439 | h), | 437 | h), |
440 | GNUNET_MQ_hd_var_size (arm_list_result, | 438 | GNUNET_MQ_hd_var_size(arm_list_result, |
441 | GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, | 439 | GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, |
442 | struct GNUNET_ARM_ListResultMessage, | 440 | struct GNUNET_ARM_ListResultMessage, |
441 | h), | ||
442 | GNUNET_MQ_hd_fixed_size(confirm, | ||
443 | GNUNET_MESSAGE_TYPE_ARM_TEST, | ||
444 | struct GNUNET_MessageHeader, | ||
443 | h), | 445 | h), |
444 | GNUNET_MQ_hd_fixed_size (confirm, | 446 | GNUNET_MQ_handler_end() }; |
445 | GNUNET_MESSAGE_TYPE_ARM_TEST, | ||
446 | struct GNUNET_MessageHeader, | ||
447 | h), | ||
448 | GNUNET_MQ_handler_end ()}; | ||
449 | struct GNUNET_MessageHeader *test; | 447 | struct GNUNET_MessageHeader *test; |
450 | struct GNUNET_MQ_Envelope *env; | 448 | struct GNUNET_MQ_Envelope *env; |
451 | 449 | ||
452 | if (NULL != h->mq) | 450 | if (NULL != h->mq) |
453 | return GNUNET_OK; | 451 | return GNUNET_OK; |
454 | GNUNET_assert (GNUNET_NO == h->currently_up); | 452 | GNUNET_assert(GNUNET_NO == h->currently_up); |
455 | h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h); | 453 | h->mq = GNUNET_CLIENT_connect(h->cfg, "arm", handlers, &mq_error_handler, h); |
456 | if (NULL == h->mq) | 454 | if (NULL == h->mq) |
457 | { | 455 | { |
458 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CLIENT_connect returned NULL\n"); | 456 | LOG(GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CLIENT_connect returned NULL\n"); |
459 | if (NULL != h->conn_status) | 457 | if (NULL != h->conn_status) |
460 | h->conn_status (h->conn_status_cls, GNUNET_SYSERR); | 458 | h->conn_status(h->conn_status_cls, GNUNET_SYSERR); |
461 | return GNUNET_SYSERR; | 459 | return GNUNET_SYSERR; |
462 | } | 460 | } |
463 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending TEST message to ARM\n"); | 461 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending TEST message to ARM\n"); |
464 | env = GNUNET_MQ_msg (test, GNUNET_MESSAGE_TYPE_ARM_TEST); | 462 | env = GNUNET_MQ_msg(test, GNUNET_MESSAGE_TYPE_ARM_TEST); |
465 | GNUNET_MQ_send (h->mq, env); | 463 | GNUNET_MQ_send(h->mq, env); |
466 | return GNUNET_OK; | 464 | return GNUNET_OK; |
467 | } | 465 | } |
468 | 466 | ||
@@ -479,21 +477,21 @@ reconnect_arm (struct GNUNET_ARM_Handle *h) | |||
479 | * @return context to use for further ARM operations, NULL on error. | 477 | * @return context to use for further ARM operations, NULL on error. |
480 | */ | 478 | */ |
481 | struct GNUNET_ARM_Handle * | 479 | struct GNUNET_ARM_Handle * |
482 | GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 480 | GNUNET_ARM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, |
483 | GNUNET_ARM_ConnectionStatusCallback conn_status, | 481 | GNUNET_ARM_ConnectionStatusCallback conn_status, |
484 | void *conn_status_cls) | 482 | void *conn_status_cls) |
485 | { | 483 | { |
486 | struct GNUNET_ARM_Handle *h; | 484 | struct GNUNET_ARM_Handle *h; |
487 | 485 | ||
488 | h = GNUNET_new (struct GNUNET_ARM_Handle); | 486 | h = GNUNET_new(struct GNUNET_ARM_Handle); |
489 | h->cfg = cfg; | 487 | h->cfg = cfg; |
490 | h->conn_status = conn_status; | 488 | h->conn_status = conn_status; |
491 | h->conn_status_cls = conn_status_cls; | 489 | h->conn_status_cls = conn_status_cls; |
492 | if (GNUNET_OK != reconnect_arm (h)) | 490 | if (GNUNET_OK != reconnect_arm(h)) |
493 | { | 491 | { |
494 | GNUNET_free (h); | 492 | GNUNET_free(h); |
495 | return NULL; | 493 | return NULL; |
496 | } | 494 | } |
497 | return h; | 495 | return h; |
498 | } | 496 | } |
499 | 497 | ||
@@ -504,38 +502,38 @@ GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
504 | * @param h the handle that was being used | 502 | * @param h the handle that was being used |
505 | */ | 503 | */ |
506 | void | 504 | void |
507 | GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h) | 505 | GNUNET_ARM_disconnect(struct GNUNET_ARM_Handle *h) |
508 | { | 506 | { |
509 | struct GNUNET_ARM_Operation *op; | 507 | struct GNUNET_ARM_Operation *op; |
510 | 508 | ||
511 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); | 509 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); |
512 | while (NULL != (op = h->operation_pending_head)) | 510 | while (NULL != (op = h->operation_pending_head)) |
513 | { | ||
514 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | ||
515 | h->operation_pending_tail, | ||
516 | op); | ||
517 | if (NULL != op->result_cont) | ||
518 | op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); | ||
519 | if (NULL != op->list_cont) | ||
520 | op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); | ||
521 | if (NULL != op->async) | ||
522 | { | 511 | { |
523 | GNUNET_SCHEDULER_cancel (op->async); | 512 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, |
524 | op->async = NULL; | 513 | h->operation_pending_tail, |
514 | op); | ||
515 | if (NULL != op->result_cont) | ||
516 | op->result_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); | ||
517 | if (NULL != op->list_cont) | ||
518 | op->list_cont(op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); | ||
519 | if (NULL != op->async) | ||
520 | { | ||
521 | GNUNET_SCHEDULER_cancel(op->async); | ||
522 | op->async = NULL; | ||
523 | } | ||
524 | GNUNET_free(op); | ||
525 | } | 525 | } |
526 | GNUNET_free (op); | ||
527 | } | ||
528 | if (NULL != h->mq) | 526 | if (NULL != h->mq) |
529 | { | 527 | { |
530 | GNUNET_MQ_destroy (h->mq); | 528 | GNUNET_MQ_destroy(h->mq); |
531 | h->mq = NULL; | 529 | h->mq = NULL; |
532 | } | 530 | } |
533 | if (NULL != h->reconnect_task) | 531 | if (NULL != h->reconnect_task) |
534 | { | 532 | { |
535 | GNUNET_SCHEDULER_cancel (h->reconnect_task); | 533 | GNUNET_SCHEDULER_cancel(h->reconnect_task); |
536 | h->reconnect_task = NULL; | 534 | h->reconnect_task = NULL; |
537 | } | 535 | } |
538 | GNUNET_free (h); | 536 | GNUNET_free(h); |
539 | } | 537 | } |
540 | 538 | ||
541 | 539 | ||
@@ -548,8 +546,8 @@ GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h) | |||
548 | * @return operation status code | 546 | * @return operation status code |
549 | */ | 547 | */ |
550 | static enum GNUNET_ARM_Result | 548 | static enum GNUNET_ARM_Result |
551 | start_arm_service (struct GNUNET_ARM_Handle *h, | 549 | start_arm_service(struct GNUNET_ARM_Handle *h, |
552 | enum GNUNET_OS_InheritStdioFlags std_inheritance) | 550 | enum GNUNET_OS_InheritStdioFlags std_inheritance) |
553 | { | 551 | { |
554 | struct GNUNET_OS_Process *proc; | 552 | struct GNUNET_OS_Process *proc; |
555 | char *cbinary; | 553 | char *cbinary; |
@@ -559,98 +557,98 @@ start_arm_service (struct GNUNET_ARM_Handle *h, | |||
559 | char *loprefix; | 557 | char *loprefix; |
560 | char *lopostfix; | 558 | char *lopostfix; |
561 | 559 | ||
562 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, | 560 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(h->cfg, |
563 | "arm", | 561 | "arm", |
564 | "PREFIX", | 562 | "PREFIX", |
565 | &loprefix)) | 563 | &loprefix)) |
566 | loprefix = GNUNET_strdup (""); | 564 | loprefix = GNUNET_strdup(""); |
567 | else | 565 | else |
568 | loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, loprefix); | 566 | loprefix = GNUNET_CONFIGURATION_expand_dollar(h->cfg, loprefix); |
569 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, | 567 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(h->cfg, |
570 | "arm", | 568 | "arm", |
571 | "OPTIONS", | 569 | "OPTIONS", |
572 | &lopostfix)) | 570 | &lopostfix)) |
573 | lopostfix = GNUNET_strdup (""); | 571 | lopostfix = GNUNET_strdup(""); |
574 | else | 572 | else |
575 | lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, lopostfix); | 573 | lopostfix = GNUNET_CONFIGURATION_expand_dollar(h->cfg, lopostfix); |
576 | if (GNUNET_OK != | 574 | if (GNUNET_OK != |
577 | GNUNET_CONFIGURATION_get_value_string (h->cfg, "arm", "BINARY", &cbinary)) | 575 | GNUNET_CONFIGURATION_get_value_string(h->cfg, "arm", "BINARY", &cbinary)) |
578 | { | 576 | { |
579 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY"); | 577 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY"); |
580 | GNUNET_free (loprefix); | 578 | GNUNET_free(loprefix); |
581 | GNUNET_free (lopostfix); | 579 | GNUNET_free(lopostfix); |
582 | return GNUNET_ARM_RESULT_IS_NOT_KNOWN; | 580 | return GNUNET_ARM_RESULT_IS_NOT_KNOWN; |
583 | } | 581 | } |
584 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, | 582 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(h->cfg, |
585 | "arm", | 583 | "arm", |
586 | "CONFIG", | 584 | "CONFIG", |
587 | &config)) | 585 | &config)) |
588 | config = NULL; | 586 | config = NULL; |
589 | binary = GNUNET_OS_get_libexec_binary_path (cbinary); | 587 | binary = GNUNET_OS_get_libexec_binary_path(cbinary); |
590 | GNUNET_asprintf ("edbinary, "\"%s\"", binary); | 588 | GNUNET_asprintf("edbinary, "\"%s\"", binary); |
591 | GNUNET_free (cbinary); | 589 | GNUNET_free(cbinary); |
592 | if ((GNUNET_YES == | 590 | if ((GNUNET_YES == |
593 | GNUNET_CONFIGURATION_have_value (h->cfg, "TESTING", "WEAKRANDOM")) && | 591 | GNUNET_CONFIGURATION_have_value(h->cfg, "TESTING", "WEAKRANDOM")) && |
594 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (h->cfg, | 592 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(h->cfg, |
595 | "TESTING", | 593 | "TESTING", |
596 | "WEAKRANDOM")) && | 594 | "WEAKRANDOM")) && |
597 | (GNUNET_NO == | 595 | (GNUNET_NO == |
598 | GNUNET_CONFIGURATION_have_value (h->cfg, "TESTING", "HOSTFILE"))) | 596 | GNUNET_CONFIGURATION_have_value(h->cfg, "TESTING", "HOSTFILE"))) |
599 | { | 597 | { |
600 | /* Means we are ONLY running locally */ | 598 | /* Means we are ONLY running locally */ |
601 | /* we're clearly running a test, don't daemonize */ | 599 | /* we're clearly running a test, don't daemonize */ |
602 | if (NULL == config) | 600 | if (NULL == config) |
603 | proc = GNUNET_OS_start_process_s (GNUNET_NO, | 601 | proc = GNUNET_OS_start_process_s(GNUNET_NO, |
604 | std_inheritance, | 602 | std_inheritance, |
605 | NULL, | 603 | NULL, |
606 | loprefix, | 604 | loprefix, |
607 | quotedbinary, | 605 | quotedbinary, |
608 | /* no daemonization! */ | 606 | /* no daemonization! */ |
609 | lopostfix, | 607 | lopostfix, |
610 | NULL); | 608 | NULL); |
611 | else | 609 | else |
612 | proc = GNUNET_OS_start_process_s (GNUNET_NO, | 610 | proc = GNUNET_OS_start_process_s(GNUNET_NO, |
613 | std_inheritance, | 611 | std_inheritance, |
614 | NULL, | 612 | NULL, |
615 | loprefix, | 613 | loprefix, |
616 | quotedbinary, | 614 | quotedbinary, |
617 | "-c", | 615 | "-c", |
618 | config, | 616 | config, |
619 | /* no daemonization! */ | 617 | /* no daemonization! */ |
620 | lopostfix, | 618 | lopostfix, |
621 | NULL); | 619 | NULL); |
622 | } | 620 | } |
623 | else | 621 | else |
624 | { | 622 | { |
625 | if (NULL == config) | 623 | if (NULL == config) |
626 | proc = GNUNET_OS_start_process_s (GNUNET_NO, | 624 | proc = GNUNET_OS_start_process_s(GNUNET_NO, |
627 | std_inheritance, | 625 | std_inheritance, |
628 | NULL, | 626 | NULL, |
629 | loprefix, | 627 | loprefix, |
630 | quotedbinary, | 628 | quotedbinary, |
631 | "-d", /* do daemonize */ | 629 | "-d", /* do daemonize */ |
632 | lopostfix, | 630 | lopostfix, |
633 | NULL); | 631 | NULL); |
634 | else | 632 | else |
635 | proc = GNUNET_OS_start_process_s (GNUNET_NO, | 633 | proc = GNUNET_OS_start_process_s(GNUNET_NO, |
636 | std_inheritance, | 634 | std_inheritance, |
637 | NULL, | 635 | NULL, |
638 | loprefix, | 636 | loprefix, |
639 | quotedbinary, | 637 | quotedbinary, |
640 | "-c", | 638 | "-c", |
641 | config, | 639 | config, |
642 | "-d", /* do daemonize */ | 640 | "-d", /* do daemonize */ |
643 | lopostfix, | 641 | lopostfix, |
644 | NULL); | 642 | NULL); |
645 | } | 643 | } |
646 | GNUNET_free (binary); | 644 | GNUNET_free(binary); |
647 | GNUNET_free (quotedbinary); | 645 | GNUNET_free(quotedbinary); |
648 | GNUNET_free_non_null (config); | 646 | GNUNET_free_non_null(config); |
649 | GNUNET_free (loprefix); | 647 | GNUNET_free(loprefix); |
650 | GNUNET_free (lopostfix); | 648 | GNUNET_free(lopostfix); |
651 | if (NULL == proc) | 649 | if (NULL == proc) |
652 | return GNUNET_ARM_RESULT_START_FAILED; | 650 | return GNUNET_ARM_RESULT_START_FAILED; |
653 | GNUNET_OS_process_destroy (proc); | 651 | GNUNET_OS_process_destroy(proc); |
654 | return GNUNET_ARM_RESULT_STARTING; | 652 | return GNUNET_ARM_RESULT_STARTING; |
655 | } | 653 | } |
656 | 654 | ||
@@ -662,19 +660,19 @@ start_arm_service (struct GNUNET_ARM_Handle *h, | |||
662 | * @param op operation to cancel | 660 | * @param op operation to cancel |
663 | */ | 661 | */ |
664 | void | 662 | void |
665 | GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op) | 663 | GNUNET_ARM_operation_cancel(struct GNUNET_ARM_Operation *op) |
666 | { | 664 | { |
667 | struct GNUNET_ARM_Handle *h = op->h; | 665 | struct GNUNET_ARM_Handle *h = op->h; |
668 | 666 | ||
669 | if (h->thm == op) | 667 | if (h->thm == op) |
670 | { | 668 | { |
671 | op->result_cont = NULL; | 669 | op->result_cont = NULL; |
672 | return; | 670 | return; |
673 | } | 671 | } |
674 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | 672 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, |
675 | h->operation_pending_tail, | 673 | h->operation_pending_tail, |
676 | op); | 674 | op); |
677 | GNUNET_free (op); | 675 | GNUNET_free(op); |
678 | } | 676 | } |
679 | 677 | ||
680 | 678 | ||
@@ -689,38 +687,38 @@ GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op) | |||
689 | * @return handle to queue, NULL on error | 687 | * @return handle to queue, NULL on error |
690 | */ | 688 | */ |
691 | static struct GNUNET_ARM_Operation * | 689 | static struct GNUNET_ARM_Operation * |
692 | change_service (struct GNUNET_ARM_Handle *h, | 690 | change_service(struct GNUNET_ARM_Handle *h, |
693 | const char *service_name, | 691 | const char *service_name, |
694 | GNUNET_ARM_ResultCallback cb, | 692 | GNUNET_ARM_ResultCallback cb, |
695 | void *cb_cls, | 693 | void *cb_cls, |
696 | uint16_t type) | 694 | uint16_t type) |
697 | { | 695 | { |
698 | struct GNUNET_ARM_Operation *op; | 696 | struct GNUNET_ARM_Operation *op; |
699 | size_t slen; | 697 | size_t slen; |
700 | struct GNUNET_MQ_Envelope *env; | 698 | struct GNUNET_MQ_Envelope *env; |
701 | struct GNUNET_ARM_Message *msg; | 699 | struct GNUNET_ARM_Message *msg; |
702 | 700 | ||
703 | slen = strlen (service_name) + 1; | 701 | slen = strlen(service_name) + 1; |
704 | if (slen + sizeof (struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE) | 702 | if (slen + sizeof(struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE) |
705 | { | 703 | { |
706 | GNUNET_break (0); | 704 | GNUNET_break(0); |
707 | return NULL; | 705 | return NULL; |
708 | } | 706 | } |
709 | if (0 == h->request_id_counter) | 707 | if (0 == h->request_id_counter) |
710 | h->request_id_counter++; | 708 | h->request_id_counter++; |
711 | op = GNUNET_new (struct GNUNET_ARM_Operation); | 709 | op = GNUNET_new(struct GNUNET_ARM_Operation); |
712 | op->h = h; | 710 | op->h = h; |
713 | op->result_cont = cb; | 711 | op->result_cont = cb; |
714 | op->cont_cls = cb_cls; | 712 | op->cont_cls = cb_cls; |
715 | op->id = h->request_id_counter++; | 713 | op->id = h->request_id_counter++; |
716 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, | 714 | GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, |
717 | h->operation_pending_tail, | 715 | h->operation_pending_tail, |
718 | op); | 716 | op); |
719 | env = GNUNET_MQ_msg_extra (msg, slen, type); | 717 | env = GNUNET_MQ_msg_extra(msg, slen, type); |
720 | msg->reserved = htonl (0); | 718 | msg->reserved = htonl(0); |
721 | msg->request_id = GNUNET_htonll (op->id); | 719 | msg->request_id = GNUNET_htonll(op->id); |
722 | GNUNET_memcpy (&msg[1], service_name, slen); | 720 | GNUNET_memcpy(&msg[1], service_name, slen); |
723 | GNUNET_MQ_send (h->mq, env); | 721 | GNUNET_MQ_send(h->mq, env); |
724 | return op; | 722 | return op; |
725 | } | 723 | } |
726 | 724 | ||
@@ -731,22 +729,22 @@ change_service (struct GNUNET_ARM_Handle *h, | |||
731 | * @param cls the operation that asked ARM to be started | 729 | * @param cls the operation that asked ARM to be started |
732 | */ | 730 | */ |
733 | static void | 731 | static void |
734 | notify_running (void *cls) | 732 | notify_running(void *cls) |
735 | { | 733 | { |
736 | struct GNUNET_ARM_Operation *op = cls; | 734 | struct GNUNET_ARM_Operation *op = cls; |
737 | struct GNUNET_ARM_Handle *h = op->h; | 735 | struct GNUNET_ARM_Handle *h = op->h; |
738 | 736 | ||
739 | op->async = NULL; | 737 | op->async = NULL; |
740 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | 738 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, |
741 | h->operation_pending_tail, | 739 | h->operation_pending_tail, |
742 | op); | 740 | op); |
743 | if (NULL != op->result_cont) | 741 | if (NULL != op->result_cont) |
744 | op->result_cont (op->cont_cls, | 742 | op->result_cont(op->cont_cls, |
745 | GNUNET_ARM_REQUEST_SENT_OK, | 743 | GNUNET_ARM_REQUEST_SENT_OK, |
746 | GNUNET_ARM_RESULT_IS_STARTED_ALREADY); | 744 | GNUNET_ARM_RESULT_IS_STARTED_ALREADY); |
747 | if ((GNUNET_YES == h->currently_up) && (NULL != h->conn_status)) | 745 | if ((GNUNET_YES == h->currently_up) && (NULL != h->conn_status)) |
748 | h->conn_status (h->conn_status_cls, GNUNET_YES); | 746 | h->conn_status(h->conn_status_cls, GNUNET_YES); |
749 | GNUNET_free (op); | 747 | GNUNET_free(op); |
750 | } | 748 | } |
751 | 749 | ||
752 | 750 | ||
@@ -756,22 +754,22 @@ notify_running (void *cls) | |||
756 | * @param cls the operation that asked ARM to be started | 754 | * @param cls the operation that asked ARM to be started |
757 | */ | 755 | */ |
758 | static void | 756 | static void |
759 | notify_starting (void *cls) | 757 | notify_starting(void *cls) |
760 | { | 758 | { |
761 | struct GNUNET_ARM_Operation *op = cls; | 759 | struct GNUNET_ARM_Operation *op = cls; |
762 | struct GNUNET_ARM_Handle *h = op->h; | 760 | struct GNUNET_ARM_Handle *h = op->h; |
763 | 761 | ||
764 | op->async = NULL; | 762 | op->async = NULL; |
765 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 763 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
766 | "Notifying client that we started the ARM service\n"); | 764 | "Notifying client that we started the ARM service\n"); |
767 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | 765 | GNUNET_CONTAINER_DLL_remove(h->operation_pending_head, |
768 | h->operation_pending_tail, | 766 | h->operation_pending_tail, |
769 | op); | 767 | op); |
770 | if (NULL != op->result_cont) | 768 | if (NULL != op->result_cont) |
771 | op->result_cont (op->cont_cls, | 769 | op->result_cont(op->cont_cls, |
772 | GNUNET_ARM_REQUEST_SENT_OK, | 770 | GNUNET_ARM_REQUEST_SENT_OK, |
773 | op->starting_ret); | 771 | op->starting_ret); |
774 | GNUNET_free (op); | 772 | GNUNET_free(op); |
775 | } | 773 | } |
776 | 774 | ||
777 | 775 | ||
@@ -786,7 +784,7 @@ notify_starting (void *cls) | |||
786 | * @return handle for the operation, NULL on error | 784 | * @return handle for the operation, NULL on error |
787 | */ | 785 | */ |
788 | struct GNUNET_ARM_Operation * | 786 | struct GNUNET_ARM_Operation * |
789 | GNUNET_ARM_request_service_start ( | 787 | GNUNET_ARM_request_service_start( |
790 | struct GNUNET_ARM_Handle *h, | 788 | struct GNUNET_ARM_Handle *h, |
791 | const char *service_name, | 789 | const char *service_name, |
792 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | 790 | enum GNUNET_OS_InheritStdioFlags std_inheritance, |
@@ -796,13 +794,13 @@ GNUNET_ARM_request_service_start ( | |||
796 | struct GNUNET_ARM_Operation *op; | 794 | struct GNUNET_ARM_Operation *op; |
797 | enum GNUNET_ARM_Result ret; | 795 | enum GNUNET_ARM_Result ret; |
798 | 796 | ||
799 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting service `%s'\n", service_name); | 797 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Starting service `%s'\n", service_name); |
800 | if (0 != strcasecmp ("arm", service_name)) | 798 | if (0 != strcasecmp("arm", service_name)) |
801 | return change_service (h, | 799 | return change_service(h, |
802 | service_name, | 800 | service_name, |
803 | cont, | 801 | cont, |
804 | cont_cls, | 802 | cont_cls, |
805 | GNUNET_MESSAGE_TYPE_ARM_START); | 803 | GNUNET_MESSAGE_TYPE_ARM_START); |
806 | 804 | ||
807 | /* Possible cases: | 805 | /* Possible cases: |
808 | * 1) We're connected to ARM already. Invoke the callback immediately. | 806 | * 1) We're connected to ARM already. Invoke the callback immediately. |
@@ -811,37 +809,37 @@ GNUNET_ARM_request_service_start ( | |||
811 | * a service test. | 809 | * a service test. |
812 | */ | 810 | */ |
813 | if (GNUNET_YES == h->currently_up) | 811 | if (GNUNET_YES == h->currently_up) |
814 | { | 812 | { |
815 | LOG (GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n"); | 813 | LOG(GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n"); |
816 | op = GNUNET_new (struct GNUNET_ARM_Operation); | 814 | op = GNUNET_new(struct GNUNET_ARM_Operation); |
817 | op->h = h; | 815 | op->h = h; |
818 | op->result_cont = cont; | 816 | op->result_cont = cont; |
819 | op->cont_cls = cont_cls; | 817 | op->cont_cls = cont_cls; |
820 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, | 818 | GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, |
821 | h->operation_pending_tail, | 819 | h->operation_pending_tail, |
822 | op); | 820 | op); |
823 | op->async = GNUNET_SCHEDULER_add_now (¬ify_running, op); | 821 | op->async = GNUNET_SCHEDULER_add_now(¬ify_running, op); |
824 | return op; | 822 | return op; |
825 | } | 823 | } |
826 | /* This is an inherently uncertain choice, as it is of course | 824 | /* This is an inherently uncertain choice, as it is of course |
827 | theoretically possible that ARM is up and we just did not | 825 | theoretically possible that ARM is up and we just did not |
828 | yet complete the MQ handshake. However, given that users | 826 | yet complete the MQ handshake. However, given that users |
829 | are unlikely to hammer 'gnunet-arm -s' on a busy system, | 827 | are unlikely to hammer 'gnunet-arm -s' on a busy system, |
830 | the above check should catch 99.99% of the cases where ARM | 828 | the above check should catch 99.99% of the cases where ARM |
831 | is already running. */ | 829 | is already running. */ |
832 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n"); | 830 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n"); |
833 | ret = start_arm_service (h, std_inheritance); | 831 | ret = start_arm_service(h, std_inheritance); |
834 | if (GNUNET_ARM_RESULT_STARTING == ret) | 832 | if (GNUNET_ARM_RESULT_STARTING == ret) |
835 | reconnect_arm (h); | 833 | reconnect_arm(h); |
836 | op = GNUNET_new (struct GNUNET_ARM_Operation); | 834 | op = GNUNET_new(struct GNUNET_ARM_Operation); |
837 | op->h = h; | 835 | op->h = h; |
838 | op->result_cont = cont; | 836 | op->result_cont = cont; |
839 | op->cont_cls = cont_cls; | 837 | op->cont_cls = cont_cls; |
840 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, | 838 | GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, |
841 | h->operation_pending_tail, | 839 | h->operation_pending_tail, |
842 | op); | 840 | op); |
843 | op->starting_ret = ret; | 841 | op->starting_ret = ret; |
844 | op->async = GNUNET_SCHEDULER_add_now (¬ify_starting, op); | 842 | op->async = GNUNET_SCHEDULER_add_now(¬ify_starting, op); |
845 | return op; | 843 | return op; |
846 | } | 844 | } |
847 | 845 | ||
@@ -861,24 +859,24 @@ GNUNET_ARM_request_service_start ( | |||
861 | * @return handle for the operation, NULL on error | 859 | * @return handle for the operation, NULL on error |
862 | */ | 860 | */ |
863 | struct GNUNET_ARM_Operation * | 861 | struct GNUNET_ARM_Operation * |
864 | GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, | 862 | GNUNET_ARM_request_service_stop(struct GNUNET_ARM_Handle *h, |
865 | const char *service_name, | 863 | const char *service_name, |
866 | GNUNET_ARM_ResultCallback cont, | 864 | GNUNET_ARM_ResultCallback cont, |
867 | void *cont_cls) | 865 | void *cont_cls) |
868 | { | 866 | { |
869 | struct GNUNET_ARM_Operation *op; | 867 | struct GNUNET_ARM_Operation *op; |
870 | 868 | ||
871 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping service `%s'\n", service_name); | 869 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Stopping service `%s'\n", service_name); |
872 | op = change_service (h, | 870 | op = change_service(h, |
873 | service_name, | 871 | service_name, |
874 | cont, | 872 | cont, |
875 | cont_cls, | 873 | cont_cls, |
876 | GNUNET_MESSAGE_TYPE_ARM_STOP); | 874 | GNUNET_MESSAGE_TYPE_ARM_STOP); |
877 | if (NULL == op) | 875 | if (NULL == op) |
878 | return NULL; | 876 | return NULL; |
879 | /* If the service is ARM, set a flag as we will use MQ errors | 877 | /* If the service is ARM, set a flag as we will use MQ errors |
880 | to detect that the process is really gone. */ | 878 | to detect that the process is really gone. */ |
881 | if (0 == strcasecmp (service_name, "arm")) | 879 | if (0 == strcasecmp(service_name, "arm")) |
882 | op->is_arm_stop = GNUNET_YES; | 880 | op->is_arm_stop = GNUNET_YES; |
883 | return op; | 881 | return op; |
884 | } | 882 | } |
@@ -893,29 +891,29 @@ GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, | |||
893 | * @return handle for the operation, NULL on error | 891 | * @return handle for the operation, NULL on error |
894 | */ | 892 | */ |
895 | struct GNUNET_ARM_Operation * | 893 | struct GNUNET_ARM_Operation * |
896 | GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, | 894 | GNUNET_ARM_request_service_list(struct GNUNET_ARM_Handle *h, |
897 | GNUNET_ARM_ServiceListCallback cont, | 895 | GNUNET_ARM_ServiceListCallback cont, |
898 | void *cont_cls) | 896 | void *cont_cls) |
899 | { | 897 | { |
900 | struct GNUNET_ARM_Operation *op; | 898 | struct GNUNET_ARM_Operation *op; |
901 | struct GNUNET_MQ_Envelope *env; | 899 | struct GNUNET_MQ_Envelope *env; |
902 | struct GNUNET_ARM_Message *msg; | 900 | struct GNUNET_ARM_Message *msg; |
903 | 901 | ||
904 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting LIST from ARM service\n"); | 902 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Requesting LIST from ARM service\n"); |
905 | if (0 == h->request_id_counter) | 903 | if (0 == h->request_id_counter) |
906 | h->request_id_counter++; | 904 | h->request_id_counter++; |
907 | op = GNUNET_new (struct GNUNET_ARM_Operation); | 905 | op = GNUNET_new(struct GNUNET_ARM_Operation); |
908 | op->h = h; | 906 | op->h = h; |
909 | op->list_cont = cont; | 907 | op->list_cont = cont; |
910 | op->cont_cls = cont_cls; | 908 | op->cont_cls = cont_cls; |
911 | op->id = h->request_id_counter++; | 909 | op->id = h->request_id_counter++; |
912 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, | 910 | GNUNET_CONTAINER_DLL_insert_tail(h->operation_pending_head, |
913 | h->operation_pending_tail, | 911 | h->operation_pending_tail, |
914 | op); | 912 | op); |
915 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_LIST); | 913 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_LIST); |
916 | msg->reserved = htonl (0); | 914 | msg->reserved = htonl(0); |
917 | msg->request_id = GNUNET_htonll (op->id); | 915 | msg->request_id = GNUNET_htonll(op->id); |
918 | GNUNET_MQ_send (h->mq, env); | 916 | GNUNET_MQ_send(h->mq, env); |
919 | return op; | 917 | return op; |
920 | } | 918 | } |
921 | 919 | ||
diff --git a/src/arm/arm_monitor_api.c b/src/arm/arm_monitor_api.c index 55b12240f..c6e1e2683 100644 --- a/src/arm/arm_monitor_api.c +++ b/src/arm/arm_monitor_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file arm/arm_monitor_api.c | 22 | * @file arm/arm_monitor_api.c |
@@ -30,16 +30,14 @@ | |||
30 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
31 | #include "arm.h" | 31 | #include "arm.h" |
32 | 32 | ||
33 | #define INIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 33 | #define INIT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) |
34 | 34 | ||
35 | #define LOG(kind, ...) GNUNET_log_from (kind, "arm-monitor-api", __VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from(kind, "arm-monitor-api", __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Handle for interacting with ARM. | 38 | * Handle for interacting with ARM. |
39 | */ | 39 | */ |
40 | struct GNUNET_ARM_MonitorHandle | 40 | struct GNUNET_ARM_MonitorHandle { |
41 | { | ||
42 | |||
43 | /** | 41 | /** |
44 | * Our control connection to the ARM service. | 42 | * Our control connection to the ARM service. |
45 | */ | 43 | */ |
@@ -79,7 +77,7 @@ struct GNUNET_ARM_MonitorHandle | |||
79 | * @return #GNUNET_OK on success | 77 | * @return #GNUNET_OK on success |
80 | */ | 78 | */ |
81 | static int | 79 | static int |
82 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h); | 80 | reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h); |
83 | 81 | ||
84 | 82 | ||
85 | /** | 83 | /** |
@@ -88,14 +86,14 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h); | |||
88 | * @param cls the `struct GNUNET_ARM_MonitorHandle` | 86 | * @param cls the `struct GNUNET_ARM_MonitorHandle` |
89 | */ | 87 | */ |
90 | static void | 88 | static void |
91 | reconnect_arm_monitor_task (void *cls) | 89 | reconnect_arm_monitor_task(void *cls) |
92 | { | 90 | { |
93 | struct GNUNET_ARM_MonitorHandle *h = cls; | 91 | struct GNUNET_ARM_MonitorHandle *h = cls; |
94 | 92 | ||
95 | h->reconnect_task = NULL; | 93 | h->reconnect_task = NULL; |
96 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 94 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
97 | "Connecting to ARM service for monitoring after delay\n"); | 95 | "Connecting to ARM service for monitoring after delay\n"); |
98 | GNUNET_break (GNUNET_OK == reconnect_arm_monitor (h)); | 96 | GNUNET_break(GNUNET_OK == reconnect_arm_monitor(h)); |
99 | } | 97 | } |
100 | 98 | ||
101 | 99 | ||
@@ -106,18 +104,18 @@ reconnect_arm_monitor_task (void *cls) | |||
106 | * @param h our handle | 104 | * @param h our handle |
107 | */ | 105 | */ |
108 | static void | 106 | static void |
109 | reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h) | 107 | reconnect_arm_monitor_later(struct GNUNET_ARM_MonitorHandle *h) |
110 | { | 108 | { |
111 | if (NULL != h->mq) | 109 | if (NULL != h->mq) |
112 | { | 110 | { |
113 | GNUNET_MQ_destroy (h->mq); | 111 | GNUNET_MQ_destroy(h->mq); |
114 | h->mq = NULL; | 112 | h->mq = NULL; |
115 | } | 113 | } |
116 | GNUNET_assert (NULL == h->reconnect_task); | 114 | GNUNET_assert(NULL == h->reconnect_task); |
117 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, | 115 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed(h->retry_backoff, |
118 | &reconnect_arm_monitor_task, | 116 | &reconnect_arm_monitor_task, |
119 | h); | 117 | h); |
120 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); | 118 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF(h->retry_backoff); |
121 | } | 119 | } |
122 | 120 | ||
123 | 121 | ||
@@ -129,18 +127,18 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h) | |||
129 | * @return #GNUNET_OK if the message is well-formed | 127 | * @return #GNUNET_OK if the message is well-formed |
130 | */ | 128 | */ |
131 | static int | 129 | static int |
132 | check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg) | 130 | check_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *msg) |
133 | { | 131 | { |
134 | size_t sl = | 132 | size_t sl = |
135 | ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage); | 133 | ntohs(msg->header.size) - sizeof(struct GNUNET_ARM_StatusMessage); |
136 | const char *name = (const char *) &msg[1]; | 134 | const char *name = (const char *)&msg[1]; |
137 | 135 | ||
138 | (void) cls; | 136 | (void)cls; |
139 | if ((0 == sl) || ('\0' != name[sl - 1])) | 137 | if ((0 == sl) || ('\0' != name[sl - 1])) |
140 | { | 138 | { |
141 | GNUNET_break (0); | 139 | GNUNET_break(0); |
142 | return GNUNET_SYSERR; | 140 | return GNUNET_SYSERR; |
143 | } | 141 | } |
144 | return GNUNET_OK; | 142 | return GNUNET_OK; |
145 | } | 143 | } |
146 | 144 | ||
@@ -152,18 +150,18 @@ check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg) | |||
152 | * @param res the message received from the arm service | 150 | * @param res the message received from the arm service |
153 | */ | 151 | */ |
154 | static void | 152 | static void |
155 | handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res) | 153 | handle_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *res) |
156 | { | 154 | { |
157 | struct GNUNET_ARM_MonitorHandle *h = cls; | 155 | struct GNUNET_ARM_MonitorHandle *h = cls; |
158 | enum GNUNET_ARM_ServiceStatus status; | 156 | enum GNUNET_ARM_ServiceStatus status; |
159 | 157 | ||
160 | status = (enum GNUNET_ARM_ServiceStatus) ntohl (res->status); | 158 | status = (enum GNUNET_ARM_ServiceStatus)ntohl(res->status); |
161 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 159 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
162 | "Received notification from ARM for service `%s' with status %d\n", | 160 | "Received notification from ARM for service `%s' with status %d\n", |
163 | (const char *) &res[1], | 161 | (const char *)&res[1], |
164 | (int) status); | 162 | (int)status); |
165 | if (NULL != h->service_status) | 163 | if (NULL != h->service_status) |
166 | h->service_status (h->service_status_cls, (const char *) &res[1], status); | 164 | h->service_status(h->service_status_cls, (const char *)&res[1], status); |
167 | } | 165 | } |
168 | 166 | ||
169 | 167 | ||
@@ -176,12 +174,12 @@ handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res) | |||
176 | * @param error error code | 174 | * @param error error code |
177 | */ | 175 | */ |
178 | static void | 176 | static void |
179 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 177 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
180 | { | 178 | { |
181 | struct GNUNET_ARM_MonitorHandle *h = cls; | 179 | struct GNUNET_ARM_MonitorHandle *h = cls; |
182 | 180 | ||
183 | (void) error; | 181 | (void)error; |
184 | reconnect_arm_monitor_later (h); | 182 | reconnect_arm_monitor_later(h); |
185 | } | 183 | } |
186 | 184 | ||
187 | 185 | ||
@@ -192,29 +190,29 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
192 | * @return #GNUNET_OK on success | 190 | * @return #GNUNET_OK on success |
193 | */ | 191 | */ |
194 | static int | 192 | static int |
195 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) | 193 | reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h) |
196 | { | 194 | { |
197 | struct GNUNET_MQ_MessageHandler handlers[] = | 195 | struct GNUNET_MQ_MessageHandler handlers[] = |
198 | {GNUNET_MQ_hd_var_size (monitor_notify, | 196 | { GNUNET_MQ_hd_var_size(monitor_notify, |
199 | GNUNET_MESSAGE_TYPE_ARM_STATUS, | 197 | GNUNET_MESSAGE_TYPE_ARM_STATUS, |
200 | struct GNUNET_ARM_StatusMessage, | 198 | struct GNUNET_ARM_StatusMessage, |
201 | h), | 199 | h), |
202 | GNUNET_MQ_handler_end ()}; | 200 | GNUNET_MQ_handler_end() }; |
203 | struct GNUNET_MessageHeader *msg; | 201 | struct GNUNET_MessageHeader *msg; |
204 | struct GNUNET_MQ_Envelope *env; | 202 | struct GNUNET_MQ_Envelope *env; |
205 | 203 | ||
206 | GNUNET_assert (NULL == h->mq); | 204 | GNUNET_assert(NULL == h->mq); |
207 | h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h); | 205 | h->mq = GNUNET_CLIENT_connect(h->cfg, "arm", handlers, &mq_error_handler, h); |
208 | if (NULL == h->mq) | 206 | if (NULL == h->mq) |
209 | { | 207 | { |
210 | if (NULL != h->service_status) | 208 | if (NULL != h->service_status) |
211 | h->service_status (h->service_status_cls, | 209 | h->service_status(h->service_status_cls, |
212 | NULL, | 210 | NULL, |
213 | GNUNET_ARM_SERVICE_STOPPED); | 211 | GNUNET_ARM_SERVICE_STOPPED); |
214 | return GNUNET_SYSERR; | 212 | return GNUNET_SYSERR; |
215 | } | 213 | } |
216 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR); | 214 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR); |
217 | GNUNET_MQ_send (h->mq, env); | 215 | GNUNET_MQ_send(h->mq, env); |
218 | return GNUNET_OK; | 216 | return GNUNET_OK; |
219 | } | 217 | } |
220 | 218 | ||
@@ -231,21 +229,21 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) | |||
231 | * @return context to use for further ARM monitor operations, NULL on error. | 229 | * @return context to use for further ARM monitor operations, NULL on error. |
232 | */ | 230 | */ |
233 | struct GNUNET_ARM_MonitorHandle * | 231 | struct GNUNET_ARM_MonitorHandle * |
234 | GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 232 | GNUNET_ARM_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, |
235 | GNUNET_ARM_ServiceStatusCallback cont, | 233 | GNUNET_ARM_ServiceStatusCallback cont, |
236 | void *cont_cls) | 234 | void *cont_cls) |
237 | { | 235 | { |
238 | struct GNUNET_ARM_MonitorHandle *h; | 236 | struct GNUNET_ARM_MonitorHandle *h; |
239 | 237 | ||
240 | h = GNUNET_new (struct GNUNET_ARM_MonitorHandle); | 238 | h = GNUNET_new(struct GNUNET_ARM_MonitorHandle); |
241 | h->cfg = cfg; | 239 | h->cfg = cfg; |
242 | h->service_status = cont; | 240 | h->service_status = cont; |
243 | h->service_status_cls = cont_cls; | 241 | h->service_status_cls = cont_cls; |
244 | if (GNUNET_OK != reconnect_arm_monitor (h)) | 242 | if (GNUNET_OK != reconnect_arm_monitor(h)) |
245 | { | 243 | { |
246 | GNUNET_free (h); | 244 | GNUNET_free(h); |
247 | return NULL; | 245 | return NULL; |
248 | } | 246 | } |
249 | return h; | 247 | return h; |
250 | } | 248 | } |
251 | 249 | ||
@@ -256,19 +254,19 @@ GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
256 | * @param h the handle that was being used | 254 | * @param h the handle that was being used |
257 | */ | 255 | */ |
258 | void | 256 | void |
259 | GNUNET_ARM_monitor_stop (struct GNUNET_ARM_MonitorHandle *h) | 257 | GNUNET_ARM_monitor_stop(struct GNUNET_ARM_MonitorHandle *h) |
260 | { | 258 | { |
261 | if (NULL != h->mq) | 259 | if (NULL != h->mq) |
262 | { | 260 | { |
263 | GNUNET_MQ_destroy (h->mq); | 261 | GNUNET_MQ_destroy(h->mq); |
264 | h->mq = NULL; | 262 | h->mq = NULL; |
265 | } | 263 | } |
266 | if (NULL != h->reconnect_task) | 264 | if (NULL != h->reconnect_task) |
267 | { | 265 | { |
268 | GNUNET_SCHEDULER_cancel (h->reconnect_task); | 266 | GNUNET_SCHEDULER_cancel(h->reconnect_task); |
269 | h->reconnect_task = NULL; | 267 | h->reconnect_task = NULL; |
270 | } | 268 | } |
271 | GNUNET_free (h); | 269 | GNUNET_free(h); |
272 | } | 270 | } |
273 | 271 | ||
274 | 272 | ||
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index f96076231..3396a4dbe 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.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 | /** | 21 | /** |
22 | * @file arm/gnunet-arm.c | 22 | * @file arm/gnunet-arm.c |
@@ -144,25 +144,25 @@ static struct GNUNET_ARM_Operation *op; | |||
144 | * were specified when gnunet-arm was run. | 144 | * were specified when gnunet-arm was run. |
145 | */ | 145 | */ |
146 | static void | 146 | static void |
147 | delete_files () | 147 | delete_files() |
148 | { | 148 | { |
149 | GNUNET_log ( | 149 | GNUNET_log( |
150 | GNUNET_ERROR_TYPE_DEBUG, | 150 | GNUNET_ERROR_TYPE_DEBUG, |
151 | "Will attempt to remove configuration file %s and service directory %s\n", | 151 | "Will attempt to remove configuration file %s and service directory %s\n", |
152 | config_file, | 152 | config_file, |
153 | dir); | 153 | dir); |
154 | if (0 != unlink (config_file)) | 154 | if (0 != unlink(config_file)) |
155 | { | 155 | { |
156 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 156 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
157 | _ ("Failed to remove configuration file %s\n"), | 157 | _("Failed to remove configuration file %s\n"), |
158 | config_file); | 158 | config_file); |
159 | } | 159 | } |
160 | if (GNUNET_OK != GNUNET_DISK_directory_remove (dir)) | 160 | if (GNUNET_OK != GNUNET_DISK_directory_remove(dir)) |
161 | { | 161 | { |
162 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 162 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
163 | _ ("Failed to remove servicehome directory %s\n"), | 163 | _("Failed to remove servicehome directory %s\n"), |
164 | dir); | 164 | dir); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
@@ -173,37 +173,37 @@ delete_files () | |||
173 | * @param cls closure, unused | 173 | * @param cls closure, unused |
174 | */ | 174 | */ |
175 | static void | 175 | static void |
176 | shutdown_task (void *cls) | 176 | shutdown_task(void *cls) |
177 | { | 177 | { |
178 | (void) cls; | 178 | (void)cls; |
179 | if (NULL != al_task) | 179 | if (NULL != al_task) |
180 | { | 180 | { |
181 | GNUNET_SCHEDULER_cancel (al_task); | 181 | GNUNET_SCHEDULER_cancel(al_task); |
182 | al_task = NULL; | 182 | al_task = NULL; |
183 | } | 183 | } |
184 | if (NULL != op) | 184 | if (NULL != op) |
185 | { | 185 | { |
186 | GNUNET_ARM_operation_cancel (op); | 186 | GNUNET_ARM_operation_cancel(op); |
187 | op = NULL; | 187 | op = NULL; |
188 | } | 188 | } |
189 | if (NULL != h) | 189 | if (NULL != h) |
190 | { | 190 | { |
191 | GNUNET_ARM_disconnect (h); | 191 | GNUNET_ARM_disconnect(h); |
192 | h = NULL; | 192 | h = NULL; |
193 | } | 193 | } |
194 | if (NULL != m) | 194 | if (NULL != m) |
195 | { | 195 | { |
196 | GNUNET_ARM_monitor_stop (m); | 196 | GNUNET_ARM_monitor_stop(m); |
197 | m = NULL; | 197 | m = NULL; |
198 | } | 198 | } |
199 | if (NULL != timeout_task) | 199 | if (NULL != timeout_task) |
200 | { | 200 | { |
201 | GNUNET_SCHEDULER_cancel (timeout_task); | 201 | GNUNET_SCHEDULER_cancel(timeout_task); |
202 | timeout_task = NULL; | 202 | timeout_task = NULL; |
203 | } | 203 | } |
204 | if ((GNUNET_YES == end) && (GNUNET_YES == delete)) | 204 | if ((GNUNET_YES == end) && (GNUNET_YES == delete)) |
205 | delete_files (); | 205 | delete_files(); |
206 | GNUNET_CONFIGURATION_destroy (cfg); | 206 | GNUNET_CONFIGURATION_destroy(cfg); |
207 | cfg = NULL; | 207 | cfg = NULL; |
208 | } | 208 | } |
209 | 209 | ||
@@ -215,16 +215,17 @@ shutdown_task (void *cls) | |||
215 | * @return a string interpretation of the request status | 215 | * @return a string interpretation of the request status |
216 | */ | 216 | */ |
217 | static const char * | 217 | static const char * |
218 | req_string (enum GNUNET_ARM_RequestStatus rs) | 218 | req_string(enum GNUNET_ARM_RequestStatus rs) |
219 | { | 219 | { |
220 | switch (rs) | 220 | switch (rs) |
221 | { | 221 | { |
222 | case GNUNET_ARM_REQUEST_SENT_OK: | 222 | case GNUNET_ARM_REQUEST_SENT_OK: |
223 | return _ ("Message was sent successfully"); | 223 | return _("Message was sent successfully"); |
224 | case GNUNET_ARM_REQUEST_DISCONNECTED: | 224 | |
225 | return _ ("We disconnected from ARM before we could send a request"); | 225 | case GNUNET_ARM_REQUEST_DISCONNECTED: |
226 | } | 226 | return _("We disconnected from ARM before we could send a request"); |
227 | return _ ("Unknown request status"); | 227 | } |
228 | return _("Unknown request status"); | ||
228 | } | 229 | } |
229 | 230 | ||
230 | 231 | ||
@@ -235,32 +236,41 @@ req_string (enum GNUNET_ARM_RequestStatus rs) | |||
235 | * @return a string interpretation | 236 | * @return a string interpretation |
236 | */ | 237 | */ |
237 | static const char * | 238 | static const char * |
238 | ret_string (enum GNUNET_ARM_Result result) | 239 | ret_string(enum GNUNET_ARM_Result result) |
239 | { | 240 | { |
240 | switch (result) | 241 | switch (result) |
241 | { | 242 | { |
242 | case GNUNET_ARM_RESULT_STOPPED: | 243 | case GNUNET_ARM_RESULT_STOPPED: |
243 | return _ ("is stopped"); | 244 | return _("is stopped"); |
244 | case GNUNET_ARM_RESULT_STARTING: | 245 | |
245 | return _ ("is starting"); | 246 | case GNUNET_ARM_RESULT_STARTING: |
246 | case GNUNET_ARM_RESULT_STOPPING: | 247 | return _("is starting"); |
247 | return _ ("is stopping"); | 248 | |
248 | case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: | 249 | case GNUNET_ARM_RESULT_STOPPING: |
249 | return _ ("is starting already"); | 250 | return _("is stopping"); |
250 | case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: | 251 | |
251 | return _ ("is stopping already"); | 252 | case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: |
252 | case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: | 253 | return _("is starting already"); |
253 | return _ ("is started already"); | 254 | |
254 | case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: | 255 | case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: |
255 | return _ ("is stopped already"); | 256 | return _("is stopping already"); |
256 | case GNUNET_ARM_RESULT_IS_NOT_KNOWN: | 257 | |
257 | return _ ("service is not known to ARM"); | 258 | case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: |
258 | case GNUNET_ARM_RESULT_START_FAILED: | 259 | return _("is started already"); |
259 | return _ ("service failed to start"); | 260 | |
260 | case GNUNET_ARM_RESULT_IN_SHUTDOWN: | 261 | case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: |
261 | return _ ("service cannot be manipulated because ARM is shutting down"); | 262 | return _("is stopped already"); |
262 | } | 263 | |
263 | return _ ("Unknown result code."); | 264 | case GNUNET_ARM_RESULT_IS_NOT_KNOWN: |
265 | return _("service is not known to ARM"); | ||
266 | |||
267 | case GNUNET_ARM_RESULT_START_FAILED: | ||
268 | return _("service failed to start"); | ||
269 | |||
270 | case GNUNET_ARM_RESULT_IN_SHUTDOWN: | ||
271 | return _("service cannot be manipulated because ARM is shutting down"); | ||
272 | } | ||
273 | return _("Unknown result code."); | ||
264 | } | 274 | } |
265 | 275 | ||
266 | 276 | ||
@@ -270,7 +280,7 @@ ret_string (enum GNUNET_ARM_Result result) | |||
270 | * @param cls closure | 280 | * @param cls closure |
271 | */ | 281 | */ |
272 | static void | 282 | static void |
273 | action_loop (void *cls); | 283 | action_loop(void *cls); |
274 | 284 | ||
275 | 285 | ||
276 | /** | 286 | /** |
@@ -283,18 +293,18 @@ action_loop (void *cls); | |||
283 | * #GNUNET_SYSERR on error. | 293 | * #GNUNET_SYSERR on error. |
284 | */ | 294 | */ |
285 | static void | 295 | static void |
286 | conn_status (void *cls, int connected) | 296 | conn_status(void *cls, int connected) |
287 | { | 297 | { |
288 | static int once; | 298 | static int once; |
289 | 299 | ||
290 | (void) cls; | 300 | (void)cls; |
291 | if ((GNUNET_SYSERR == connected) && (0 == once)) | 301 | if ((GNUNET_SYSERR == connected) && (0 == once)) |
292 | { | 302 | { |
293 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 303 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
294 | _ ("Fatal error initializing ARM API.\n")); | 304 | _("Fatal error initializing ARM API.\n")); |
295 | GNUNET_SCHEDULER_shutdown (); | 305 | GNUNET_SCHEDULER_shutdown(); |
296 | return; | 306 | return; |
297 | } | 307 | } |
298 | once = 1; | 308 | once = 1; |
299 | } | 309 | } |
300 | 310 | ||
@@ -311,32 +321,32 @@ conn_status (void *cls, int connected) | |||
311 | * according to ARM | 321 | * according to ARM |
312 | */ | 322 | */ |
313 | static void | 323 | static void |
314 | start_callback (void *cls, | 324 | start_callback(void *cls, |
315 | enum GNUNET_ARM_RequestStatus rs, | 325 | enum GNUNET_ARM_RequestStatus rs, |
316 | enum GNUNET_ARM_Result result) | 326 | enum GNUNET_ARM_Result result) |
317 | { | 327 | { |
318 | (void) cls; | 328 | (void)cls; |
319 | op = NULL; | 329 | op = NULL; |
320 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 330 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
321 | { | 331 | { |
322 | fprintf (stdout, | 332 | fprintf(stdout, |
323 | _ ("Failed to start the ARM service: %s\n"), | 333 | _("Failed to start the ARM service: %s\n"), |
324 | req_string (rs)); | 334 | req_string(rs)); |
325 | GNUNET_SCHEDULER_shutdown (); | 335 | GNUNET_SCHEDULER_shutdown(); |
326 | return; | 336 | return; |
327 | } | 337 | } |
328 | if ((GNUNET_ARM_RESULT_STARTING != result) && | 338 | if ((GNUNET_ARM_RESULT_STARTING != result) && |
329 | (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) | 339 | (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) |
330 | { | 340 | { |
331 | fprintf (stdout, | 341 | fprintf(stdout, |
332 | _ ("Failed to start the ARM service: %s\n"), | 342 | _("Failed to start the ARM service: %s\n"), |
333 | ret_string (result)); | 343 | ret_string(result)); |
334 | GNUNET_SCHEDULER_shutdown (); | 344 | GNUNET_SCHEDULER_shutdown(); |
335 | return; | 345 | return; |
336 | } | 346 | } |
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM service [re]start successful\n"); | 347 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "ARM service [re]start successful\n"); |
338 | start = 0; | 348 | start = 0; |
339 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); | 349 | al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL); |
340 | } | 350 | } |
341 | 351 | ||
342 | 352 | ||
@@ -352,44 +362,44 @@ start_callback (void *cls, | |||
352 | * according to ARM | 362 | * according to ARM |
353 | */ | 363 | */ |
354 | static void | 364 | static void |
355 | stop_callback (void *cls, | 365 | stop_callback(void *cls, |
356 | enum GNUNET_ARM_RequestStatus rs, | 366 | enum GNUNET_ARM_RequestStatus rs, |
357 | enum GNUNET_ARM_Result result) | 367 | enum GNUNET_ARM_Result result) |
358 | { | 368 | { |
359 | char *msg; | 369 | char *msg; |
360 | 370 | ||
361 | (void) cls; | 371 | (void)cls; |
362 | op = NULL; | 372 | op = NULL; |
363 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 373 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
364 | { | 374 | { |
365 | GNUNET_asprintf (&msg, | 375 | GNUNET_asprintf(&msg, |
366 | "%s", | 376 | "%s", |
367 | _ ( | 377 | _( |
368 | "Failed to send a stop request to the ARM service: %s\n")); | 378 | "Failed to send a stop request to the ARM service: %s\n")); |
369 | fprintf (stdout, msg, req_string (rs)); | 379 | fprintf(stdout, msg, req_string(rs)); |
370 | GNUNET_free (msg); | 380 | GNUNET_free(msg); |
371 | GNUNET_SCHEDULER_shutdown (); | 381 | GNUNET_SCHEDULER_shutdown(); |
372 | return; | 382 | return; |
373 | } | 383 | } |
374 | if ((GNUNET_ARM_RESULT_STOPPING != result) && | 384 | if ((GNUNET_ARM_RESULT_STOPPING != result) && |
375 | (GNUNET_ARM_RESULT_STOPPED != result) && | 385 | (GNUNET_ARM_RESULT_STOPPED != result) && |
376 | (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result)) | 386 | (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result)) |
377 | { | 387 | { |
378 | fprintf (stdout, | 388 | fprintf(stdout, |
379 | _ ("Failed to stop the ARM service: %s\n"), | 389 | _("Failed to stop the ARM service: %s\n"), |
380 | ret_string (result)); | 390 | ret_string(result)); |
381 | GNUNET_SCHEDULER_shutdown (); | 391 | GNUNET_SCHEDULER_shutdown(); |
382 | return; | 392 | return; |
383 | } | 393 | } |
384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM service shutdown successful\n"); | 394 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "ARM service shutdown successful\n"); |
385 | end = 0; | 395 | end = 0; |
386 | if (restart) | 396 | if (restart) |
387 | { | 397 | { |
388 | restart = 0; | 398 | restart = 0; |
389 | start = 1; | 399 | start = 1; |
390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initiating an ARM restart\n"); | 400 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initiating an ARM restart\n"); |
391 | } | 401 | } |
392 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); | 402 | al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL); |
393 | } | 403 | } |
394 | 404 | ||
395 | 405 | ||
@@ -405,37 +415,37 @@ stop_callback (void *cls, | |||
405 | * according to ARM | 415 | * according to ARM |
406 | */ | 416 | */ |
407 | static void | 417 | static void |
408 | init_callback (void *cls, | 418 | init_callback(void *cls, |
409 | enum GNUNET_ARM_RequestStatus rs, | 419 | enum GNUNET_ARM_RequestStatus rs, |
410 | enum GNUNET_ARM_Result result) | 420 | enum GNUNET_ARM_Result result) |
411 | { | 421 | { |
412 | (void) cls; | 422 | (void)cls; |
413 | op = NULL; | 423 | op = NULL; |
414 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 424 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
415 | { | 425 | { |
416 | fprintf (stdout, | 426 | fprintf(stdout, |
417 | _ ("Failed to send a request to start the `%s' service: %s\n"), | 427 | _("Failed to send a request to start the `%s' service: %s\n"), |
418 | init, | 428 | init, |
419 | req_string (rs)); | 429 | req_string(rs)); |
420 | GNUNET_SCHEDULER_shutdown (); | 430 | GNUNET_SCHEDULER_shutdown(); |
421 | return; | 431 | return; |
422 | } | 432 | } |
423 | if ((GNUNET_ARM_RESULT_STARTING != result) && | 433 | if ((GNUNET_ARM_RESULT_STARTING != result) && |
424 | (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) | 434 | (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) |
425 | { | 435 | { |
426 | fprintf (stdout, | 436 | fprintf(stdout, |
427 | _ ("Failed to start the `%s' service: %s\n"), | 437 | _("Failed to start the `%s' service: %s\n"), |
428 | init, | 438 | init, |
429 | ret_string (result)); | 439 | ret_string(result)); |
430 | GNUNET_SCHEDULER_shutdown (); | 440 | GNUNET_SCHEDULER_shutdown(); |
431 | return; | 441 | return; |
432 | } | 442 | } |
433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 443 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
434 | "Service %s [re]started successfully\n", | 444 | "Service %s [re]started successfully\n", |
435 | init); | 445 | init); |
436 | GNUNET_free (init); | 446 | GNUNET_free(init); |
437 | init = NULL; | 447 | init = NULL; |
438 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); | 448 | al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL); |
439 | } | 449 | } |
440 | 450 | ||
441 | 451 | ||
@@ -451,42 +461,42 @@ init_callback (void *cls, | |||
451 | * according to ARM | 461 | * according to ARM |
452 | */ | 462 | */ |
453 | static void | 463 | static void |
454 | term_callback (void *cls, | 464 | term_callback(void *cls, |
455 | enum GNUNET_ARM_RequestStatus rs, | 465 | enum GNUNET_ARM_RequestStatus rs, |
456 | enum GNUNET_ARM_Result result) | 466 | enum GNUNET_ARM_Result result) |
457 | { | 467 | { |
458 | char *msg; | 468 | char *msg; |
459 | 469 | ||
460 | (void) cls; | 470 | (void)cls; |
461 | op = NULL; | 471 | op = NULL; |
462 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 472 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
463 | { | 473 | { |
464 | GNUNET_asprintf (&msg, | 474 | GNUNET_asprintf(&msg, |
465 | _ ( | 475 | _( |
466 | "Failed to send a request to kill the `%s' service: %%s\n"), | 476 | "Failed to send a request to kill the `%s' service: %%s\n"), |
467 | term); | 477 | term); |
468 | fprintf (stdout, msg, req_string (rs)); | 478 | fprintf(stdout, msg, req_string(rs)); |
469 | GNUNET_free (msg); | 479 | GNUNET_free(msg); |
470 | GNUNET_SCHEDULER_shutdown (); | 480 | GNUNET_SCHEDULER_shutdown(); |
471 | return; | 481 | return; |
472 | } | 482 | } |
473 | if ((GNUNET_ARM_RESULT_STOPPED != result) && | 483 | if ((GNUNET_ARM_RESULT_STOPPED != result) && |
474 | (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result)) | 484 | (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result)) |
475 | { | 485 | { |
476 | fprintf (stdout, | 486 | fprintf(stdout, |
477 | _ ("Failed to kill the `%s' service: %s\n"), | 487 | _("Failed to kill the `%s' service: %s\n"), |
478 | term, | 488 | term, |
479 | ret_string (result)); | 489 | ret_string(result)); |
480 | GNUNET_SCHEDULER_shutdown (); | 490 | GNUNET_SCHEDULER_shutdown(); |
481 | return; | 491 | return; |
482 | } | 492 | } |
483 | 493 | ||
484 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 494 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
485 | "Service %s stopped successfully\n", | 495 | "Service %s stopped successfully\n", |
486 | term); | 496 | term); |
487 | GNUNET_free (term); | 497 | GNUNET_free(term); |
488 | term = NULL; | 498 | term = NULL; |
489 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); | 499 | al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL); |
490 | } | 500 | } |
491 | 501 | ||
492 | 502 | ||
@@ -501,39 +511,39 @@ term_callback (void *cls, | |||
501 | * @param list list of services that are running | 511 | * @param list list of services that are running |
502 | */ | 512 | */ |
503 | static void | 513 | static void |
504 | list_callback (void *cls, | 514 | list_callback(void *cls, |
505 | enum GNUNET_ARM_RequestStatus rs, | 515 | enum GNUNET_ARM_RequestStatus rs, |
506 | unsigned int count, | 516 | unsigned int count, |
507 | const char *const *list) | 517 | const char *const *list) |
508 | { | 518 | { |
509 | (void) cls; | 519 | (void)cls; |
510 | op = NULL; | 520 | op = NULL; |
511 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 521 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
512 | { | 522 | { |
513 | char *msg; | 523 | char *msg; |
514 | 524 | ||
515 | GNUNET_asprintf (&msg, | 525 | GNUNET_asprintf(&msg, |
516 | "%s", | 526 | "%s", |
517 | _ ("Failed to request a list of services: %s\n")); | 527 | _("Failed to request a list of services: %s\n")); |
518 | fprintf (stdout, msg, req_string (rs)); | 528 | fprintf(stdout, msg, req_string(rs)); |
519 | GNUNET_free (msg); | 529 | GNUNET_free(msg); |
520 | ret = 3; | 530 | ret = 3; |
521 | GNUNET_SCHEDULER_shutdown (); | 531 | GNUNET_SCHEDULER_shutdown(); |
522 | } | 532 | } |
523 | if (NULL == list) | 533 | if (NULL == list) |
524 | { | 534 | { |
525 | fprintf (stderr, | 535 | fprintf(stderr, |
526 | "%s", | 536 | "%s", |
527 | _ ("Error communicating with ARM. ARM not running?\n")); | 537 | _("Error communicating with ARM. ARM not running?\n")); |
528 | GNUNET_SCHEDULER_shutdown (); | 538 | GNUNET_SCHEDULER_shutdown(); |
529 | ret = 3; | 539 | ret = 3; |
530 | return; | 540 | return; |
531 | } | 541 | } |
532 | if (! quiet) | 542 | if (!quiet) |
533 | fprintf (stdout, "%s", _ ("Running services:\n")); | 543 | fprintf(stdout, "%s", _("Running services:\n")); |
534 | for (unsigned int i = 0; i < count; i++) | 544 | for (unsigned int i = 0; i < count; i++) |
535 | fprintf (stdout, "%s\n", list[i]); | 545 | fprintf(stdout, "%s\n", list[i]); |
536 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); | 546 | al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL); |
537 | } | 547 | } |
538 | 548 | ||
539 | 549 | ||
@@ -544,85 +554,91 @@ list_callback (void *cls, | |||
544 | * @param cls closure, unused | 554 | * @param cls closure, unused |
545 | */ | 555 | */ |
546 | static void | 556 | static void |
547 | action_loop (void *cls) | 557 | action_loop(void *cls) |
548 | { | 558 | { |
549 | (void) cls; | 559 | (void)cls; |
550 | al_task = NULL; | 560 | al_task = NULL; |
551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running requested actions\n"); | 561 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running requested actions\n"); |
552 | while (1) | 562 | while (1) |
553 | { | ||
554 | switch (phase++) | ||
555 | { | 563 | { |
556 | case 0: | 564 | switch (phase++) |
557 | if (NULL != term) | 565 | { |
558 | { | 566 | case 0: |
559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Termination action\n"); | 567 | if (NULL != term) |
560 | op = GNUNET_ARM_request_service_stop (h, term, &term_callback, NULL); | 568 | { |
561 | return; | 569 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Termination action\n"); |
562 | } | 570 | op = GNUNET_ARM_request_service_stop(h, term, &term_callback, NULL); |
563 | break; | 571 | return; |
564 | case 1: | 572 | } |
565 | if (end || restart) | 573 | break; |
566 | { | 574 | |
567 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "End action\n"); | 575 | case 1: |
568 | op = GNUNET_ARM_request_service_stop (h, "arm", &stop_callback, NULL); | 576 | if (end || restart) |
569 | return; | 577 | { |
570 | } | 578 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "End action\n"); |
571 | break; | 579 | op = GNUNET_ARM_request_service_stop(h, "arm", &stop_callback, NULL); |
572 | case 2: | 580 | return; |
573 | if (start) | 581 | } |
574 | { | 582 | break; |
575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start action\n"); | 583 | |
576 | op = | 584 | case 2: |
577 | GNUNET_ARM_request_service_start (h, | 585 | if (start) |
578 | "arm", | 586 | { |
579 | (no_stdout | 587 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Start action\n"); |
580 | ? 0 | 588 | op = |
581 | : GNUNET_OS_INHERIT_STD_OUT) | | 589 | GNUNET_ARM_request_service_start(h, |
582 | (no_stderr | 590 | "arm", |
583 | ? 0 | 591 | (no_stdout |
584 | : GNUNET_OS_INHERIT_STD_ERR), | 592 | ? 0 |
585 | &start_callback, | 593 | : GNUNET_OS_INHERIT_STD_OUT) | |
586 | NULL); | 594 | (no_stderr |
587 | return; | 595 | ? 0 |
588 | } | 596 | : GNUNET_OS_INHERIT_STD_ERR), |
589 | break; | 597 | &start_callback, |
590 | case 3: | 598 | NULL); |
591 | if (NULL != init) | 599 | return; |
592 | { | 600 | } |
593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialization action\n"); | 601 | break; |
594 | op = GNUNET_ARM_request_service_start (h, | 602 | |
595 | init, | 603 | case 3: |
596 | GNUNET_OS_INHERIT_STD_NONE, | 604 | if (NULL != init) |
597 | &init_callback, | 605 | { |
598 | NULL); | 606 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initialization action\n"); |
599 | return; | 607 | op = GNUNET_ARM_request_service_start(h, |
600 | } | 608 | init, |
601 | break; | 609 | GNUNET_OS_INHERIT_STD_NONE, |
602 | case 4: | 610 | &init_callback, |
603 | if (list) | 611 | NULL); |
604 | { | 612 | return; |
605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 613 | } |
606 | "Going to list all running services controlled by ARM.\n"); | 614 | break; |
607 | op = GNUNET_ARM_request_service_list (h, &list_callback, &list); | 615 | |
608 | return; | 616 | case 4: |
609 | } | 617 | if (list) |
610 | break; | 618 | { |
611 | case 5: | 619 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
612 | if (monitor) | 620 | "Going to list all running services controlled by ARM.\n"); |
613 | { | 621 | op = GNUNET_ARM_request_service_list(h, &list_callback, &list); |
614 | if (! quiet) | 622 | return; |
615 | fprintf (stderr, _ ("Now only monitoring, press CTRL-C to stop.\n")); | 623 | } |
616 | quiet = | 624 | break; |
617 | 0; /* does not make sense to stay quiet in monitor mode at this time */ | 625 | |
618 | return; /* done with tasks, just monitor */ | 626 | case 5: |
619 | } | 627 | if (monitor) |
620 | break; | 628 | { |
621 | default: /* last phase */ | 629 | if (!quiet) |
622 | GNUNET_SCHEDULER_shutdown (); | 630 | fprintf(stderr, _("Now only monitoring, press CTRL-C to stop.\n")); |
623 | return; | 631 | quiet = |
632 | 0; /* does not make sense to stay quiet in monitor mode at this time */ | ||
633 | return; /* done with tasks, just monitor */ | ||
634 | } | ||
635 | break; | ||
636 | |||
637 | default: /* last phase */ | ||
638 | GNUNET_SCHEDULER_shutdown(); | ||
639 | return; | ||
640 | } | ||
624 | } | 641 | } |
625 | } | ||
626 | } | 642 | } |
627 | 643 | ||
628 | 644 | ||
@@ -634,44 +650,48 @@ action_loop (void *cls) | |||
634 | * @param status status of the service | 650 | * @param status status of the service |
635 | */ | 651 | */ |
636 | static void | 652 | static void |
637 | srv_status (void *cls, | 653 | srv_status(void *cls, |
638 | const char *service, | 654 | const char *service, |
639 | enum GNUNET_ARM_ServiceStatus status) | 655 | enum GNUNET_ARM_ServiceStatus status) |
640 | { | 656 | { |
641 | const char *msg; | 657 | const char *msg; |
642 | 658 | ||
643 | (void) cls; | 659 | (void)cls; |
644 | switch (status) | 660 | switch (status) |
645 | { | 661 | { |
646 | case GNUNET_ARM_SERVICE_MONITORING_STARTED: | 662 | case GNUNET_ARM_SERVICE_MONITORING_STARTED: |
647 | return; /* this should be done silently */ | 663 | return; /* this should be done silently */ |
648 | case GNUNET_ARM_SERVICE_STOPPED: | 664 | |
649 | msg = _ ("Stopped %s.\n"); | 665 | case GNUNET_ARM_SERVICE_STOPPED: |
650 | break; | 666 | msg = _("Stopped %s.\n"); |
651 | case GNUNET_ARM_SERVICE_STARTING: | 667 | break; |
652 | msg = _ ("Starting %s...\n"); | 668 | |
653 | break; | 669 | case GNUNET_ARM_SERVICE_STARTING: |
654 | case GNUNET_ARM_SERVICE_STOPPING: | 670 | msg = _("Starting %s...\n"); |
655 | msg = _ ("Stopping %s...\n"); | 671 | break; |
656 | break; | 672 | |
657 | default: | 673 | case GNUNET_ARM_SERVICE_STOPPING: |
658 | msg = NULL; | 674 | msg = _("Stopping %s...\n"); |
659 | break; | 675 | break; |
660 | } | 676 | |
661 | if (! quiet) | 677 | default: |
662 | { | 678 | msg = NULL; |
663 | if (NULL != msg) | 679 | break; |
664 | fprintf (stderr, msg, service); | 680 | } |
665 | else | 681 | if (!quiet) |
666 | fprintf (stderr, | 682 | { |
667 | _ ("Unknown status %u for service %s.\n"), | 683 | if (NULL != msg) |
668 | status, | 684 | fprintf(stderr, msg, service); |
669 | service); | 685 | else |
670 | } | 686 | fprintf(stderr, |
671 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 687 | _("Unknown status %u for service %s.\n"), |
672 | "Got service %s status %d\n", | 688 | status, |
673 | service, | 689 | service); |
674 | (int) status); | 690 | } |
691 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
692 | "Got service %s status %d\n", | ||
693 | service, | ||
694 | (int)status); | ||
675 | } | 695 | } |
676 | 696 | ||
677 | 697 | ||
@@ -679,12 +699,12 @@ srv_status (void *cls, | |||
679 | * Task run on timeout (if -T is given). | 699 | * Task run on timeout (if -T is given). |
680 | */ | 700 | */ |
681 | static void | 701 | static void |
682 | timeout_task_cb (void *cls) | 702 | timeout_task_cb(void *cls) |
683 | { | 703 | { |
684 | (void) cls; | 704 | (void)cls; |
685 | timeout_task = NULL; | 705 | timeout_task = NULL; |
686 | ret = 2; | 706 | ret = 2; |
687 | GNUNET_SCHEDULER_shutdown (); | 707 | GNUNET_SCHEDULER_shutdown(); |
688 | } | 708 | } |
689 | 709 | ||
690 | 710 | ||
@@ -697,34 +717,34 @@ timeout_task_cb (void *cls) | |||
697 | * @param c configuration | 717 | * @param c configuration |
698 | */ | 718 | */ |
699 | static void | 719 | static void |
700 | run (void *cls, | 720 | run(void *cls, |
701 | char *const *args, | 721 | char *const *args, |
702 | const char *cfgfile, | 722 | const char *cfgfile, |
703 | const struct GNUNET_CONFIGURATION_Handle *c) | 723 | const struct GNUNET_CONFIGURATION_Handle *c) |
704 | { | 724 | { |
705 | (void) cls; | 725 | (void)cls; |
706 | (void) args; | 726 | (void)args; |
707 | (void) cfgfile; | 727 | (void)cfgfile; |
708 | cfg = GNUNET_CONFIGURATION_dup (c); | 728 | cfg = GNUNET_CONFIGURATION_dup(c); |
709 | if (GNUNET_OK != | 729 | if (GNUNET_OK != |
710 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "GNUNET_HOME", &dir)) | 730 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_HOME", &dir)) |
711 | { | 731 | { |
712 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "PATHS", "GNUNET_HOME"); | 732 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "PATHS", "GNUNET_HOME"); |
713 | return; | 733 | return; |
714 | } | 734 | } |
715 | (void) GNUNET_CONFIGURATION_get_value_filename (cfg, | 735 | (void)GNUNET_CONFIGURATION_get_value_filename(cfg, |
716 | "arm", | 736 | "arm", |
717 | "CONFIG", | 737 | "CONFIG", |
718 | &config_file); | 738 | &config_file); |
719 | if (NULL == (h = GNUNET_ARM_connect (cfg, &conn_status, NULL))) | 739 | if (NULL == (h = GNUNET_ARM_connect(cfg, &conn_status, NULL))) |
720 | return; | 740 | return; |
721 | if (monitor) | 741 | if (monitor) |
722 | m = GNUNET_ARM_monitor_start (cfg, &srv_status, NULL); | 742 | m = GNUNET_ARM_monitor_start(cfg, &srv_status, NULL); |
723 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); | 743 | al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL); |
724 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 744 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
725 | if (0 != timeout.rel_value_us) | 745 | if (0 != timeout.rel_value_us) |
726 | timeout_task = | 746 | timeout_task = |
727 | GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task_cb, NULL); | 747 | GNUNET_SCHEDULER_add_delayed(timeout, &timeout_task_cb, NULL); |
728 | } | 748 | } |
729 | 749 | ||
730 | 750 | ||
@@ -736,88 +756,88 @@ run (void *cls, | |||
736 | * @return 0 ok, 1 on error, 2 on timeout | 756 | * @return 0 ok, 1 on error, 2 on timeout |
737 | */ | 757 | */ |
738 | int | 758 | int |
739 | main (int argc, char *const *argv) | 759 | main(int argc, char *const *argv) |
740 | { | 760 | { |
741 | struct GNUNET_GETOPT_CommandLineOption options[] = | 761 | struct GNUNET_GETOPT_CommandLineOption options[] = |
742 | {GNUNET_GETOPT_option_flag ('e', | 762 | { GNUNET_GETOPT_option_flag('e', |
743 | "end", | 763 | "end", |
744 | gettext_noop ("stop all GNUnet services"), | 764 | gettext_noop("stop all GNUnet services"), |
745 | &end), | 765 | &end), |
746 | GNUNET_GETOPT_option_string ('i', | 766 | GNUNET_GETOPT_option_string('i', |
747 | "init", | 767 | "init", |
748 | "SERVICE", | 768 | "SERVICE", |
749 | gettext_noop ("start a particular service"), | 769 | gettext_noop("start a particular service"), |
750 | &init), | 770 | &init), |
751 | GNUNET_GETOPT_option_string ('k', | 771 | GNUNET_GETOPT_option_string('k', |
752 | "kill", | 772 | "kill", |
753 | "SERVICE", | 773 | "SERVICE", |
754 | gettext_noop ("stop a particular service"), | 774 | gettext_noop("stop a particular service"), |
755 | &term), | 775 | &term), |
756 | GNUNET_GETOPT_option_flag ('s', | 776 | GNUNET_GETOPT_option_flag('s', |
757 | "start", | 777 | "start", |
758 | gettext_noop ( | 778 | gettext_noop( |
759 | "start all GNUnet default services"), | 779 | "start all GNUnet default services"), |
760 | &start), | 780 | &start), |
761 | GNUNET_GETOPT_option_flag ('r', | 781 | GNUNET_GETOPT_option_flag('r', |
762 | "restart", | 782 | "restart", |
763 | gettext_noop ( | 783 | gettext_noop( |
764 | "stop and start all GNUnet default services"), | 784 | "stop and start all GNUnet default services"), |
765 | &restart), | 785 | &restart), |
766 | GNUNET_GETOPT_option_flag ('d', | 786 | GNUNET_GETOPT_option_flag('d', |
767 | "delete", | 787 | "delete", |
768 | gettext_noop ( | 788 | gettext_noop( |
769 | "delete config file and directory on exit"), | 789 | "delete config file and directory on exit"), |
770 | &delete), | 790 | &delete), |
771 | GNUNET_GETOPT_option_flag ('m', | 791 | GNUNET_GETOPT_option_flag('m', |
772 | "monitor", | 792 | "monitor", |
773 | gettext_noop ("monitor ARM activities"), | 793 | gettext_noop("monitor ARM activities"), |
774 | &monitor), | 794 | &monitor), |
775 | GNUNET_GETOPT_option_flag ('q', | 795 | GNUNET_GETOPT_option_flag('q', |
776 | "quiet", | 796 | "quiet", |
777 | gettext_noop ("don't print status messages"), | 797 | gettext_noop("don't print status messages"), |
778 | &quiet), | 798 | &quiet), |
779 | GNUNET_GETOPT_option_relative_time ( | 799 | GNUNET_GETOPT_option_relative_time( |
780 | 'T', | 800 | 'T', |
781 | "timeout", | 801 | "timeout", |
782 | "DELAY", | 802 | "DELAY", |
783 | gettext_noop ( | 803 | gettext_noop( |
784 | "exit with error status if operation does not finish after DELAY"), | 804 | "exit with error status if operation does not finish after DELAY"), |
785 | &timeout), | 805 | &timeout), |
786 | GNUNET_GETOPT_option_flag ('I', | 806 | GNUNET_GETOPT_option_flag('I', |
787 | "info", | 807 | "info", |
788 | gettext_noop ( | 808 | gettext_noop( |
789 | "list currently running services"), | 809 | "list currently running services"), |
790 | &list), | 810 | &list), |
791 | GNUNET_GETOPT_option_flag ( | 811 | GNUNET_GETOPT_option_flag( |
792 | 'O', | 812 | 'O', |
793 | "no-stdout", | 813 | "no-stdout", |
794 | gettext_noop ("don't let gnunet-service-arm inherit standard output"), | 814 | gettext_noop("don't let gnunet-service-arm inherit standard output"), |
795 | &no_stdout), | 815 | &no_stdout), |
796 | GNUNET_GETOPT_option_flag ( | 816 | GNUNET_GETOPT_option_flag( |
797 | 'E', | 817 | 'E', |
798 | "no-stderr", | 818 | "no-stderr", |
799 | gettext_noop ("don't let gnunet-service-arm inherit standard error"), | 819 | gettext_noop("don't let gnunet-service-arm inherit standard error"), |
800 | &no_stderr), | 820 | &no_stderr), |
801 | GNUNET_GETOPT_OPTION_END}; | 821 | GNUNET_GETOPT_OPTION_END }; |
802 | int lret; | 822 | int lret; |
803 | 823 | ||
804 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 824 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
805 | return 2; | 825 | return 2; |
806 | if (GNUNET_OK == | 826 | if (GNUNET_OK == |
807 | (lret = GNUNET_PROGRAM_run ( | 827 | (lret = GNUNET_PROGRAM_run( |
808 | argc, | 828 | argc, |
809 | argv, | 829 | argv, |
810 | "gnunet-arm", | 830 | "gnunet-arm", |
811 | gettext_noop ( | 831 | gettext_noop( |
812 | "Control services and the Automated Restart Manager (ARM)"), | 832 | "Control services and the Automated Restart Manager (ARM)"), |
813 | options, | 833 | options, |
814 | &run, | 834 | &run, |
815 | NULL))) | 835 | NULL))) |
816 | { | 836 | { |
817 | GNUNET_free ((void *) argv); | 837 | GNUNET_free((void *)argv); |
818 | return ret; | 838 | return ret; |
819 | } | 839 | } |
820 | GNUNET_free ((void *) argv); | 840 | GNUNET_free((void *)argv); |
821 | return lret; | 841 | return lret; |
822 | } | 842 | } |
823 | 843 | ||
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index b0f7e07c4..e8c740235 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.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 | /** | 21 | /** |
22 | * @file arm/gnunet-service-arm.c | 22 | * @file arm/gnunet-service-arm.c |
@@ -29,10 +29,10 @@ | |||
29 | #include "gnunet_protocols.h" | 29 | #include "gnunet_protocols.h" |
30 | #include "arm.h" | 30 | #include "arm.h" |
31 | 31 | ||
32 | #define LOG(kind, ...) GNUNET_log_from (kind, "util", __VA_ARGS__) | 32 | #define LOG(kind, ...) GNUNET_log_from(kind, "util", __VA_ARGS__) |
33 | 33 | ||
34 | #define LOG_STRERROR(kind, syscall) \ | 34 | #define LOG_STRERROR(kind, syscall) \ |
35 | GNUNET_log_from_strerror (kind, "util", syscall) | 35 | GNUNET_log_from_strerror(kind, "util", syscall) |
36 | 36 | ||
37 | 37 | ||
38 | #if HAVE_WAIT4 | 38 | #if HAVE_WAIT4 |
@@ -65,8 +65,7 @@ struct ServiceList; | |||
65 | /** | 65 | /** |
66 | * Record with information about a listen socket we have open. | 66 | * Record with information about a listen socket we have open. |
67 | */ | 67 | */ |
68 | struct ServiceListeningInfo | 68 | struct ServiceListeningInfo { |
69 | { | ||
70 | /** | 69 | /** |
71 | * This is a linked list. | 70 | * This is a linked list. |
72 | */ | 71 | */ |
@@ -107,8 +106,7 @@ struct ServiceListeningInfo | |||
107 | /** | 106 | /** |
108 | * List of our services. | 107 | * List of our services. |
109 | */ | 108 | */ |
110 | struct ServiceList | 109 | struct ServiceList { |
111 | { | ||
112 | /** | 110 | /** |
113 | * This is a doubly-linked list. | 111 | * This is a doubly-linked list. |
114 | */ | 112 | */ |
@@ -280,30 +278,30 @@ static struct GNUNET_NotificationContext *notifier; | |||
280 | * parameter is ignore on systems other than LINUX | 278 | * parameter is ignore on systems other than LINUX |
281 | */ | 279 | */ |
282 | static void | 280 | static void |
283 | add_unixpath (struct sockaddr **saddrs, | 281 | add_unixpath(struct sockaddr **saddrs, |
284 | socklen_t *saddrlens, | 282 | socklen_t *saddrlens, |
285 | const char *unixpath, | 283 | const char *unixpath, |
286 | int abstract) | 284 | int abstract) |
287 | { | 285 | { |
288 | #ifdef AF_UNIX | 286 | #ifdef AF_UNIX |
289 | struct sockaddr_un *un; | 287 | struct sockaddr_un *un; |
290 | 288 | ||
291 | un = GNUNET_new (struct sockaddr_un); | 289 | un = GNUNET_new(struct sockaddr_un); |
292 | un->sun_family = AF_UNIX; | 290 | un->sun_family = AF_UNIX; |
293 | GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path)); | 291 | GNUNET_strlcpy(un->sun_path, unixpath, sizeof(un->sun_path)); |
294 | #ifdef LINUX | 292 | #ifdef LINUX |
295 | if (GNUNET_YES == abstract) | 293 | if (GNUNET_YES == abstract) |
296 | un->sun_path[0] = '\0'; | 294 | un->sun_path[0] = '\0'; |
297 | #endif | 295 | #endif |
298 | #if HAVE_SOCKADDR_UN_SUN_LEN | 296 | #if HAVE_SOCKADDR_UN_SUN_LEN |
299 | un->sun_len = (u_char) sizeof (struct sockaddr_un); | 297 | un->sun_len = (u_char)sizeof(struct sockaddr_un); |
300 | #endif | 298 | #endif |
301 | *saddrs = (struct sockaddr *) un; | 299 | *saddrs = (struct sockaddr *)un; |
302 | *saddrlens = sizeof (struct sockaddr_un); | 300 | *saddrlens = sizeof(struct sockaddr_un); |
303 | #else | 301 | #else |
304 | /* this function should never be called | 302 | /* this function should never be called |
305 | * unless AF_UNIX is defined! */ | 303 | * unless AF_UNIX is defined! */ |
306 | GNUNET_assert (0); | 304 | GNUNET_assert(0); |
307 | #endif | 305 | #endif |
308 | } | 306 | } |
309 | 307 | ||
@@ -329,10 +327,10 @@ add_unixpath (struct sockaddr **saddrs, | |||
329 | * set to NULL). | 327 | * set to NULL). |
330 | */ | 328 | */ |
331 | static int | 329 | static int |
332 | get_server_addresses (const char *service_name, | 330 | get_server_addresses(const char *service_name, |
333 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 331 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
334 | struct sockaddr ***addrs, | 332 | struct sockaddr ***addrs, |
335 | socklen_t **addr_lens) | 333 | socklen_t **addr_lens) |
336 | { | 334 | { |
337 | int disablev6; | 335 | int disablev6; |
338 | struct GNUNET_NETWORK_Handle *desc; | 336 | struct GNUNET_NETWORK_Handle *desc; |
@@ -353,72 +351,72 @@ get_server_addresses (const char *service_name, | |||
353 | *addrs = NULL; | 351 | *addrs = NULL; |
354 | *addr_lens = NULL; | 352 | *addr_lens = NULL; |
355 | desc = NULL; | 353 | desc = NULL; |
356 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) | 354 | if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "DISABLEV6")) |
357 | { | ||
358 | if (GNUNET_SYSERR == | ||
359 | (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg, | ||
360 | service_name, | ||
361 | "DISABLEV6"))) | ||
362 | return GNUNET_SYSERR; | ||
363 | } | ||
364 | else | ||
365 | disablev6 = GNUNET_NO; | ||
366 | |||
367 | if (! disablev6) | ||
368 | { | ||
369 | /* probe IPv6 support */ | ||
370 | desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); | ||
371 | if (NULL == desc) | ||
372 | { | 355 | { |
373 | if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || | 356 | if (GNUNET_SYSERR == |
374 | (EACCES == errno)) | 357 | (disablev6 = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
375 | { | 358 | service_name, |
376 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); | 359 | "DISABLEV6"))) |
377 | return GNUNET_SYSERR; | 360 | return GNUNET_SYSERR; |
378 | } | ||
379 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
380 | _ ( | ||
381 | "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), | ||
382 | service_name, | ||
383 | strerror (errno)); | ||
384 | disablev6 = GNUNET_YES; | ||
385 | } | 361 | } |
386 | else | 362 | else |
363 | disablev6 = GNUNET_NO; | ||
364 | |||
365 | if (!disablev6) | ||
387 | { | 366 | { |
388 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); | 367 | /* probe IPv6 support */ |
389 | desc = NULL; | 368 | desc = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_STREAM, 0); |
369 | if (NULL == desc) | ||
370 | { | ||
371 | if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || | ||
372 | (EACCES == errno)) | ||
373 | { | ||
374 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
375 | return GNUNET_SYSERR; | ||
376 | } | ||
377 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
378 | _( | ||
379 | "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), | ||
380 | service_name, | ||
381 | strerror(errno)); | ||
382 | disablev6 = GNUNET_YES; | ||
383 | } | ||
384 | else | ||
385 | { | ||
386 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc)); | ||
387 | desc = NULL; | ||
388 | } | ||
390 | } | 389 | } |
391 | } | ||
392 | 390 | ||
393 | port = 0; | 391 | port = 0; |
394 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) | 392 | if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "PORT")) |
395 | { | ||
396 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, | ||
397 | service_name, | ||
398 | "PORT", | ||
399 | &port)) | ||
400 | { | ||
401 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
402 | _ ("Require valid port number for service `%s' in configuration!\n"), | ||
403 | service_name); | ||
404 | } | ||
405 | if (port > 65535) | ||
406 | { | 393 | { |
407 | LOG (GNUNET_ERROR_TYPE_ERROR, | 394 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, |
408 | _ ("Require valid port number for service `%s' in configuration!\n"), | 395 | service_name, |
409 | service_name); | 396 | "PORT", |
410 | return GNUNET_SYSERR; | 397 | &port)) |
398 | { | ||
399 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
400 | _("Require valid port number for service `%s' in configuration!\n"), | ||
401 | service_name); | ||
402 | } | ||
403 | if (port > 65535) | ||
404 | { | ||
405 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
406 | _("Require valid port number for service `%s' in configuration!\n"), | ||
407 | service_name); | ||
408 | return GNUNET_SYSERR; | ||
409 | } | ||
411 | } | 410 | } |
412 | } | ||
413 | 411 | ||
414 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) | 412 | if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "BINDTO")) |
415 | { | 413 | { |
416 | GNUNET_break (GNUNET_OK == | 414 | GNUNET_break(GNUNET_OK == |
417 | GNUNET_CONFIGURATION_get_value_string (cfg, | 415 | GNUNET_CONFIGURATION_get_value_string(cfg, |
418 | service_name, | 416 | service_name, |
419 | "BINDTO", | 417 | "BINDTO", |
420 | &hostname)); | 418 | &hostname)); |
421 | } | 419 | } |
422 | else | 420 | else |
423 | hostname = NULL; | 421 | hostname = NULL; |
424 | 422 | ||
@@ -426,235 +424,235 @@ get_server_addresses (const char *service_name, | |||
426 | abstract = GNUNET_NO; | 424 | abstract = GNUNET_NO; |
427 | #ifdef AF_UNIX | 425 | #ifdef AF_UNIX |
428 | if ((GNUNET_YES == | 426 | if ((GNUNET_YES == |
429 | GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && | 427 | GNUNET_CONFIGURATION_have_value(cfg, service_name, "UNIXPATH")) && |
430 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, | 428 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, |
431 | service_name, | 429 | service_name, |
432 | "UNIXPATH", | 430 | "UNIXPATH", |
433 | &unixpath)) && | 431 | &unixpath)) && |
434 | (0 < strlen (unixpath))) | 432 | (0 < strlen(unixpath))) |
435 | { | ||
436 | /* probe UNIX support */ | ||
437 | struct sockaddr_un s_un; | ||
438 | |||
439 | if (strlen (unixpath) >= sizeof (s_un.sun_path)) | ||
440 | { | 433 | { |
441 | LOG (GNUNET_ERROR_TYPE_WARNING, | 434 | /* probe UNIX support */ |
442 | _ ("UNIXPATH `%s' too long, maximum length is %llu\n"), | 435 | struct sockaddr_un s_un; |
443 | unixpath, | 436 | |
444 | (unsigned long long) sizeof (s_un.sun_path)); | 437 | if (strlen(unixpath) >= sizeof(s_un.sun_path)) |
445 | unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); | 438 | { |
446 | LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath); | 439 | LOG(GNUNET_ERROR_TYPE_WARNING, |
447 | } | 440 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), |
441 | unixpath, | ||
442 | (unsigned long long)sizeof(s_un.sun_path)); | ||
443 | unixpath = GNUNET_NETWORK_shorten_unixpath(unixpath); | ||
444 | LOG(GNUNET_ERROR_TYPE_INFO, _("Using `%s' instead\n"), unixpath); | ||
445 | } | ||
448 | #ifdef LINUX | 446 | #ifdef LINUX |
449 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 447 | abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
450 | "TESTING", | 448 | "TESTING", |
451 | "USE_ABSTRACT_SOCKETS"); | 449 | "USE_ABSTRACT_SOCKETS"); |
452 | if (GNUNET_SYSERR == abstract) | 450 | if (GNUNET_SYSERR == abstract) |
453 | abstract = GNUNET_NO; | 451 | abstract = GNUNET_NO; |
454 | #endif | 452 | #endif |
455 | if ((GNUNET_YES != abstract) && | 453 | if ((GNUNET_YES != abstract) && |
456 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath))) | 454 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file(unixpath))) |
457 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); | 455 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); |
458 | } | ||
459 | if (NULL != unixpath) | ||
460 | { | ||
461 | desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); | ||
462 | if (NULL == desc) | ||
463 | { | ||
464 | if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || | ||
465 | (EACCES == errno)) | ||
466 | { | ||
467 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
468 | GNUNET_free_non_null (hostname); | ||
469 | GNUNET_free (unixpath); | ||
470 | return GNUNET_SYSERR; | ||
471 | } | ||
472 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
473 | _ ( | ||
474 | "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), | ||
475 | service_name, | ||
476 | strerror (errno)); | ||
477 | GNUNET_free (unixpath); | ||
478 | unixpath = NULL; | ||
479 | } | 456 | } |
480 | else | 457 | if (NULL != unixpath) |
481 | { | 458 | { |
482 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); | 459 | desc = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0); |
483 | desc = NULL; | 460 | if (NULL == desc) |
461 | { | ||
462 | if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || | ||
463 | (EACCES == errno)) | ||
464 | { | ||
465 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
466 | GNUNET_free_non_null(hostname); | ||
467 | GNUNET_free(unixpath); | ||
468 | return GNUNET_SYSERR; | ||
469 | } | ||
470 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
471 | _( | ||
472 | "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), | ||
473 | service_name, | ||
474 | strerror(errno)); | ||
475 | GNUNET_free(unixpath); | ||
476 | unixpath = NULL; | ||
477 | } | ||
478 | else | ||
479 | { | ||
480 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc)); | ||
481 | desc = NULL; | ||
482 | } | ||
484 | } | 483 | } |
485 | } | ||
486 | #endif | 484 | #endif |
487 | 485 | ||
488 | if ((0 == port) && (NULL == unixpath)) | 486 | if ((0 == port) && (NULL == unixpath)) |
489 | { | ||
490 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, | ||
491 | service_name, | ||
492 | "START_ON_DEMAND")) | ||
493 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
494 | _ ( | ||
495 | "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), | ||
496 | service_name); | ||
497 | GNUNET_free_non_null (hostname); | ||
498 | return GNUNET_SYSERR; | ||
499 | } | ||
500 | if (0 == port) | ||
501 | { | ||
502 | saddrs = GNUNET_new_array (2, struct sockaddr *); | ||
503 | saddrlens = GNUNET_new_array (2, socklen_t); | ||
504 | add_unixpath (saddrs, saddrlens, unixpath, abstract); | ||
505 | GNUNET_free_non_null (unixpath); | ||
506 | GNUNET_free_non_null (hostname); | ||
507 | *addrs = saddrs; | ||
508 | *addr_lens = saddrlens; | ||
509 | return 1; | ||
510 | } | ||
511 | |||
512 | if (NULL != hostname) | ||
513 | { | ||
514 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
515 | "Resolving `%s' since that is where `%s' will bind to.\n", | ||
516 | hostname, | ||
517 | service_name); | ||
518 | memset (&hints, 0, sizeof (struct addrinfo)); | ||
519 | if (disablev6) | ||
520 | hints.ai_family = AF_INET; | ||
521 | hints.ai_protocol = IPPROTO_TCP; | ||
522 | if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) || | ||
523 | (NULL == res)) | ||
524 | { | 487 | { |
525 | LOG (GNUNET_ERROR_TYPE_ERROR, | 488 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, |
526 | _ ("Failed to resolve `%s': %s\n"), | 489 | service_name, |
527 | hostname, | 490 | "START_ON_DEMAND")) |
528 | gai_strerror (ret)); | 491 | LOG(GNUNET_ERROR_TYPE_ERROR, |
529 | GNUNET_free (hostname); | 492 | _( |
530 | GNUNET_free_non_null (unixpath); | 493 | "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), |
531 | return GNUNET_SYSERR; | 494 | service_name); |
532 | } | 495 | GNUNET_free_non_null(hostname); |
533 | next = res; | ||
534 | i = 0; | ||
535 | while (NULL != (pos = next)) | ||
536 | { | ||
537 | next = pos->ai_next; | ||
538 | if ((disablev6) && (pos->ai_family == AF_INET6)) | ||
539 | continue; | ||
540 | i++; | ||
541 | } | ||
542 | if (0 == i) | ||
543 | { | ||
544 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
545 | _ ("Failed to find %saddress for `%s'.\n"), | ||
546 | disablev6 ? "IPv4 " : "", | ||
547 | hostname); | ||
548 | freeaddrinfo (res); | ||
549 | GNUNET_free (hostname); | ||
550 | GNUNET_free_non_null (unixpath); | ||
551 | return GNUNET_SYSERR; | 496 | return GNUNET_SYSERR; |
552 | } | 497 | } |
553 | resi = i; | 498 | if (0 == port) |
554 | if (NULL != unixpath) | ||
555 | resi++; | ||
556 | saddrs = GNUNET_new_array (resi + 1, struct sockaddr *); | ||
557 | saddrlens = GNUNET_new_array (resi + 1, socklen_t); | ||
558 | i = 0; | ||
559 | if (NULL != unixpath) | ||
560 | { | 499 | { |
561 | add_unixpath (saddrs, saddrlens, unixpath, abstract); | 500 | saddrs = GNUNET_new_array(2, struct sockaddr *); |
562 | i++; | 501 | saddrlens = GNUNET_new_array(2, socklen_t); |
502 | add_unixpath(saddrs, saddrlens, unixpath, abstract); | ||
503 | GNUNET_free_non_null(unixpath); | ||
504 | GNUNET_free_non_null(hostname); | ||
505 | *addrs = saddrs; | ||
506 | *addr_lens = saddrlens; | ||
507 | return 1; | ||
563 | } | 508 | } |
564 | next = res; | 509 | |
565 | while (NULL != (pos = next)) | 510 | if (NULL != hostname) |
566 | { | ||
567 | next = pos->ai_next; | ||
568 | if ((disablev6) && (AF_INET6 == pos->ai_family)) | ||
569 | continue; | ||
570 | if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) | ||
571 | continue; /* not TCP */ | ||
572 | if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) | ||
573 | continue; /* huh? */ | ||
574 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
575 | "Service `%s' will bind to `%s'\n", | ||
576 | service_name, | ||
577 | GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); | ||
578 | if (AF_INET == pos->ai_family) | ||
579 | { | ||
580 | GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen); | ||
581 | saddrlens[i] = pos->ai_addrlen; | ||
582 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | ||
583 | GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); | ||
584 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | ||
585 | } | ||
586 | else | ||
587 | { | ||
588 | GNUNET_assert (AF_INET6 == pos->ai_family); | ||
589 | GNUNET_assert (sizeof (struct sockaddr_in6) == pos->ai_addrlen); | ||
590 | saddrlens[i] = pos->ai_addrlen; | ||
591 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | ||
592 | GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); | ||
593 | ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); | ||
594 | } | ||
595 | i++; | ||
596 | } | ||
597 | GNUNET_free (hostname); | ||
598 | freeaddrinfo (res); | ||
599 | resi = i; | ||
600 | } | ||
601 | else | ||
602 | { | ||
603 | /* will bind against everything, just set port */ | ||
604 | if (disablev6) | ||
605 | { | 511 | { |
606 | /* V4-only */ | 512 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
607 | resi = 1; | 513 | "Resolving `%s' since that is where `%s' will bind to.\n", |
514 | hostname, | ||
515 | service_name); | ||
516 | memset(&hints, 0, sizeof(struct addrinfo)); | ||
517 | if (disablev6) | ||
518 | hints.ai_family = AF_INET; | ||
519 | hints.ai_protocol = IPPROTO_TCP; | ||
520 | if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) || | ||
521 | (NULL == res)) | ||
522 | { | ||
523 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
524 | _("Failed to resolve `%s': %s\n"), | ||
525 | hostname, | ||
526 | gai_strerror(ret)); | ||
527 | GNUNET_free(hostname); | ||
528 | GNUNET_free_non_null(unixpath); | ||
529 | return GNUNET_SYSERR; | ||
530 | } | ||
531 | next = res; | ||
532 | i = 0; | ||
533 | while (NULL != (pos = next)) | ||
534 | { | ||
535 | next = pos->ai_next; | ||
536 | if ((disablev6) && (pos->ai_family == AF_INET6)) | ||
537 | continue; | ||
538 | i++; | ||
539 | } | ||
540 | if (0 == i) | ||
541 | { | ||
542 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
543 | _("Failed to find %saddress for `%s'.\n"), | ||
544 | disablev6 ? "IPv4 " : "", | ||
545 | hostname); | ||
546 | freeaddrinfo(res); | ||
547 | GNUNET_free(hostname); | ||
548 | GNUNET_free_non_null(unixpath); | ||
549 | return GNUNET_SYSERR; | ||
550 | } | ||
551 | resi = i; | ||
608 | if (NULL != unixpath) | 552 | if (NULL != unixpath) |
609 | resi++; | 553 | resi++; |
554 | saddrs = GNUNET_new_array(resi + 1, struct sockaddr *); | ||
555 | saddrlens = GNUNET_new_array(resi + 1, socklen_t); | ||
610 | i = 0; | 556 | i = 0; |
611 | saddrs = GNUNET_new_array (resi + 1, struct sockaddr *); | ||
612 | saddrlens = GNUNET_new_array (resi + 1, socklen_t); | ||
613 | if (NULL != unixpath) | 557 | if (NULL != unixpath) |
614 | { | 558 | { |
615 | add_unixpath (saddrs, saddrlens, unixpath, abstract); | 559 | add_unixpath(saddrs, saddrlens, unixpath, abstract); |
616 | i++; | 560 | i++; |
617 | } | 561 | } |
618 | saddrlens[i] = sizeof (struct sockaddr_in); | 562 | next = res; |
619 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | 563 | while (NULL != (pos = next)) |
620 | #if HAVE_SOCKADDR_IN_SIN_LEN | 564 | { |
621 | ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; | 565 | next = pos->ai_next; |
622 | #endif | 566 | if ((disablev6) && (AF_INET6 == pos->ai_family)) |
623 | ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; | 567 | continue; |
624 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | 568 | if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) |
569 | continue; /* not TCP */ | ||
570 | if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) | ||
571 | continue; /* huh? */ | ||
572 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
573 | "Service `%s' will bind to `%s'\n", | ||
574 | service_name, | ||
575 | GNUNET_a2s(pos->ai_addr, pos->ai_addrlen)); | ||
576 | if (AF_INET == pos->ai_family) | ||
577 | { | ||
578 | GNUNET_assert(sizeof(struct sockaddr_in) == pos->ai_addrlen); | ||
579 | saddrlens[i] = pos->ai_addrlen; | ||
580 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
581 | GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); | ||
582 | ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); | ||
583 | } | ||
584 | else | ||
585 | { | ||
586 | GNUNET_assert(AF_INET6 == pos->ai_family); | ||
587 | GNUNET_assert(sizeof(struct sockaddr_in6) == pos->ai_addrlen); | ||
588 | saddrlens[i] = pos->ai_addrlen; | ||
589 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
590 | GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); | ||
591 | ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); | ||
592 | } | ||
593 | i++; | ||
594 | } | ||
595 | GNUNET_free(hostname); | ||
596 | freeaddrinfo(res); | ||
597 | resi = i; | ||
625 | } | 598 | } |
626 | else | 599 | else |
627 | { | 600 | { |
628 | /* dual stack */ | 601 | /* will bind against everything, just set port */ |
629 | resi = 2; | 602 | if (disablev6) |
630 | if (NULL != unixpath) | 603 | { |
631 | resi++; | 604 | /* V4-only */ |
632 | saddrs = GNUNET_new_array (resi + 1, struct sockaddr *); | 605 | resi = 1; |
633 | saddrlens = GNUNET_new_array (resi + 1, socklen_t); | 606 | if (NULL != unixpath) |
634 | i = 0; | 607 | resi++; |
635 | if (NULL != unixpath) | 608 | i = 0; |
636 | { | 609 | saddrs = GNUNET_new_array(resi + 1, struct sockaddr *); |
637 | add_unixpath (saddrs, saddrlens, unixpath, abstract); | 610 | saddrlens = GNUNET_new_array(resi + 1, socklen_t); |
638 | i++; | 611 | if (NULL != unixpath) |
639 | } | 612 | { |
640 | saddrlens[i] = sizeof (struct sockaddr_in6); | 613 | add_unixpath(saddrs, saddrlens, unixpath, abstract); |
641 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | 614 | i++; |
615 | } | ||
616 | saddrlens[i] = sizeof(struct sockaddr_in); | ||
617 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
618 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
619 | ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i]; | ||
620 | #endif | ||
621 | ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; | ||
622 | ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); | ||
623 | } | ||
624 | else | ||
625 | { | ||
626 | /* dual stack */ | ||
627 | resi = 2; | ||
628 | if (NULL != unixpath) | ||
629 | resi++; | ||
630 | saddrs = GNUNET_new_array(resi + 1, struct sockaddr *); | ||
631 | saddrlens = GNUNET_new_array(resi + 1, socklen_t); | ||
632 | i = 0; | ||
633 | if (NULL != unixpath) | ||
634 | { | ||
635 | add_unixpath(saddrs, saddrlens, unixpath, abstract); | ||
636 | i++; | ||
637 | } | ||
638 | saddrlens[i] = sizeof(struct sockaddr_in6); | ||
639 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
642 | #if HAVE_SOCKADDR_IN_SIN_LEN | 640 | #if HAVE_SOCKADDR_IN_SIN_LEN |
643 | ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; | 641 | ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0]; |
644 | #endif | 642 | #endif |
645 | ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; | 643 | ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6; |
646 | ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); | 644 | ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); |
647 | i++; | 645 | i++; |
648 | saddrlens[i] = sizeof (struct sockaddr_in); | 646 | saddrlens[i] = sizeof(struct sockaddr_in); |
649 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | 647 | saddrs[i] = GNUNET_malloc(saddrlens[i]); |
650 | #if HAVE_SOCKADDR_IN_SIN_LEN | 648 | #if HAVE_SOCKADDR_IN_SIN_LEN |
651 | ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; | 649 | ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[1]; |
652 | #endif | 650 | #endif |
653 | ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; | 651 | ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; |
654 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | 652 | ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); |
653 | } | ||
655 | } | 654 | } |
656 | } | 655 | GNUNET_free_non_null(unixpath); |
657 | GNUNET_free_non_null (unixpath); | ||
658 | *addrs = saddrs; | 656 | *addrs = saddrs; |
659 | *addr_lens = saddrlens; | 657 | *addr_lens = saddrlens; |
660 | return resi; | 658 | return resi; |
@@ -672,19 +670,19 @@ get_server_addresses (const char *service_name, | |||
672 | * @return NULL if it was not found | 670 | * @return NULL if it was not found |
673 | */ | 671 | */ |
674 | static void | 672 | static void |
675 | signal_result (struct GNUNET_SERVICE_Client *client, | 673 | signal_result(struct GNUNET_SERVICE_Client *client, |
676 | const char *name, | 674 | const char *name, |
677 | uint64_t request_id, | 675 | uint64_t request_id, |
678 | enum GNUNET_ARM_Result result) | 676 | enum GNUNET_ARM_Result result) |
679 | { | 677 | { |
680 | struct GNUNET_MQ_Envelope *env; | 678 | struct GNUNET_MQ_Envelope *env; |
681 | struct GNUNET_ARM_ResultMessage *msg; | 679 | struct GNUNET_ARM_ResultMessage *msg; |
682 | 680 | ||
683 | (void) name; | 681 | (void)name; |
684 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_RESULT); | 682 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_RESULT); |
685 | msg->result = htonl (result); | 683 | msg->result = htonl(result); |
686 | msg->arm_msg.request_id = GNUNET_htonll (request_id); | 684 | msg->arm_msg.request_id = GNUNET_htonll(request_id); |
687 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 685 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
688 | } | 686 | } |
689 | 687 | ||
690 | 688 | ||
@@ -697,34 +695,34 @@ signal_result (struct GNUNET_SERVICE_Client *client, | |||
697 | * otherwise, send to all clients in the notifier | 695 | * otherwise, send to all clients in the notifier |
698 | */ | 696 | */ |
699 | static void | 697 | static void |
700 | broadcast_status (const char *name, | 698 | broadcast_status(const char *name, |
701 | enum GNUNET_ARM_ServiceStatus status, | 699 | enum GNUNET_ARM_ServiceStatus status, |
702 | struct GNUNET_SERVICE_Client *unicast) | 700 | struct GNUNET_SERVICE_Client *unicast) |
703 | { | 701 | { |
704 | struct GNUNET_MQ_Envelope *env; | 702 | struct GNUNET_MQ_Envelope *env; |
705 | struct GNUNET_ARM_StatusMessage *msg; | 703 | struct GNUNET_ARM_StatusMessage *msg; |
706 | size_t namelen; | 704 | size_t namelen; |
707 | 705 | ||
708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 706 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
709 | "Sending status %u of service `%s' to client\n", | 707 | "Sending status %u of service `%s' to client\n", |
710 | (unsigned int) status, | 708 | (unsigned int)status, |
711 | name); | 709 | name); |
712 | namelen = strlen (name) + 1; | 710 | namelen = strlen(name) + 1; |
713 | env = GNUNET_MQ_msg_extra (msg, namelen, GNUNET_MESSAGE_TYPE_ARM_STATUS); | 711 | env = GNUNET_MQ_msg_extra(msg, namelen, GNUNET_MESSAGE_TYPE_ARM_STATUS); |
714 | msg->status = htonl ((uint32_t) (status)); | 712 | msg->status = htonl((uint32_t)(status)); |
715 | GNUNET_memcpy ((char *) &msg[1], name, namelen); | 713 | GNUNET_memcpy((char *)&msg[1], name, namelen); |
716 | if (NULL == unicast) | 714 | if (NULL == unicast) |
717 | { | 715 | { |
718 | if (NULL != notifier) | 716 | if (NULL != notifier) |
719 | GNUNET_notification_context_broadcast (notifier, | 717 | GNUNET_notification_context_broadcast(notifier, |
720 | &msg->header, | 718 | &msg->header, |
721 | GNUNET_YES); | 719 | GNUNET_YES); |
722 | GNUNET_MQ_discard (env); | 720 | GNUNET_MQ_discard(env); |
723 | } | 721 | } |
724 | else | 722 | else |
725 | { | 723 | { |
726 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (unicast), env); | 724 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(unicast), env); |
727 | } | 725 | } |
728 | } | 726 | } |
729 | 727 | ||
730 | 728 | ||
@@ -737,9 +735,9 @@ broadcast_status (const char *name, | |||
737 | * being started. 0 if starting was not requested. | 735 | * being started. 0 if starting was not requested. |
738 | */ | 736 | */ |
739 | static void | 737 | static void |
740 | start_process (struct ServiceList *sl, | 738 | start_process(struct ServiceList *sl, |
741 | struct GNUNET_SERVICE_Client *client, | 739 | struct GNUNET_SERVICE_Client *client, |
742 | uint64_t request_id) | 740 | uint64_t request_id) |
743 | { | 741 | { |
744 | char *loprefix; | 742 | char *loprefix; |
745 | char *options; | 743 | char *options; |
@@ -755,194 +753,194 @@ start_process (struct ServiceList *sl, | |||
755 | lsocks = NULL; | 753 | lsocks = NULL; |
756 | ls = 0; | 754 | ls = 0; |
757 | for (sli = sl->listen_head; NULL != sli; sli = sli->next) | 755 | for (sli = sl->listen_head; NULL != sli; sli = sli->next) |
758 | { | ||
759 | GNUNET_array_append (lsocks, | ||
760 | ls, | ||
761 | GNUNET_NETWORK_get_fd (sli->listen_socket)); | ||
762 | if (NULL != sli->accept_task) | ||
763 | { | 756 | { |
764 | GNUNET_SCHEDULER_cancel (sli->accept_task); | 757 | GNUNET_array_append(lsocks, |
765 | sli->accept_task = NULL; | 758 | ls, |
759 | GNUNET_NETWORK_get_fd(sli->listen_socket)); | ||
760 | if (NULL != sli->accept_task) | ||
761 | { | ||
762 | GNUNET_SCHEDULER_cancel(sli->accept_task); | ||
763 | sli->accept_task = NULL; | ||
764 | } | ||
766 | } | 765 | } |
767 | } | ||
768 | #if WINDOWS | 766 | #if WINDOWS |
769 | GNUNET_array_append (lsocks, ls, INVALID_SOCKET); | 767 | GNUNET_array_append(lsocks, ls, INVALID_SOCKET); |
770 | #else | 768 | #else |
771 | GNUNET_array_append (lsocks, ls, -1); | 769 | GNUNET_array_append(lsocks, ls, -1); |
772 | #endif | 770 | #endif |
773 | 771 | ||
774 | /* obtain configuration */ | 772 | /* obtain configuration */ |
775 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | 773 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, |
776 | sl->name, | 774 | sl->name, |
777 | "PREFIX", | 775 | "PREFIX", |
778 | &loprefix)) | 776 | &loprefix)) |
779 | loprefix = GNUNET_strdup (prefix_command); | 777 | loprefix = GNUNET_strdup(prefix_command); |
780 | else | 778 | else |
781 | loprefix = GNUNET_CONFIGURATION_expand_dollar (cfg, loprefix); | 779 | loprefix = GNUNET_CONFIGURATION_expand_dollar(cfg, loprefix); |
782 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | 780 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, |
783 | sl->name, | 781 | sl->name, |
784 | "OPTIONS", | 782 | "OPTIONS", |
785 | &options)) | 783 | &options)) |
786 | options = NULL; | 784 | options = NULL; |
787 | else | 785 | else |
788 | options = GNUNET_CONFIGURATION_expand_dollar (cfg, options); | 786 | options = GNUNET_CONFIGURATION_expand_dollar(cfg, options); |
789 | { | 787 | { |
790 | char *new_options; | 788 | char *new_options; |
791 | char *optpos; | 789 | char *optpos; |
792 | char *fin_options; | 790 | char *fin_options; |
793 | 791 | ||
794 | fin_options = GNUNET_strdup (final_option); | 792 | fin_options = GNUNET_strdup(final_option); |
795 | /* replace '{}' with service name */ | 793 | /* replace '{}' with service name */ |
796 | while (NULL != (optpos = strstr (fin_options, "{}"))) | 794 | while (NULL != (optpos = strstr(fin_options, "{}"))) |
797 | { | 795 | { |
798 | /* terminate string at opening parenthesis */ | 796 | /* terminate string at opening parenthesis */ |
799 | *optpos = 0; | 797 | *optpos = 0; |
800 | GNUNET_asprintf (&new_options, | 798 | GNUNET_asprintf(&new_options, |
801 | "%s%s%s", | 799 | "%s%s%s", |
802 | fin_options, | 800 | fin_options, |
803 | sl->name, | 801 | sl->name, |
804 | optpos + 2); | 802 | optpos + 2); |
805 | GNUNET_free (fin_options); | 803 | GNUNET_free(fin_options); |
806 | fin_options = new_options; | 804 | fin_options = new_options; |
807 | } | 805 | } |
808 | if (NULL != options) | 806 | if (NULL != options) |
809 | { | 807 | { |
810 | /* combine "fin_options" with "options" */ | 808 | /* combine "fin_options" with "options" */ |
811 | optpos = options; | 809 | optpos = options; |
812 | GNUNET_asprintf (&options, "%s %s", fin_options, optpos); | 810 | GNUNET_asprintf(&options, "%s %s", fin_options, optpos); |
813 | GNUNET_free (fin_options); | 811 | GNUNET_free(fin_options); |
814 | GNUNET_free (optpos); | 812 | GNUNET_free(optpos); |
815 | } | 813 | } |
816 | else | 814 | else |
817 | { | 815 | { |
818 | /* only have "fin_options", use that */ | 816 | /* only have "fin_options", use that */ |
819 | options = fin_options; | 817 | options = fin_options; |
820 | } | 818 | } |
821 | } | 819 | } |
822 | options = GNUNET_CONFIGURATION_expand_dollar (cfg, options); | 820 | options = GNUNET_CONFIGURATION_expand_dollar(cfg, options); |
823 | use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "DEBUG"); | 821 | use_debug = GNUNET_CONFIGURATION_get_value_yesno(cfg, sl->name, "DEBUG"); |
824 | { | 822 | { |
825 | const char *service_type = NULL; | 823 | const char *service_type = NULL; |
826 | const char *choices[] = {"GNUNET", "SIMPLE", NULL}; | 824 | const char *choices[] = { "GNUNET", "SIMPLE", NULL }; |
827 | 825 | ||
828 | is_simple_service = GNUNET_NO; | 826 | is_simple_service = GNUNET_NO; |
829 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_choice (cfg, | 827 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_choice(cfg, |
830 | sl->name, | 828 | sl->name, |
831 | "TYPE", | 829 | "TYPE", |
832 | choices, | 830 | choices, |
833 | &service_type)) && | 831 | &service_type)) && |
834 | (0 == strcasecmp (service_type, "SIMPLE"))) | 832 | (0 == strcasecmp(service_type, "SIMPLE"))) |
835 | is_simple_service = GNUNET_YES; | 833 | is_simple_service = GNUNET_YES; |
836 | } | 834 | } |
837 | 835 | ||
838 | GNUNET_assert (NULL == sl->proc); | 836 | GNUNET_assert(NULL == sl->proc); |
839 | if (GNUNET_YES == is_simple_service) | 837 | if (GNUNET_YES == is_simple_service) |
840 | { | ||
841 | /* A simple service will receive no GNUnet specific | ||
842 | command line options. */ | ||
843 | binary = GNUNET_strdup (sl->binary); | ||
844 | binary = GNUNET_CONFIGURATION_expand_dollar (cfg, binary); | ||
845 | GNUNET_asprintf ("edbinary, "\"%s\"", sl->binary); | ||
846 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
847 | "Starting simple service `%s' using binary `%s'\n", | ||
848 | sl->name, | ||
849 | sl->binary); | ||
850 | /* FIXME: dollar expansion should only be done outside | ||
851 | * of ''-quoted strings, escaping should be considered. */ | ||
852 | if (NULL != options) | ||
853 | options = GNUNET_CONFIGURATION_expand_dollar (cfg, options); | ||
854 | sl->proc = GNUNET_OS_start_process_s (sl->pipe_control, | ||
855 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
856 | lsocks, | ||
857 | loprefix, | ||
858 | quotedbinary, | ||
859 | options, | ||
860 | NULL); | ||
861 | } | ||
862 | else | ||
863 | { | ||
864 | /* actually start process */ | ||
865 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
866 | "Starting service `%s' using binary `%s' and configuration `%s'\n", | ||
867 | sl->name, | ||
868 | sl->binary, | ||
869 | sl->config); | ||
870 | binary = GNUNET_OS_get_libexec_binary_path (sl->binary); | ||
871 | GNUNET_asprintf ("edbinary, "\"%s\"", binary); | ||
872 | |||
873 | if (GNUNET_YES == use_debug) | ||
874 | { | 838 | { |
875 | if (NULL == sl->config) | 839 | /* A simple service will receive no GNUnet specific |
876 | sl->proc = GNUNET_OS_start_process_s (sl->pipe_control, | 840 | command line options. */ |
877 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 841 | binary = GNUNET_strdup(sl->binary); |
878 | lsocks, | 842 | binary = GNUNET_CONFIGURATION_expand_dollar(cfg, binary); |
879 | loprefix, | 843 | GNUNET_asprintf("edbinary, "\"%s\"", sl->binary); |
880 | quotedbinary, | 844 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
881 | "-L", | 845 | "Starting simple service `%s' using binary `%s'\n", |
882 | "DEBUG", | 846 | sl->name, |
883 | options, | 847 | sl->binary); |
884 | NULL); | 848 | /* FIXME: dollar expansion should only be done outside |
885 | else | 849 | * of ''-quoted strings, escaping should be considered. */ |
886 | sl->proc = GNUNET_OS_start_process_s (sl->pipe_control, | 850 | if (NULL != options) |
887 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 851 | options = GNUNET_CONFIGURATION_expand_dollar(cfg, options); |
888 | lsocks, | 852 | sl->proc = GNUNET_OS_start_process_s(sl->pipe_control, |
889 | loprefix, | 853 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
890 | quotedbinary, | 854 | lsocks, |
891 | "-c", | 855 | loprefix, |
892 | sl->config, | 856 | quotedbinary, |
893 | "-L", | 857 | options, |
894 | "DEBUG", | 858 | NULL); |
895 | options, | ||
896 | NULL); | ||
897 | } | 859 | } |
898 | else | 860 | else |
899 | { | 861 | { |
900 | if (NULL == sl->config) | 862 | /* actually start process */ |
901 | sl->proc = GNUNET_OS_start_process_s (sl->pipe_control, | 863 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
902 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 864 | "Starting service `%s' using binary `%s' and configuration `%s'\n", |
903 | lsocks, | 865 | sl->name, |
904 | loprefix, | 866 | sl->binary, |
905 | quotedbinary, | 867 | sl->config); |
906 | options, | 868 | binary = GNUNET_OS_get_libexec_binary_path(sl->binary); |
907 | NULL); | 869 | GNUNET_asprintf("edbinary, "\"%s\"", binary); |
870 | |||
871 | if (GNUNET_YES == use_debug) | ||
872 | { | ||
873 | if (NULL == sl->config) | ||
874 | sl->proc = GNUNET_OS_start_process_s(sl->pipe_control, | ||
875 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
876 | lsocks, | ||
877 | loprefix, | ||
878 | quotedbinary, | ||
879 | "-L", | ||
880 | "DEBUG", | ||
881 | options, | ||
882 | NULL); | ||
883 | else | ||
884 | sl->proc = GNUNET_OS_start_process_s(sl->pipe_control, | ||
885 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
886 | lsocks, | ||
887 | loprefix, | ||
888 | quotedbinary, | ||
889 | "-c", | ||
890 | sl->config, | ||
891 | "-L", | ||
892 | "DEBUG", | ||
893 | options, | ||
894 | NULL); | ||
895 | } | ||
908 | else | 896 | else |
909 | sl->proc = GNUNET_OS_start_process_s (sl->pipe_control, | 897 | { |
910 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 898 | if (NULL == sl->config) |
911 | lsocks, | 899 | sl->proc = GNUNET_OS_start_process_s(sl->pipe_control, |
912 | loprefix, | 900 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
913 | quotedbinary, | 901 | lsocks, |
914 | "-c", | 902 | loprefix, |
915 | sl->config, | 903 | quotedbinary, |
916 | options, | 904 | options, |
917 | NULL); | 905 | NULL); |
906 | else | ||
907 | sl->proc = GNUNET_OS_start_process_s(sl->pipe_control, | ||
908 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
909 | lsocks, | ||
910 | loprefix, | ||
911 | quotedbinary, | ||
912 | "-c", | ||
913 | sl->config, | ||
914 | options, | ||
915 | NULL); | ||
916 | } | ||
918 | } | 917 | } |
919 | } | 918 | GNUNET_free(binary); |
920 | GNUNET_free (binary); | 919 | GNUNET_free(quotedbinary); |
921 | GNUNET_free (quotedbinary); | ||
922 | if (NULL == sl->proc) | 920 | if (NULL == sl->proc) |
923 | { | 921 | { |
924 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 922 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
925 | _ ("Failed to start service `%s'\n"), | 923 | _("Failed to start service `%s'\n"), |
926 | sl->name); | 924 | sl->name); |
927 | if (client) | 925 | if (client) |
928 | signal_result (client, | 926 | signal_result(client, |
929 | sl->name, | 927 | sl->name, |
930 | request_id, | 928 | request_id, |
931 | GNUNET_ARM_RESULT_START_FAILED); | 929 | GNUNET_ARM_RESULT_START_FAILED); |
932 | } | 930 | } |
933 | else | 931 | else |
934 | { | 932 | { |
935 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 933 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
936 | _ ("Starting service `%s'\n"), | 934 | _("Starting service `%s'\n"), |
937 | sl->name); | 935 | sl->name); |
938 | broadcast_status (sl->name, GNUNET_ARM_SERVICE_STARTING, NULL); | 936 | broadcast_status(sl->name, GNUNET_ARM_SERVICE_STARTING, NULL); |
939 | if (client) | 937 | if (client) |
940 | signal_result (client, sl->name, request_id, GNUNET_ARM_RESULT_STARTING); | 938 | signal_result(client, sl->name, request_id, GNUNET_ARM_RESULT_STARTING); |
941 | } | 939 | } |
942 | /* clean up */ | 940 | /* clean up */ |
943 | GNUNET_free (loprefix); | 941 | GNUNET_free(loprefix); |
944 | GNUNET_free (options); | 942 | GNUNET_free(options); |
945 | GNUNET_array_grow (lsocks, ls, 0); | 943 | GNUNET_array_grow(lsocks, ls, 0); |
946 | } | 944 | } |
947 | 945 | ||
948 | 946 | ||
@@ -954,17 +952,17 @@ start_process (struct ServiceList *sl, | |||
954 | * @return NULL if it was not found | 952 | * @return NULL if it was not found |
955 | */ | 953 | */ |
956 | static struct ServiceList * | 954 | static struct ServiceList * |
957 | find_service (const char *name) | 955 | find_service(const char *name) |
958 | { | 956 | { |
959 | struct ServiceList *sl; | 957 | struct ServiceList *sl; |
960 | 958 | ||
961 | sl = running_head; | 959 | sl = running_head; |
962 | while (sl != NULL) | 960 | while (sl != NULL) |
963 | { | 961 | { |
964 | if (0 == strcasecmp (sl->name, name)) | 962 | if (0 == strcasecmp(sl->name, name)) |
965 | return sl; | 963 | return sl; |
966 | sl = sl->next; | 964 | sl = sl->next; |
967 | } | 965 | } |
968 | return NULL; | 966 | return NULL; |
969 | } | 967 | } |
970 | 968 | ||
@@ -976,14 +974,14 @@ find_service (const char *name) | |||
976 | * @param cls callback data, `struct ServiceListeningInfo` describing a listen socket | 974 | * @param cls callback data, `struct ServiceListeningInfo` describing a listen socket |
977 | */ | 975 | */ |
978 | static void | 976 | static void |
979 | accept_connection (void *cls) | 977 | accept_connection(void *cls) |
980 | { | 978 | { |
981 | struct ServiceListeningInfo *sli = cls; | 979 | struct ServiceListeningInfo *sli = cls; |
982 | struct ServiceList *sl = sli->sl; | 980 | struct ServiceList *sl = sli->sl; |
983 | 981 | ||
984 | sli->accept_task = NULL; | 982 | sli->accept_task = NULL; |
985 | GNUNET_assert (GNUNET_NO == in_shutdown); | 983 | GNUNET_assert(GNUNET_NO == in_shutdown); |
986 | start_process (sl, NULL, 0); | 984 | start_process(sl, NULL, 0); |
987 | } | 985 | } |
988 | 986 | ||
989 | 987 | ||
@@ -996,121 +994,125 @@ accept_connection (void *cls) | |||
996 | * @param sl service entry for the service in question | 994 | * @param sl service entry for the service in question |
997 | */ | 995 | */ |
998 | static void | 996 | static void |
999 | create_listen_socket (struct sockaddr *sa, | 997 | create_listen_socket(struct sockaddr *sa, |
1000 | socklen_t addr_len, | 998 | socklen_t addr_len, |
1001 | struct ServiceList *sl) | 999 | struct ServiceList *sl) |
1002 | { | 1000 | { |
1003 | static int on = 1; | 1001 | static int on = 1; |
1004 | struct GNUNET_NETWORK_Handle *sock; | 1002 | struct GNUNET_NETWORK_Handle *sock; |
1005 | struct ServiceListeningInfo *sli; | 1003 | struct ServiceListeningInfo *sli; |
1004 | |||
1006 | #ifndef WINDOWS | 1005 | #ifndef WINDOWS |
1007 | int match_uid; | 1006 | int match_uid; |
1008 | int match_gid; | 1007 | int match_gid; |
1009 | #endif | 1008 | #endif |
1010 | 1009 | ||
1011 | switch (sa->sa_family) | 1010 | switch (sa->sa_family) |
1012 | { | 1011 | { |
1013 | case AF_INET: | 1012 | case AF_INET: |
1014 | sock = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0); | 1013 | sock = GNUNET_NETWORK_socket_create(PF_INET, SOCK_STREAM, 0); |
1015 | break; | 1014 | break; |
1016 | case AF_INET6: | 1015 | |
1017 | sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); | 1016 | case AF_INET6: |
1018 | break; | 1017 | sock = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_STREAM, 0); |
1019 | case AF_UNIX: | 1018 | break; |
1020 | if (0 == strcmp (GNUNET_a2s (sa, addr_len), | 1019 | |
1021 | "@")) /* Do not bind to blank UNIX path! */ | 1020 | case AF_UNIX: |
1022 | return; | 1021 | if (0 == strcmp(GNUNET_a2s(sa, addr_len), |
1023 | sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0); | 1022 | "@")) /* Do not bind to blank UNIX path! */ |
1024 | break; | 1023 | return; |
1025 | default: | 1024 | sock = GNUNET_NETWORK_socket_create(PF_UNIX, SOCK_STREAM, 0); |
1026 | GNUNET_break (0); | 1025 | break; |
1027 | sock = NULL; | 1026 | |
1028 | errno = EAFNOSUPPORT; | 1027 | default: |
1029 | break; | 1028 | GNUNET_break(0); |
1030 | } | 1029 | sock = NULL; |
1030 | errno = EAFNOSUPPORT; | ||
1031 | break; | ||
1032 | } | ||
1031 | if (NULL == sock) | 1033 | if (NULL == sock) |
1032 | { | 1034 | { |
1033 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1035 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1034 | _ ("Unable to create socket for service `%s': %s\n"), | 1036 | _("Unable to create socket for service `%s': %s\n"), |
1035 | sl->name, | 1037 | sl->name, |
1036 | strerror (errno)); | 1038 | strerror(errno)); |
1037 | GNUNET_free (sa); | 1039 | GNUNET_free(sa); |
1038 | return; | 1040 | return; |
1039 | } | 1041 | } |
1040 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (sock, | 1042 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(sock, |
1041 | SOL_SOCKET, | 1043 | SOL_SOCKET, |
1042 | SO_REUSEADDR, | 1044 | SO_REUSEADDR, |
1043 | &on, | 1045 | &on, |
1044 | sizeof (on))) | 1046 | sizeof(on))) |
1045 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1047 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1046 | "setsockopt"); | 1048 | "setsockopt"); |
1047 | #ifdef IPV6_V6ONLY | 1049 | #ifdef IPV6_V6ONLY |
1048 | if ((sa->sa_family == AF_INET6) && | 1050 | if ((sa->sa_family == AF_INET6) && |
1049 | (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (sock, | 1051 | (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(sock, |
1050 | IPPROTO_IPV6, | 1052 | IPPROTO_IPV6, |
1051 | IPV6_V6ONLY, | 1053 | IPV6_V6ONLY, |
1052 | &on, | 1054 | &on, |
1053 | sizeof (on)))) | 1055 | sizeof(on)))) |
1054 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1056 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1055 | "setsockopt"); | 1057 | "setsockopt"); |
1056 | #endif | 1058 | #endif |
1057 | #ifndef WINDOWS | 1059 | #ifndef WINDOWS |
1058 | if (AF_UNIX == sa->sa_family) | 1060 | if (AF_UNIX == sa->sa_family) |
1059 | GNUNET_NETWORK_unix_precheck ((struct sockaddr_un *) sa); | 1061 | GNUNET_NETWORK_unix_precheck((struct sockaddr_un *)sa); |
1060 | #endif | 1062 | #endif |
1061 | if (GNUNET_OK != | 1063 | if (GNUNET_OK != |
1062 | GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) sa, addr_len)) | 1064 | GNUNET_NETWORK_socket_bind(sock, (const struct sockaddr *)sa, addr_len)) |
1063 | { | 1065 | { |
1064 | GNUNET_log ( | 1066 | GNUNET_log( |
1065 | GNUNET_ERROR_TYPE_WARNING, | 1067 | GNUNET_ERROR_TYPE_WARNING, |
1066 | _ ( | 1068 | _( |
1067 | "Unable to bind listening socket for service `%s' to address `%s': %s\n"), | 1069 | "Unable to bind listening socket for service `%s' to address `%s': %s\n"), |
1068 | sl->name, | 1070 | sl->name, |
1069 | GNUNET_a2s (sa, addr_len), | 1071 | GNUNET_a2s(sa, addr_len), |
1070 | strerror (errno)); | 1072 | strerror(errno)); |
1071 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | 1073 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock)); |
1072 | GNUNET_free (sa); | 1074 | GNUNET_free(sa); |
1073 | return; | 1075 | return; |
1074 | } | 1076 | } |
1075 | #ifndef WINDOWS | 1077 | #ifndef WINDOWS |
1076 | if ((AF_UNIX == sa->sa_family) | 1078 | if ((AF_UNIX == sa->sa_family) |
1077 | #ifdef LINUX | 1079 | #ifdef LINUX |
1078 | /* Permission settings are not required when abstract sockets are used */ | 1080 | /* Permission settings are not required when abstract sockets are used */ |
1079 | && ('\0' != ((const struct sockaddr_un *) sa)->sun_path[0]) | 1081 | && ('\0' != ((const struct sockaddr_un *)sa)->sun_path[0]) |
1080 | #endif | 1082 | #endif |
1081 | ) | 1083 | ) |
1082 | { | 1084 | { |
1083 | match_uid = | 1085 | match_uid = |
1084 | GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "UNIX_MATCH_UID"); | 1086 | GNUNET_CONFIGURATION_get_value_yesno(cfg, sl->name, "UNIX_MATCH_UID"); |
1085 | match_gid = | 1087 | match_gid = |
1086 | GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "UNIX_MATCH_GID"); | 1088 | GNUNET_CONFIGURATION_get_value_yesno(cfg, sl->name, "UNIX_MATCH_GID"); |
1087 | GNUNET_DISK_fix_permissions (((const struct sockaddr_un *) sa)->sun_path, | 1089 | GNUNET_DISK_fix_permissions(((const struct sockaddr_un *)sa)->sun_path, |
1088 | match_uid, | 1090 | match_uid, |
1089 | match_gid); | 1091 | match_gid); |
1090 | } | 1092 | } |
1091 | #endif | 1093 | #endif |
1092 | if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5)) | 1094 | if (GNUNET_OK != GNUNET_NETWORK_socket_listen(sock, 5)) |
1093 | { | 1095 | { |
1094 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen"); | 1096 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "listen"); |
1095 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | 1097 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock)); |
1096 | GNUNET_free (sa); | 1098 | GNUNET_free(sa); |
1097 | return; | 1099 | return; |
1098 | } | 1100 | } |
1099 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1101 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1100 | _ ("ARM now monitors connections to service `%s' at `%s'\n"), | 1102 | _("ARM now monitors connections to service `%s' at `%s'\n"), |
1101 | sl->name, | 1103 | sl->name, |
1102 | GNUNET_a2s (sa, addr_len)); | 1104 | GNUNET_a2s(sa, addr_len)); |
1103 | sli = GNUNET_new (struct ServiceListeningInfo); | 1105 | sli = GNUNET_new(struct ServiceListeningInfo); |
1104 | sli->service_addr = sa; | 1106 | sli->service_addr = sa; |
1105 | sli->service_addr_len = addr_len; | 1107 | sli->service_addr_len = addr_len; |
1106 | sli->listen_socket = sock; | 1108 | sli->listen_socket = sock; |
1107 | sli->sl = sl; | 1109 | sli->sl = sl; |
1108 | sli->accept_task = | 1110 | sli->accept_task = |
1109 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1111 | GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, |
1110 | sock, | 1112 | sock, |
1111 | &accept_connection, | 1113 | &accept_connection, |
1112 | sli); | 1114 | sli); |
1113 | GNUNET_CONTAINER_DLL_insert (sl->listen_head, sl->listen_tail, sli); | 1115 | GNUNET_CONTAINER_DLL_insert(sl->listen_head, sl->listen_tail, sli); |
1114 | } | 1116 | } |
1115 | 1117 | ||
1116 | 1118 | ||
@@ -1121,15 +1123,15 @@ create_listen_socket (struct sockaddr *sa, | |||
1121 | * @param sl entry to free | 1123 | * @param sl entry to free |
1122 | */ | 1124 | */ |
1123 | static void | 1125 | static void |
1124 | free_service (struct ServiceList *sl) | 1126 | free_service(struct ServiceList *sl) |
1125 | { | 1127 | { |
1126 | GNUNET_assert (GNUNET_YES == in_shutdown); | 1128 | GNUNET_assert(GNUNET_YES == in_shutdown); |
1127 | GNUNET_CONTAINER_DLL_remove (running_head, running_tail, sl); | 1129 | GNUNET_CONTAINER_DLL_remove(running_head, running_tail, sl); |
1128 | GNUNET_assert (NULL == sl->listen_head); | 1130 | GNUNET_assert(NULL == sl->listen_head); |
1129 | GNUNET_free_non_null (sl->config); | 1131 | GNUNET_free_non_null(sl->config); |
1130 | GNUNET_free_non_null (sl->binary); | 1132 | GNUNET_free_non_null(sl->binary); |
1131 | GNUNET_free (sl->name); | 1133 | GNUNET_free(sl->name); |
1132 | GNUNET_free (sl); | 1134 | GNUNET_free(sl); |
1133 | } | 1135 | } |
1134 | 1136 | ||
1135 | 1137 | ||
@@ -1142,10 +1144,10 @@ free_service (struct ServiceList *sl) | |||
1142 | * #GNUNET_SYSERR to close it (signal serious error) | 1144 | * #GNUNET_SYSERR to close it (signal serious error) |
1143 | */ | 1145 | */ |
1144 | static int | 1146 | static int |
1145 | check_start (void *cls, const struct GNUNET_ARM_Message *amsg) | 1147 | check_start(void *cls, const struct GNUNET_ARM_Message *amsg) |
1146 | { | 1148 | { |
1147 | (void) cls; | 1149 | (void)cls; |
1148 | GNUNET_MQ_check_zero_termination (amsg); | 1150 | GNUNET_MQ_check_zero_termination(amsg); |
1149 | return GNUNET_OK; | 1151 | return GNUNET_OK; |
1150 | } | 1152 | } |
1151 | 1153 | ||
@@ -1157,43 +1159,43 @@ check_start (void *cls, const struct GNUNET_ARM_Message *amsg) | |||
1157 | * @param amsg the actual message | 1159 | * @param amsg the actual message |
1158 | */ | 1160 | */ |
1159 | static void | 1161 | static void |
1160 | handle_start (void *cls, const struct GNUNET_ARM_Message *amsg) | 1162 | handle_start(void *cls, const struct GNUNET_ARM_Message *amsg) |
1161 | { | 1163 | { |
1162 | struct GNUNET_SERVICE_Client *client = cls; | 1164 | struct GNUNET_SERVICE_Client *client = cls; |
1163 | const char *servicename; | 1165 | const char *servicename; |
1164 | struct ServiceList *sl; | 1166 | struct ServiceList *sl; |
1165 | uint64_t request_id; | 1167 | uint64_t request_id; |
1166 | 1168 | ||
1167 | request_id = GNUNET_ntohll (amsg->request_id); | 1169 | request_id = GNUNET_ntohll(amsg->request_id); |
1168 | servicename = (const char *) &amsg[1]; | 1170 | servicename = (const char *)&amsg[1]; |
1169 | GNUNET_SERVICE_client_continue (client); | 1171 | GNUNET_SERVICE_client_continue(client); |
1170 | if (GNUNET_YES == in_shutdown) | 1172 | if (GNUNET_YES == in_shutdown) |
1171 | { | 1173 | { |
1172 | signal_result (client, | 1174 | signal_result(client, |
1173 | servicename, | 1175 | servicename, |
1174 | request_id, | 1176 | request_id, |
1175 | GNUNET_ARM_RESULT_IN_SHUTDOWN); | 1177 | GNUNET_ARM_RESULT_IN_SHUTDOWN); |
1176 | return; | 1178 | return; |
1177 | } | 1179 | } |
1178 | sl = find_service (servicename); | 1180 | sl = find_service(servicename); |
1179 | if (NULL == sl) | 1181 | if (NULL == sl) |
1180 | { | 1182 | { |
1181 | signal_result (client, | 1183 | signal_result(client, |
1182 | servicename, | 1184 | servicename, |
1183 | request_id, | 1185 | request_id, |
1184 | GNUNET_ARM_RESULT_IS_NOT_KNOWN); | 1186 | GNUNET_ARM_RESULT_IS_NOT_KNOWN); |
1185 | return; | 1187 | return; |
1186 | } | 1188 | } |
1187 | sl->force_start = GNUNET_YES; | 1189 | sl->force_start = GNUNET_YES; |
1188 | if (NULL != sl->proc) | 1190 | if (NULL != sl->proc) |
1189 | { | 1191 | { |
1190 | signal_result (client, | 1192 | signal_result(client, |
1191 | servicename, | 1193 | servicename, |
1192 | request_id, | 1194 | request_id, |
1193 | GNUNET_ARM_RESULT_IS_STARTED_ALREADY); | 1195 | GNUNET_ARM_RESULT_IS_STARTED_ALREADY); |
1194 | return; | 1196 | return; |
1195 | } | 1197 | } |
1196 | start_process (sl, client, request_id); | 1198 | start_process(sl, client, request_id); |
1197 | } | 1199 | } |
1198 | 1200 | ||
1199 | 1201 | ||
@@ -1203,11 +1205,11 @@ handle_start (void *cls, const struct GNUNET_ARM_Message *amsg) | |||
1203 | * @param cls closure (refers to service) | 1205 | * @param cls closure (refers to service) |
1204 | */ | 1206 | */ |
1205 | static void | 1207 | static void |
1206 | trigger_shutdown (void *cls) | 1208 | trigger_shutdown(void *cls) |
1207 | { | 1209 | { |
1208 | (void) cls; | 1210 | (void)cls; |
1209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Triggering shutdown\n"); | 1211 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Triggering shutdown\n"); |
1210 | GNUNET_SCHEDULER_shutdown (); | 1212 | GNUNET_SCHEDULER_shutdown(); |
1211 | } | 1213 | } |
1212 | 1214 | ||
1213 | 1215 | ||
@@ -1220,10 +1222,10 @@ trigger_shutdown (void *cls) | |||
1220 | * #GNUNET_SYSERR to close it (signal serious error) | 1222 | * #GNUNET_SYSERR to close it (signal serious error) |
1221 | */ | 1223 | */ |
1222 | static int | 1224 | static int |
1223 | check_stop (void *cls, const struct GNUNET_ARM_Message *amsg) | 1225 | check_stop(void *cls, const struct GNUNET_ARM_Message *amsg) |
1224 | { | 1226 | { |
1225 | (void) cls; | 1227 | (void)cls; |
1226 | GNUNET_MQ_check_zero_termination (amsg); | 1228 | GNUNET_MQ_check_zero_termination(amsg); |
1227 | return GNUNET_OK; | 1229 | return GNUNET_OK; |
1228 | } | 1230 | } |
1229 | 1231 | ||
@@ -1235,72 +1237,72 @@ check_stop (void *cls, const struct GNUNET_ARM_Message *amsg) | |||
1235 | * @param amsg the actual message | 1237 | * @param amsg the actual message |
1236 | */ | 1238 | */ |
1237 | static void | 1239 | static void |
1238 | handle_stop (void *cls, const struct GNUNET_ARM_Message *amsg) | 1240 | handle_stop(void *cls, const struct GNUNET_ARM_Message *amsg) |
1239 | { | 1241 | { |
1240 | struct GNUNET_SERVICE_Client *client = cls; | 1242 | struct GNUNET_SERVICE_Client *client = cls; |
1241 | struct ServiceList *sl; | 1243 | struct ServiceList *sl; |
1242 | const char *servicename; | 1244 | const char *servicename; |
1243 | uint64_t request_id; | 1245 | uint64_t request_id; |
1244 | 1246 | ||
1245 | request_id = GNUNET_ntohll (amsg->request_id); | 1247 | request_id = GNUNET_ntohll(amsg->request_id); |
1246 | servicename = (const char *) &amsg[1]; | 1248 | servicename = (const char *)&amsg[1]; |
1247 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1249 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1248 | _ ("Preparing to stop `%s'\n"), | 1250 | _("Preparing to stop `%s'\n"), |
1249 | servicename); | 1251 | servicename); |
1250 | GNUNET_SERVICE_client_continue (client); | 1252 | GNUNET_SERVICE_client_continue(client); |
1251 | if (0 == strcasecmp (servicename, "arm")) | 1253 | if (0 == strcasecmp(servicename, "arm")) |
1252 | { | 1254 | { |
1253 | broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL); | 1255 | broadcast_status(servicename, GNUNET_ARM_SERVICE_STOPPING, NULL); |
1254 | signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_STOPPING); | 1256 | signal_result(client, servicename, request_id, GNUNET_ARM_RESULT_STOPPING); |
1255 | GNUNET_SERVICE_client_persist (client); | 1257 | GNUNET_SERVICE_client_persist(client); |
1256 | GNUNET_SCHEDULER_add_now (&trigger_shutdown, NULL); | 1258 | GNUNET_SCHEDULER_add_now(&trigger_shutdown, NULL); |
1257 | return; | 1259 | return; |
1258 | } | 1260 | } |
1259 | sl = find_service (servicename); | 1261 | sl = find_service(servicename); |
1260 | if (NULL == sl) | 1262 | if (NULL == sl) |
1261 | { | 1263 | { |
1262 | signal_result (client, | 1264 | signal_result(client, |
1263 | servicename, | 1265 | servicename, |
1264 | request_id, | 1266 | request_id, |
1265 | GNUNET_ARM_RESULT_IS_NOT_KNOWN); | 1267 | GNUNET_ARM_RESULT_IS_NOT_KNOWN); |
1266 | return; | 1268 | return; |
1267 | } | 1269 | } |
1268 | sl->force_start = GNUNET_NO; | 1270 | sl->force_start = GNUNET_NO; |
1269 | if (GNUNET_YES == in_shutdown) | 1271 | if (GNUNET_YES == in_shutdown) |
1270 | { | 1272 | { |
1271 | /* shutdown in progress */ | 1273 | /* shutdown in progress */ |
1272 | signal_result (client, | 1274 | signal_result(client, |
1273 | servicename, | 1275 | servicename, |
1274 | request_id, | 1276 | request_id, |
1275 | GNUNET_ARM_RESULT_IN_SHUTDOWN); | 1277 | GNUNET_ARM_RESULT_IN_SHUTDOWN); |
1276 | return; | 1278 | return; |
1277 | } | 1279 | } |
1278 | if (NULL != sl->killing_client) | 1280 | if (NULL != sl->killing_client) |
1279 | { | 1281 | { |
1280 | /* killing already in progress */ | 1282 | /* killing already in progress */ |
1281 | signal_result (client, | 1283 | signal_result(client, |
1282 | servicename, | 1284 | servicename, |
1283 | request_id, | 1285 | request_id, |
1284 | GNUNET_ARM_RESULT_IS_STOPPING_ALREADY); | 1286 | GNUNET_ARM_RESULT_IS_STOPPING_ALREADY); |
1285 | return; | 1287 | return; |
1286 | } | 1288 | } |
1287 | if (NULL == sl->proc) | 1289 | if (NULL == sl->proc) |
1288 | { | 1290 | { |
1289 | /* process is down */ | 1291 | /* process is down */ |
1290 | signal_result (client, | 1292 | signal_result(client, |
1291 | servicename, | 1293 | servicename, |
1292 | request_id, | 1294 | request_id, |
1293 | GNUNET_ARM_RESULT_IS_STOPPED_ALREADY); | 1295 | GNUNET_ARM_RESULT_IS_STOPPED_ALREADY); |
1294 | return; | 1296 | return; |
1295 | } | 1297 | } |
1296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1298 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1297 | "Sending kill signal to service `%s', waiting for process to die.\n", | 1299 | "Sending kill signal to service `%s', waiting for process to die.\n", |
1298 | servicename); | 1300 | servicename); |
1299 | broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL); | 1301 | broadcast_status(servicename, GNUNET_ARM_SERVICE_STOPPING, NULL); |
1300 | /* no signal_start - only when it's STOPPED */ | 1302 | /* no signal_start - only when it's STOPPED */ |
1301 | sl->killed_at = GNUNET_TIME_absolute_get (); | 1303 | sl->killed_at = GNUNET_TIME_absolute_get(); |
1302 | if (0 != GNUNET_OS_process_kill (sl->proc, GNUNET_TERM_SIG)) | 1304 | if (0 != GNUNET_OS_process_kill(sl->proc, GNUNET_TERM_SIG)) |
1303 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 1305 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); |
1304 | sl->killing_client = client; | 1306 | sl->killing_client = client; |
1305 | sl->killing_client_request_id = request_id; | 1307 | sl->killing_client_request_id = request_id; |
1306 | } | 1308 | } |
@@ -1313,7 +1315,7 @@ handle_stop (void *cls, const struct GNUNET_ARM_Message *amsg) | |||
1313 | * @param message the actual message | 1315 | * @param message the actual message |
1314 | */ | 1316 | */ |
1315 | static void | 1317 | static void |
1316 | handle_list (void *cls, const struct GNUNET_ARM_Message *request) | 1318 | handle_list(void *cls, const struct GNUNET_ARM_Message *request) |
1317 | { | 1319 | { |
1318 | struct GNUNET_SERVICE_Client *client = cls; | 1320 | struct GNUNET_SERVICE_Client *client = cls; |
1319 | struct GNUNET_MQ_Envelope *env; | 1321 | struct GNUNET_MQ_Envelope *env; |
@@ -1323,40 +1325,40 @@ handle_list (void *cls, const struct GNUNET_ARM_Message *request) | |||
1323 | uint16_t count; | 1325 | uint16_t count; |
1324 | char *pos; | 1326 | char *pos; |
1325 | 1327 | ||
1326 | GNUNET_break (0 == ntohl (request->reserved)); | 1328 | GNUNET_break(0 == ntohl(request->reserved)); |
1327 | count = 0; | 1329 | count = 0; |
1328 | string_list_size = 0; | 1330 | string_list_size = 0; |
1329 | 1331 | ||
1330 | /* first count the running processes get their name's size */ | 1332 | /* first count the running processes get their name's size */ |
1331 | for (sl = running_head; NULL != sl; sl = sl->next) | 1333 | for (sl = running_head; NULL != sl; sl = sl->next) |
1332 | { | ||
1333 | if (NULL != sl->proc) | ||
1334 | { | 1334 | { |
1335 | string_list_size += strlen (sl->name); | 1335 | if (NULL != sl->proc) |
1336 | string_list_size += strlen (sl->binary); | 1336 | { |
1337 | string_list_size += 4; | 1337 | string_list_size += strlen(sl->name); |
1338 | count++; | 1338 | string_list_size += strlen(sl->binary); |
1339 | string_list_size += 4; | ||
1340 | count++; | ||
1341 | } | ||
1339 | } | 1342 | } |
1340 | } | ||
1341 | 1343 | ||
1342 | env = GNUNET_MQ_msg_extra (msg, | 1344 | env = GNUNET_MQ_msg_extra(msg, |
1343 | string_list_size, | 1345 | string_list_size, |
1344 | GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT); | 1346 | GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT); |
1345 | msg->arm_msg.request_id = request->request_id; | 1347 | msg->arm_msg.request_id = request->request_id; |
1346 | msg->count = htons (count); | 1348 | msg->count = htons(count); |
1347 | 1349 | ||
1348 | pos = (char *) &msg[1]; | 1350 | pos = (char *)&msg[1]; |
1349 | for (sl = running_head; NULL != sl; sl = sl->next) | 1351 | for (sl = running_head; NULL != sl; sl = sl->next) |
1350 | { | ||
1351 | if (NULL != sl->proc) | ||
1352 | { | 1352 | { |
1353 | size_t s = strlen (sl->name) + strlen (sl->binary) + 4; | 1353 | if (NULL != sl->proc) |
1354 | GNUNET_snprintf (pos, s, "%s (%s)", sl->name, sl->binary); | 1354 | { |
1355 | pos += s; | 1355 | size_t s = strlen(sl->name) + strlen(sl->binary) + 4; |
1356 | GNUNET_snprintf(pos, s, "%s (%s)", sl->name, sl->binary); | ||
1357 | pos += s; | ||
1358 | } | ||
1356 | } | 1359 | } |
1357 | } | 1360 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
1358 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 1361 | GNUNET_SERVICE_client_continue(client); |
1359 | GNUNET_SERVICE_client_continue (client); | ||
1360 | } | 1362 | } |
1361 | 1363 | ||
1362 | 1364 | ||
@@ -1367,16 +1369,16 @@ handle_list (void *cls, const struct GNUNET_ARM_Message *request) | |||
1367 | * @param message the actual message | 1369 | * @param message the actual message |
1368 | */ | 1370 | */ |
1369 | static void | 1371 | static void |
1370 | handle_test (void *cls, const struct GNUNET_MessageHeader *message) | 1372 | handle_test(void *cls, const struct GNUNET_MessageHeader *message) |
1371 | { | 1373 | { |
1372 | struct GNUNET_SERVICE_Client *client = cls; | 1374 | struct GNUNET_SERVICE_Client *client = cls; |
1373 | struct GNUNET_MQ_Envelope *env; | 1375 | struct GNUNET_MQ_Envelope *env; |
1374 | struct GNUNET_MessageHeader *msg; | 1376 | struct GNUNET_MessageHeader *msg; |
1375 | 1377 | ||
1376 | (void) message; | 1378 | (void)message; |
1377 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_TEST); | 1379 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_TEST); |
1378 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 1380 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
1379 | GNUNET_SERVICE_client_continue (client); | 1381 | GNUNET_SERVICE_client_continue(client); |
1380 | } | 1382 | } |
1381 | 1383 | ||
1382 | 1384 | ||
@@ -1385,24 +1387,24 @@ handle_test (void *cls, const struct GNUNET_MessageHeader *message) | |||
1385 | * tasks, signal handler and the server. | 1387 | * tasks, signal handler and the server. |
1386 | */ | 1388 | */ |
1387 | static void | 1389 | static void |
1388 | do_shutdown () | 1390 | do_shutdown() |
1389 | { | 1391 | { |
1390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Last shutdown phase\n"); | 1392 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Last shutdown phase\n"); |
1391 | if (NULL != notifier) | 1393 | if (NULL != notifier) |
1392 | { | 1394 | { |
1393 | GNUNET_notification_context_destroy (notifier); | 1395 | GNUNET_notification_context_destroy(notifier); |
1394 | notifier = NULL; | 1396 | notifier = NULL; |
1395 | } | 1397 | } |
1396 | if (NULL != service) | 1398 | if (NULL != service) |
1397 | { | 1399 | { |
1398 | GNUNET_SERVICE_shutdown (service); | 1400 | GNUNET_SERVICE_shutdown(service); |
1399 | service = NULL; | 1401 | service = NULL; |
1400 | } | 1402 | } |
1401 | if (NULL != child_death_task) | 1403 | if (NULL != child_death_task) |
1402 | { | 1404 | { |
1403 | GNUNET_SCHEDULER_cancel (child_death_task); | 1405 | GNUNET_SCHEDULER_cancel(child_death_task); |
1404 | child_death_task = NULL; | 1406 | child_death_task = NULL; |
1405 | } | 1407 | } |
1406 | } | 1408 | } |
1407 | 1409 | ||
1408 | 1410 | ||
@@ -1413,13 +1415,13 @@ do_shutdown () | |||
1413 | * @return number of active services found | 1415 | * @return number of active services found |
1414 | */ | 1416 | */ |
1415 | static unsigned int | 1417 | static unsigned int |
1416 | list_count (struct ServiceList *running_head) | 1418 | list_count(struct ServiceList *running_head) |
1417 | { | 1419 | { |
1418 | struct ServiceList *i; | 1420 | struct ServiceList *i; |
1419 | unsigned int res; | 1421 | unsigned int res; |
1420 | 1422 | ||
1421 | for (res = 0, i = running_head; NULL != i; i = i->next, res++) | 1423 | for (res = 0, i = running_head; NULL != i; i = i->next, res++) |
1422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s\n", i->name); | 1424 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s\n", i->name); |
1423 | return res; | 1425 | return res; |
1424 | } | 1426 | } |
1425 | 1427 | ||
@@ -1430,61 +1432,61 @@ list_count (struct ServiceList *running_head) | |||
1430 | * @param cls closure, NULL if we need to self-restart | 1432 | * @param cls closure, NULL if we need to self-restart |
1431 | */ | 1433 | */ |
1432 | static void | 1434 | static void |
1433 | shutdown_task (void *cls) | 1435 | shutdown_task(void *cls) |
1434 | { | 1436 | { |
1435 | struct ServiceList *pos; | 1437 | struct ServiceList *pos; |
1436 | struct ServiceList *nxt; | 1438 | struct ServiceList *nxt; |
1437 | struct ServiceListeningInfo *sli; | 1439 | struct ServiceListeningInfo *sli; |
1438 | 1440 | ||
1439 | (void) cls; | 1441 | (void)cls; |
1440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "First shutdown phase\n"); | 1442 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "First shutdown phase\n"); |
1441 | if (NULL != child_restart_task) | 1443 | if (NULL != child_restart_task) |
1442 | { | 1444 | { |
1443 | GNUNET_SCHEDULER_cancel (child_restart_task); | 1445 | GNUNET_SCHEDULER_cancel(child_restart_task); |
1444 | child_restart_task = NULL; | 1446 | child_restart_task = NULL; |
1445 | } | 1447 | } |
1446 | in_shutdown = GNUNET_YES; | 1448 | in_shutdown = GNUNET_YES; |
1447 | /* first, stop listening */ | 1449 | /* first, stop listening */ |
1448 | for (pos = running_head; NULL != pos; pos = pos->next) | 1450 | for (pos = running_head; NULL != pos; pos = pos->next) |
1449 | { | ||
1450 | while (NULL != (sli = pos->listen_head)) | ||
1451 | { | 1451 | { |
1452 | GNUNET_CONTAINER_DLL_remove (pos->listen_head, pos->listen_tail, sli); | 1452 | while (NULL != (sli = pos->listen_head)) |
1453 | if (NULL != sli->accept_task) | 1453 | { |
1454 | { | 1454 | GNUNET_CONTAINER_DLL_remove(pos->listen_head, pos->listen_tail, sli); |
1455 | GNUNET_SCHEDULER_cancel (sli->accept_task); | 1455 | if (NULL != sli->accept_task) |
1456 | sli->accept_task = NULL; | 1456 | { |
1457 | } | 1457 | GNUNET_SCHEDULER_cancel(sli->accept_task); |
1458 | GNUNET_break (GNUNET_OK == | 1458 | sli->accept_task = NULL; |
1459 | GNUNET_NETWORK_socket_close (sli->listen_socket)); | 1459 | } |
1460 | GNUNET_free (sli->service_addr); | 1460 | GNUNET_break(GNUNET_OK == |
1461 | GNUNET_free (sli); | 1461 | GNUNET_NETWORK_socket_close(sli->listen_socket)); |
1462 | GNUNET_free(sli->service_addr); | ||
1463 | GNUNET_free(sli); | ||
1464 | } | ||
1462 | } | 1465 | } |
1463 | } | ||
1464 | /* then, shutdown all existing service processes */ | 1466 | /* then, shutdown all existing service processes */ |
1465 | nxt = running_head; | 1467 | nxt = running_head; |
1466 | while (NULL != (pos = nxt)) | 1468 | while (NULL != (pos = nxt)) |
1467 | { | ||
1468 | nxt = pos->next; | ||
1469 | if (NULL != pos->proc) | ||
1470 | { | ||
1471 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n", pos->name); | ||
1472 | pos->killed_at = GNUNET_TIME_absolute_get (); | ||
1473 | if (0 != GNUNET_OS_process_kill (pos->proc, GNUNET_TERM_SIG)) | ||
1474 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
1475 | } | ||
1476 | else | ||
1477 | { | 1469 | { |
1478 | free_service (pos); | 1470 | nxt = pos->next; |
1471 | if (NULL != pos->proc) | ||
1472 | { | ||
1473 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n", pos->name); | ||
1474 | pos->killed_at = GNUNET_TIME_absolute_get(); | ||
1475 | if (0 != GNUNET_OS_process_kill(pos->proc, GNUNET_TERM_SIG)) | ||
1476 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
1477 | } | ||
1478 | else | ||
1479 | { | ||
1480 | free_service(pos); | ||
1481 | } | ||
1479 | } | 1482 | } |
1480 | } | ||
1481 | /* finally, should all service processes be already gone, terminate for real */ | 1483 | /* finally, should all service processes be already gone, terminate for real */ |
1482 | if (NULL == running_head) | 1484 | if (NULL == running_head) |
1483 | do_shutdown (); | 1485 | do_shutdown(); |
1484 | else | 1486 | else |
1485 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1487 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1486 | "Delaying shutdown, have %u childs still running\n", | 1488 | "Delaying shutdown, have %u childs still running\n", |
1487 | list_count (running_head)); | 1489 | list_count(running_head)); |
1488 | } | 1490 | } |
1489 | 1491 | ||
1490 | 1492 | ||
@@ -1494,73 +1496,73 @@ shutdown_task (void *cls) | |||
1494 | * @param cls closure, always NULL | 1496 | * @param cls closure, always NULL |
1495 | */ | 1497 | */ |
1496 | static void | 1498 | static void |
1497 | delayed_restart_task (void *cls) | 1499 | delayed_restart_task(void *cls) |
1498 | 1500 | ||
1499 | { | 1501 | { |
1500 | struct ServiceList *sl; | 1502 | struct ServiceList *sl; |
1501 | struct GNUNET_TIME_Relative lowestRestartDelay; | 1503 | struct GNUNET_TIME_Relative lowestRestartDelay; |
1502 | struct ServiceListeningInfo *sli; | 1504 | struct ServiceListeningInfo *sli; |
1503 | 1505 | ||
1504 | (void) cls; | 1506 | (void)cls; |
1505 | child_restart_task = NULL; | 1507 | child_restart_task = NULL; |
1506 | GNUNET_assert (GNUNET_NO == in_shutdown); | 1508 | GNUNET_assert(GNUNET_NO == in_shutdown); |
1507 | lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL; | 1509 | lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL; |
1508 | 1510 | ||
1509 | /* check for services that need to be restarted due to | 1511 | /* check for services that need to be restarted due to |
1510 | * configuration changes or because the last restart failed */ | 1512 | * configuration changes or because the last restart failed */ |
1511 | for (sl = running_head; NULL != sl; sl = sl->next) | 1513 | for (sl = running_head; NULL != sl; sl = sl->next) |
1512 | { | ||
1513 | if (NULL != sl->proc) | ||
1514 | continue; | ||
1515 | /* service is currently not running */ | ||
1516 | if (0 == GNUNET_TIME_absolute_get_remaining (sl->restart_at).rel_value_us) | ||
1517 | { | 1514 | { |
1518 | /* restart is now allowed */ | 1515 | if (NULL != sl->proc) |
1519 | if (sl->force_start) | 1516 | continue; |
1520 | { | 1517 | /* service is currently not running */ |
1521 | /* process should run by default, start immediately */ | 1518 | if (0 == GNUNET_TIME_absolute_get_remaining(sl->restart_at).rel_value_us) |
1522 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1519 | { |
1523 | _ ("Restarting service `%s'.\n"), | 1520 | /* restart is now allowed */ |
1524 | sl->name); | 1521 | if (sl->force_start) |
1525 | start_process (sl, NULL, 0); | 1522 | { |
1526 | } | 1523 | /* process should run by default, start immediately */ |
1524 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1525 | _("Restarting service `%s'.\n"), | ||
1526 | sl->name); | ||
1527 | start_process(sl, NULL, 0); | ||
1528 | } | ||
1529 | else | ||
1530 | { | ||
1531 | /* process is run on-demand, ensure it is re-started if there is demand */ | ||
1532 | for (sli = sl->listen_head; NULL != sli; sli = sli->next) | ||
1533 | if (NULL == sli->accept_task) | ||
1534 | { | ||
1535 | /* accept was actually paused, so start it again */ | ||
1536 | sli->accept_task = | ||
1537 | GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, | ||
1538 | sli->listen_socket, | ||
1539 | &accept_connection, | ||
1540 | sli); | ||
1541 | } | ||
1542 | } | ||
1543 | } | ||
1527 | else | 1544 | else |
1528 | { | 1545 | { |
1529 | /* process is run on-demand, ensure it is re-started if there is demand */ | 1546 | /* update calculation for earliest time to reactivate a service */ |
1530 | for (sli = sl->listen_head; NULL != sli; sli = sli->next) | 1547 | lowestRestartDelay = |
1531 | if (NULL == sli->accept_task) | 1548 | GNUNET_TIME_relative_min(lowestRestartDelay, |
1532 | { | 1549 | GNUNET_TIME_absolute_get_remaining( |
1533 | /* accept was actually paused, so start it again */ | 1550 | sl->restart_at)); |
1534 | sli->accept_task = | 1551 | } |
1535 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | ||
1536 | sli->listen_socket, | ||
1537 | &accept_connection, | ||
1538 | sli); | ||
1539 | } | ||
1540 | } | ||
1541 | } | ||
1542 | else | ||
1543 | { | ||
1544 | /* update calculation for earliest time to reactivate a service */ | ||
1545 | lowestRestartDelay = | ||
1546 | GNUNET_TIME_relative_min (lowestRestartDelay, | ||
1547 | GNUNET_TIME_absolute_get_remaining ( | ||
1548 | sl->restart_at)); | ||
1549 | } | 1552 | } |
1550 | } | ||
1551 | if (lowestRestartDelay.rel_value_us != | 1553 | if (lowestRestartDelay.rel_value_us != |
1552 | GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) | 1554 | GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) |
1553 | { | 1555 | { |
1554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1556 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1555 | "Will restart process in %s\n", | 1557 | "Will restart process in %s\n", |
1556 | GNUNET_STRINGS_relative_time_to_string (lowestRestartDelay, | 1558 | GNUNET_STRINGS_relative_time_to_string(lowestRestartDelay, |
1557 | GNUNET_YES)); | 1559 | GNUNET_YES)); |
1558 | child_restart_task = | 1560 | child_restart_task = |
1559 | GNUNET_SCHEDULER_add_delayed_with_priority (lowestRestartDelay, | 1561 | GNUNET_SCHEDULER_add_delayed_with_priority(lowestRestartDelay, |
1560 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 1562 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
1561 | &delayed_restart_task, | 1563 | &delayed_restart_task, |
1562 | NULL); | 1564 | NULL); |
1563 | } | 1565 | } |
1564 | } | 1566 | } |
1565 | 1567 | ||
1566 | 1568 | ||
@@ -1571,7 +1573,7 @@ delayed_restart_task (void *cls) | |||
1571 | * @param cls closure, NULL | 1573 | * @param cls closure, NULL |
1572 | */ | 1574 | */ |
1573 | static void | 1575 | static void |
1574 | maint_child_death (void *cls) | 1576 | maint_child_death(void *cls) |
1575 | { | 1577 | { |
1576 | struct ServiceList *pos; | 1578 | struct ServiceList *pos; |
1577 | struct ServiceList *next; | 1579 | struct ServiceList *next; |
@@ -1584,199 +1586,199 @@ maint_child_death (void *cls) | |||
1584 | unsigned long statusCode; | 1586 | unsigned long statusCode; |
1585 | const struct GNUNET_DISK_FileHandle *pr; | 1587 | const struct GNUNET_DISK_FileHandle *pr; |
1586 | 1588 | ||
1587 | (void) cls; | 1589 | (void)cls; |
1588 | pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); | 1590 | pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); |
1589 | child_death_task = NULL; | 1591 | child_death_task = NULL; |
1590 | /* consume the signal */ | 1592 | /* consume the signal */ |
1591 | GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); | 1593 | GNUNET_break(0 < GNUNET_DISK_file_read(pr, &c, sizeof(c))); |
1592 | 1594 | ||
1593 | /* check for services that died (WAITPID) */ | 1595 | /* check for services that died (WAITPID) */ |
1594 | next = running_head; | 1596 | next = running_head; |
1595 | while (NULL != (pos = next)) | 1597 | while (NULL != (pos = next)) |
1596 | { | ||
1597 | next = pos->next; | ||
1598 | |||
1599 | if (NULL == pos->proc) | ||
1600 | { | 1598 | { |
1601 | if (GNUNET_YES == in_shutdown) | 1599 | next = pos->next; |
1602 | free_service (pos); | 1600 | |
1603 | continue; | 1601 | if (NULL == pos->proc) |
1604 | } | 1602 | { |
1603 | if (GNUNET_YES == in_shutdown) | ||
1604 | free_service(pos); | ||
1605 | continue; | ||
1606 | } | ||
1605 | #if HAVE_WAIT4 | 1607 | #if HAVE_WAIT4 |
1606 | if (NULL != wait_file) | 1608 | if (NULL != wait_file) |
1607 | { | 1609 | { |
1608 | /* need to use 'wait4()' to obtain and log performance data */ | 1610 | /* need to use 'wait4()' to obtain and log performance data */ |
1609 | struct rusage ru; | 1611 | struct rusage ru; |
1610 | int status; | 1612 | int status; |
1611 | pid_t pid; | 1613 | pid_t pid; |
1612 | 1614 | ||
1613 | pid = GNUNET_OS_process_get_pid (pos->proc); | 1615 | pid = GNUNET_OS_process_get_pid(pos->proc); |
1614 | ret = wait4 (pid, &status, WNOHANG, &ru); | 1616 | ret = wait4(pid, &status, WNOHANG, &ru); |
1615 | if (ret <= 0) | 1617 | if (ret <= 0) |
1616 | continue; /* no process done */ | 1618 | continue; /* no process done */ |
1617 | if (WIFEXITED (status)) | 1619 | if (WIFEXITED(status)) |
1618 | { | 1620 | { |
1619 | statusType = GNUNET_OS_PROCESS_EXITED; | 1621 | statusType = GNUNET_OS_PROCESS_EXITED; |
1620 | statusCode = WEXITSTATUS (status); | 1622 | statusCode = WEXITSTATUS(status); |
1621 | } | 1623 | } |
1622 | else if (WIFSIGNALED (status)) | 1624 | else if (WIFSIGNALED(status)) |
1623 | { | 1625 | { |
1624 | statusType = GNUNET_OS_PROCESS_SIGNALED; | 1626 | statusType = GNUNET_OS_PROCESS_SIGNALED; |
1625 | statusCode = WTERMSIG (status); | 1627 | statusCode = WTERMSIG(status); |
1626 | } | 1628 | } |
1627 | else if (WIFSTOPPED (status)) | 1629 | else if (WIFSTOPPED(status)) |
1628 | { | 1630 | { |
1629 | statusType = GNUNET_OS_PROCESS_SIGNALED; | 1631 | statusType = GNUNET_OS_PROCESS_SIGNALED; |
1630 | statusCode = WSTOPSIG (status); | 1632 | statusCode = WSTOPSIG(status); |
1631 | } | 1633 | } |
1632 | #ifdef WIFCONTINUED | 1634 | #ifdef WIFCONTINUED |
1633 | else if (WIFCONTINUED (status)) | 1635 | else if (WIFCONTINUED(status)) |
1634 | { | 1636 | { |
1635 | statusType = GNUNET_OS_PROCESS_RUNNING; | 1637 | statusType = GNUNET_OS_PROCESS_RUNNING; |
1636 | statusCode = 0; | 1638 | statusCode = 0; |
1637 | } | 1639 | } |
1638 | #endif | 1640 | #endif |
1639 | else | 1641 | else |
1640 | { | 1642 | { |
1641 | statusType = GNUNET_OS_PROCESS_UNKNOWN; | 1643 | statusType = GNUNET_OS_PROCESS_UNKNOWN; |
1642 | statusCode = 0; | 1644 | statusCode = 0; |
1643 | } | 1645 | } |
1644 | if ((GNUNET_OS_PROCESS_EXITED == statusType) || | 1646 | if ((GNUNET_OS_PROCESS_EXITED == statusType) || |
1645 | (GNUNET_OS_PROCESS_SIGNALED == statusType)) | 1647 | (GNUNET_OS_PROCESS_SIGNALED == statusType)) |
1646 | { | 1648 | { |
1647 | double utime = ru.ru_utime.tv_sec + (ru.ru_utime.tv_usec / 10e6); | 1649 | double utime = ru.ru_utime.tv_sec + (ru.ru_utime.tv_usec / 10e6); |
1648 | double stime = ru.ru_stime.tv_sec + (ru.ru_stime.tv_usec / 10e6); | 1650 | double stime = ru.ru_stime.tv_sec + (ru.ru_stime.tv_usec / 10e6); |
1649 | fprintf (wait_file, | 1651 | fprintf(wait_file, |
1650 | "%s(%u) %.3f %.3f %llu %llu %llu %llu %llu\n", | 1652 | "%s(%u) %.3f %.3f %llu %llu %llu %llu %llu\n", |
1651 | pos->binary, | 1653 | pos->binary, |
1652 | (unsigned int) pid, | 1654 | (unsigned int)pid, |
1653 | utime, | 1655 | utime, |
1654 | stime, | 1656 | stime, |
1655 | (unsigned long long) ru.ru_maxrss, | 1657 | (unsigned long long)ru.ru_maxrss, |
1656 | (unsigned long long) ru.ru_inblock, | 1658 | (unsigned long long)ru.ru_inblock, |
1657 | (unsigned long long) ru.ru_oublock, | 1659 | (unsigned long long)ru.ru_oublock, |
1658 | (unsigned long long) ru.ru_nvcsw, | 1660 | (unsigned long long)ru.ru_nvcsw, |
1659 | (unsigned long long) ru.ru_nivcsw); | 1661 | (unsigned long long)ru.ru_nivcsw); |
1660 | } | 1662 | } |
1661 | } | 1663 | } |
1662 | else /* continue with JUST this "if" as "else" (intentionally no brackets!) */ | 1664 | else /* continue with JUST this "if" as "else" (intentionally no brackets!) */ |
1663 | #endif | 1665 | #endif |
1664 | if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc, | 1666 | if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status(pos->proc, |
1665 | &statusType, | 1667 | &statusType, |
1666 | &statusCode))) || | 1668 | &statusCode))) || |
1667 | (ret == GNUNET_NO) || (statusType == GNUNET_OS_PROCESS_STOPPED) || | 1669 | (ret == GNUNET_NO) || (statusType == GNUNET_OS_PROCESS_STOPPED) || |
1668 | (statusType == GNUNET_OS_PROCESS_UNKNOWN) || | 1670 | (statusType == GNUNET_OS_PROCESS_UNKNOWN) || |
1669 | (statusType == GNUNET_OS_PROCESS_RUNNING)) | 1671 | (statusType == GNUNET_OS_PROCESS_RUNNING)) |
1670 | continue; | 1672 | continue; |
1671 | 1673 | ||
1672 | if (statusType == GNUNET_OS_PROCESS_EXITED) | 1674 | if (statusType == GNUNET_OS_PROCESS_EXITED) |
1673 | { | ||
1674 | statstr = _ (/* process termination method */ "exit"); | ||
1675 | statcode = statusCode; | ||
1676 | } | ||
1677 | else if (statusType == GNUNET_OS_PROCESS_SIGNALED) | ||
1678 | { | ||
1679 | statstr = _ (/* process termination method */ "signal"); | ||
1680 | statcode = statusCode; | ||
1681 | } | ||
1682 | else | ||
1683 | { | ||
1684 | statstr = _ (/* process termination method */ "unknown"); | ||
1685 | statcode = 0; | ||
1686 | } | ||
1687 | if (0 != pos->killed_at.abs_value_us) | ||
1688 | { | ||
1689 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1690 | _ ("Service `%s' took %s to terminate\n"), | ||
1691 | pos->name, | ||
1692 | GNUNET_STRINGS_relative_time_to_string ( | ||
1693 | GNUNET_TIME_absolute_get_duration (pos->killed_at), | ||
1694 | GNUNET_YES)); | ||
1695 | } | ||
1696 | GNUNET_OS_process_destroy (pos->proc); | ||
1697 | pos->proc = NULL; | ||
1698 | broadcast_status (pos->name, GNUNET_ARM_SERVICE_STOPPED, NULL); | ||
1699 | if (NULL != pos->killing_client) | ||
1700 | { | ||
1701 | signal_result (pos->killing_client, | ||
1702 | pos->name, | ||
1703 | pos->killing_client_request_id, | ||
1704 | GNUNET_ARM_RESULT_STOPPED); | ||
1705 | pos->killing_client = NULL; | ||
1706 | pos->killing_client_request_id = 0; | ||
1707 | } | ||
1708 | if (GNUNET_YES != in_shutdown) | ||
1709 | { | ||
1710 | if ((statusType == GNUNET_OS_PROCESS_EXITED) && (statcode == 0)) | ||
1711 | { | ||
1712 | /* process terminated normally, allow restart at any time */ | ||
1713 | pos->restart_at.abs_value_us = 0; | ||
1714 | GNUNET_log ( | ||
1715 | GNUNET_ERROR_TYPE_INFO, | ||
1716 | _ ("Service `%s' terminated normally, will restart at any time\n"), | ||
1717 | pos->name); | ||
1718 | /* process can still be re-started on-demand, ensure it is re-started if there is demand */ | ||
1719 | for (sli = pos->listen_head; NULL != sli; sli = sli->next) | ||
1720 | { | 1675 | { |
1721 | GNUNET_break (NULL == sli->accept_task); | 1676 | statstr = _(/* process termination method */ "exit"); |
1722 | sli->accept_task = | 1677 | statcode = statusCode; |
1723 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1678 | } |
1724 | sli->listen_socket, | 1679 | else if (statusType == GNUNET_OS_PROCESS_SIGNALED) |
1725 | &accept_connection, | 1680 | { |
1726 | sli); | 1681 | statstr = _(/* process termination method */ "signal"); |
1682 | statcode = statusCode; | ||
1727 | } | 1683 | } |
1728 | } | ||
1729 | else | 1684 | else |
1730 | { | ||
1731 | GNUNET_log ( | ||
1732 | GNUNET_ERROR_TYPE_INFO, | ||
1733 | _ ("Service `%s' terminated with status %s/%d, will restart in %s\n"), | ||
1734 | pos->name, | ||
1735 | statstr, | ||
1736 | statcode, | ||
1737 | GNUNET_STRINGS_relative_time_to_string (pos->backoff, GNUNET_YES)); | ||
1738 | { | 1685 | { |
1739 | /* Reduce backoff based on runtime of the process, | 1686 | statstr = _(/* process termination method */ "unknown"); |
1740 | so that there is a cool-down if a process actually | 1687 | statcode = 0; |
1741 | runs for a while. */ | 1688 | } |
1742 | struct GNUNET_TIME_Relative runtime; | 1689 | if (0 != pos->killed_at.abs_value_us) |
1743 | unsigned int minutes; | 1690 | { |
1744 | 1691 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | |
1745 | runtime = GNUNET_TIME_absolute_get_duration (pos->restart_at); | 1692 | _("Service `%s' took %s to terminate\n"), |
1746 | minutes = | 1693 | pos->name, |
1747 | runtime.rel_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us; | 1694 | GNUNET_STRINGS_relative_time_to_string( |
1748 | if (minutes > 31) | 1695 | GNUNET_TIME_absolute_get_duration(pos->killed_at), |
1749 | pos->backoff = GNUNET_TIME_UNIT_ZERO; | 1696 | GNUNET_YES)); |
1697 | } | ||
1698 | GNUNET_OS_process_destroy(pos->proc); | ||
1699 | pos->proc = NULL; | ||
1700 | broadcast_status(pos->name, GNUNET_ARM_SERVICE_STOPPED, NULL); | ||
1701 | if (NULL != pos->killing_client) | ||
1702 | { | ||
1703 | signal_result(pos->killing_client, | ||
1704 | pos->name, | ||
1705 | pos->killing_client_request_id, | ||
1706 | GNUNET_ARM_RESULT_STOPPED); | ||
1707 | pos->killing_client = NULL; | ||
1708 | pos->killing_client_request_id = 0; | ||
1709 | } | ||
1710 | if (GNUNET_YES != in_shutdown) | ||
1711 | { | ||
1712 | if ((statusType == GNUNET_OS_PROCESS_EXITED) && (statcode == 0)) | ||
1713 | { | ||
1714 | /* process terminated normally, allow restart at any time */ | ||
1715 | pos->restart_at.abs_value_us = 0; | ||
1716 | GNUNET_log( | ||
1717 | GNUNET_ERROR_TYPE_INFO, | ||
1718 | _("Service `%s' terminated normally, will restart at any time\n"), | ||
1719 | pos->name); | ||
1720 | /* process can still be re-started on-demand, ensure it is re-started if there is demand */ | ||
1721 | for (sli = pos->listen_head; NULL != sli; sli = sli->next) | ||
1722 | { | ||
1723 | GNUNET_break(NULL == sli->accept_task); | ||
1724 | sli->accept_task = | ||
1725 | GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, | ||
1726 | sli->listen_socket, | ||
1727 | &accept_connection, | ||
1728 | sli); | ||
1729 | } | ||
1730 | } | ||
1750 | else | 1731 | else |
1751 | pos->backoff.rel_value_us <<= minutes; | 1732 | { |
1733 | GNUNET_log( | ||
1734 | GNUNET_ERROR_TYPE_INFO, | ||
1735 | _("Service `%s' terminated with status %s/%d, will restart in %s\n"), | ||
1736 | pos->name, | ||
1737 | statstr, | ||
1738 | statcode, | ||
1739 | GNUNET_STRINGS_relative_time_to_string(pos->backoff, GNUNET_YES)); | ||
1740 | { | ||
1741 | /* Reduce backoff based on runtime of the process, | ||
1742 | so that there is a cool-down if a process actually | ||
1743 | runs for a while. */ | ||
1744 | struct GNUNET_TIME_Relative runtime; | ||
1745 | unsigned int minutes; | ||
1746 | |||
1747 | runtime = GNUNET_TIME_absolute_get_duration(pos->restart_at); | ||
1748 | minutes = | ||
1749 | runtime.rel_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us; | ||
1750 | if (minutes > 31) | ||
1751 | pos->backoff = GNUNET_TIME_UNIT_ZERO; | ||
1752 | else | ||
1753 | pos->backoff.rel_value_us <<= minutes; | ||
1754 | } | ||
1755 | /* schedule restart */ | ||
1756 | pos->restart_at = GNUNET_TIME_relative_to_absolute(pos->backoff); | ||
1757 | pos->backoff = GNUNET_TIME_STD_BACKOFF(pos->backoff); | ||
1758 | if (NULL != child_restart_task) | ||
1759 | GNUNET_SCHEDULER_cancel(child_restart_task); | ||
1760 | child_restart_task = | ||
1761 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
1762 | &delayed_restart_task, | ||
1763 | NULL); | ||
1764 | } | ||
1765 | } | ||
1766 | else | ||
1767 | { | ||
1768 | free_service(pos); | ||
1752 | } | 1769 | } |
1753 | /* schedule restart */ | ||
1754 | pos->restart_at = GNUNET_TIME_relative_to_absolute (pos->backoff); | ||
1755 | pos->backoff = GNUNET_TIME_STD_BACKOFF (pos->backoff); | ||
1756 | if (NULL != child_restart_task) | ||
1757 | GNUNET_SCHEDULER_cancel (child_restart_task); | ||
1758 | child_restart_task = | ||
1759 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
1760 | &delayed_restart_task, | ||
1761 | NULL); | ||
1762 | } | ||
1763 | } | ||
1764 | else | ||
1765 | { | ||
1766 | free_service (pos); | ||
1767 | } | 1770 | } |
1768 | } | ||
1769 | child_death_task = | 1771 | child_death_task = |
1770 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 1772 | GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
1771 | pr, | 1773 | pr, |
1772 | &maint_child_death, | 1774 | &maint_child_death, |
1773 | NULL); | 1775 | NULL); |
1774 | if ((NULL == running_head) && (GNUNET_YES == in_shutdown)) | 1776 | if ((NULL == running_head) && (GNUNET_YES == in_shutdown)) |
1775 | do_shutdown (); | 1777 | do_shutdown(); |
1776 | else if (GNUNET_YES == in_shutdown) | 1778 | else if (GNUNET_YES == in_shutdown) |
1777 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1779 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1778 | "Delaying shutdown after child's death, still have %u children\n", | 1780 | "Delaying shutdown after child's death, still have %u children\n", |
1779 | list_count (running_head)); | 1781 | list_count(running_head)); |
1780 | } | 1782 | } |
1781 | 1783 | ||
1782 | 1784 | ||
@@ -1785,17 +1787,17 @@ maint_child_death (void *cls) | |||
1785 | * respective handler by writing to the trigger pipe. | 1787 | * respective handler by writing to the trigger pipe. |
1786 | */ | 1788 | */ |
1787 | static void | 1789 | static void |
1788 | sighandler_child_death () | 1790 | sighandler_child_death() |
1789 | { | 1791 | { |
1790 | static char c; | 1792 | static char c; |
1791 | int old_errno = errno; /* back-up errno */ | 1793 | int old_errno = errno; /* back-up errno */ |
1792 | 1794 | ||
1793 | GNUNET_break ( | 1795 | GNUNET_break( |
1794 | 1 == | 1796 | 1 == |
1795 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, | 1797 | GNUNET_DISK_file_write(GNUNET_DISK_pipe_handle(sigpipe, |
1796 | GNUNET_DISK_PIPE_END_WRITE), | 1798 | GNUNET_DISK_PIPE_END_WRITE), |
1797 | &c, | 1799 | &c, |
1798 | sizeof (c))); | 1800 | sizeof(c))); |
1799 | errno = old_errno; /* restore errno */ | 1801 | errno = old_errno; /* restore errno */ |
1800 | } | 1802 | } |
1801 | 1803 | ||
@@ -1809,7 +1811,7 @@ sighandler_child_death () | |||
1809 | * @return #GNUNET_OK (continue) | 1811 | * @return #GNUNET_OK (continue) |
1810 | */ | 1812 | */ |
1811 | static void | 1813 | static void |
1812 | setup_service (void *cls, const char *section) | 1814 | setup_service(void *cls, const char *section) |
1813 | { | 1815 | { |
1814 | struct ServiceList *sl; | 1816 | struct ServiceList *sl; |
1815 | char *binary; | 1817 | char *binary; |
@@ -1819,65 +1821,65 @@ setup_service (void *cls, const char *section) | |||
1819 | socklen_t *addr_lens; | 1821 | socklen_t *addr_lens; |
1820 | int ret; | 1822 | int ret; |
1821 | 1823 | ||
1822 | (void) cls; | 1824 | (void)cls; |
1823 | if (0 == strcasecmp (section, "arm")) | 1825 | if (0 == strcasecmp(section, "arm")) |
1824 | return; | 1826 | return; |
1825 | if (GNUNET_OK != | 1827 | if (GNUNET_OK != |
1826 | GNUNET_CONFIGURATION_get_value_string (cfg, section, "BINARY", &binary)) | 1828 | GNUNET_CONFIGURATION_get_value_string(cfg, section, "BINARY", &binary)) |
1827 | { | 1829 | { |
1828 | /* not a service section */ | 1830 | /* not a service section */ |
1829 | return; | 1831 | return; |
1830 | } | 1832 | } |
1831 | if ((GNUNET_YES == | 1833 | if ((GNUNET_YES == |
1832 | GNUNET_CONFIGURATION_have_value (cfg, section, "RUN_PER_USER")) && | 1834 | GNUNET_CONFIGURATION_have_value(cfg, section, "RUN_PER_USER")) && |
1833 | (GNUNET_YES == | 1835 | (GNUNET_YES == |
1834 | GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "RUN_PER_USER"))) | 1836 | GNUNET_CONFIGURATION_get_value_yesno(cfg, section, "RUN_PER_USER"))) |
1835 | { | ||
1836 | if (GNUNET_NO == start_user) | ||
1837 | { | 1837 | { |
1838 | GNUNET_free (binary); | 1838 | if (GNUNET_NO == start_user) |
1839 | return; /* user service, and we don't deal with those */ | 1839 | { |
1840 | GNUNET_free(binary); | ||
1841 | return; /* user service, and we don't deal with those */ | ||
1842 | } | ||
1840 | } | 1843 | } |
1841 | } | ||
1842 | else | 1844 | else |
1843 | { | ||
1844 | if (GNUNET_NO == start_system) | ||
1845 | { | 1845 | { |
1846 | GNUNET_free (binary); | 1846 | if (GNUNET_NO == start_system) |
1847 | return; /* system service, and we don't deal with those */ | 1847 | { |
1848 | GNUNET_free(binary); | ||
1849 | return; /* system service, and we don't deal with those */ | ||
1850 | } | ||
1848 | } | 1851 | } |
1849 | } | 1852 | sl = find_service(section); |
1850 | sl = find_service (section); | ||
1851 | if (NULL != sl) | 1853 | if (NULL != sl) |
1852 | { | 1854 | { |
1853 | /* got the same section twice!? */ | 1855 | /* got the same section twice!? */ |
1854 | GNUNET_break (0); | 1856 | GNUNET_break(0); |
1855 | GNUNET_free (binary); | 1857 | GNUNET_free(binary); |
1856 | return; | 1858 | return; |
1857 | } | 1859 | } |
1858 | config = NULL; | 1860 | config = NULL; |
1859 | if (((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, | 1861 | if (((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, |
1860 | section, | 1862 | section, |
1861 | "CONFIG", | 1863 | "CONFIG", |
1862 | &config)) && | 1864 | &config)) && |
1863 | (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, | 1865 | (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, |
1864 | "PATHS", | 1866 | "PATHS", |
1865 | "DEFAULTCONFIG", | 1867 | "DEFAULTCONFIG", |
1866 | &config))) || | 1868 | &config))) || |
1867 | (0 != stat (config, &sbuf))) | 1869 | (0 != stat(config, &sbuf))) |
1868 | { | ||
1869 | if (NULL != config) | ||
1870 | { | 1870 | { |
1871 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, | 1871 | if (NULL != config) |
1872 | section, | 1872 | { |
1873 | "CONFIG", | 1873 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, |
1874 | strerror (errno)); | 1874 | section, |
1875 | GNUNET_free (config); | 1875 | "CONFIG", |
1876 | config = NULL; | 1876 | strerror(errno)); |
1877 | GNUNET_free(config); | ||
1878 | config = NULL; | ||
1879 | } | ||
1877 | } | 1880 | } |
1878 | } | 1881 | sl = GNUNET_new(struct ServiceList); |
1879 | sl = GNUNET_new (struct ServiceList); | 1882 | sl->name = GNUNET_strdup(section); |
1880 | sl->name = GNUNET_strdup (section); | ||
1881 | sl->binary = binary; | 1883 | sl->binary = binary; |
1882 | sl->config = config; | 1884 | sl->config = config; |
1883 | sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 1885 | sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
@@ -1885,32 +1887,32 @@ setup_service (void *cls, const char *section) | |||
1885 | #if WINDOWS | 1887 | #if WINDOWS |
1886 | sl->pipe_control = GNUNET_YES; | 1888 | sl->pipe_control = GNUNET_YES; |
1887 | #else | 1889 | #else |
1888 | if (GNUNET_CONFIGURATION_have_value (cfg, section, "PIPECONTROL")) | 1890 | if (GNUNET_CONFIGURATION_have_value(cfg, section, "PIPECONTROL")) |
1889 | sl->pipe_control = | 1891 | sl->pipe_control = |
1890 | GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "PIPECONTROL"); | 1892 | GNUNET_CONFIGURATION_get_value_yesno(cfg, section, "PIPECONTROL"); |
1891 | #endif | 1893 | #endif |
1892 | GNUNET_CONTAINER_DLL_insert (running_head, running_tail, sl); | 1894 | GNUNET_CONTAINER_DLL_insert(running_head, running_tail, sl); |
1893 | if (GNUNET_YES == | 1895 | if (GNUNET_YES == |
1894 | GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "IMMEDIATE_START")) | 1896 | GNUNET_CONFIGURATION_get_value_yesno(cfg, section, "IMMEDIATE_START")) |
1895 | { | 1897 | { |
1896 | sl->force_start = GNUNET_YES; | 1898 | sl->force_start = GNUNET_YES; |
1897 | if (GNUNET_YES == | 1899 | if (GNUNET_YES == |
1898 | GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "NOARMBIND")) | 1900 | GNUNET_CONFIGURATION_get_value_yesno(cfg, section, "NOARMBIND")) |
1899 | return; | 1901 | return; |
1900 | } | 1902 | } |
1901 | else | 1903 | else |
1902 | { | 1904 | { |
1903 | if (GNUNET_YES != | 1905 | if (GNUNET_YES != |
1904 | GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "START_ON_DEMAND")) | 1906 | GNUNET_CONFIGURATION_get_value_yesno(cfg, section, "START_ON_DEMAND")) |
1905 | return; | 1907 | return; |
1906 | } | 1908 | } |
1907 | if (0 >= (ret = get_server_addresses (section, cfg, &addrs, &addr_lens))) | 1909 | if (0 >= (ret = get_server_addresses(section, cfg, &addrs, &addr_lens))) |
1908 | return; | 1910 | return; |
1909 | /* this will free (or capture) addrs[i] */ | 1911 | /* this will free (or capture) addrs[i] */ |
1910 | for (unsigned int i = 0; i < (unsigned int) ret; i++) | 1912 | for (unsigned int i = 0; i < (unsigned int)ret; i++) |
1911 | create_listen_socket (addrs[i], addr_lens[i], sl); | 1913 | create_listen_socket(addrs[i], addr_lens[i], sl); |
1912 | GNUNET_free (addrs); | 1914 | GNUNET_free(addrs); |
1913 | GNUNET_free (addr_lens); | 1915 | GNUNET_free(addr_lens); |
1914 | } | 1916 | } |
1915 | 1917 | ||
1916 | 1918 | ||
@@ -1923,16 +1925,16 @@ setup_service (void *cls, const char *section) | |||
1923 | * @return @a client | 1925 | * @return @a client |
1924 | */ | 1926 | */ |
1925 | static void * | 1927 | static void * |
1926 | client_connect_cb (void *cls, | 1928 | client_connect_cb(void *cls, |
1927 | struct GNUNET_SERVICE_Client *client, | 1929 | struct GNUNET_SERVICE_Client *client, |
1928 | struct GNUNET_MQ_Handle *mq) | 1930 | struct GNUNET_MQ_Handle *mq) |
1929 | { | 1931 | { |
1930 | /* All clients are considered to be of the "monitor" kind | 1932 | /* All clients are considered to be of the "monitor" kind |
1931 | * (that is, they don't affect ARM shutdown). | 1933 | * (that is, they don't affect ARM shutdown). |
1932 | */ | 1934 | */ |
1933 | (void) cls; | 1935 | (void)cls; |
1934 | (void) mq; | 1936 | (void)mq; |
1935 | GNUNET_SERVICE_client_mark_monitor (client); | 1937 | GNUNET_SERVICE_client_mark_monitor(client); |
1936 | return client; | 1938 | return client; |
1937 | } | 1939 | } |
1938 | 1940 | ||
@@ -1945,12 +1947,12 @@ client_connect_cb (void *cls, | |||
1945 | * @param app_ctx must match @a client | 1947 | * @param app_ctx must match @a client |
1946 | */ | 1948 | */ |
1947 | static void | 1949 | static void |
1948 | client_disconnect_cb (void *cls, | 1950 | client_disconnect_cb(void *cls, |
1949 | struct GNUNET_SERVICE_Client *client, | 1951 | struct GNUNET_SERVICE_Client *client, |
1950 | void *app_ctx) | 1952 | void *app_ctx) |
1951 | { | 1953 | { |
1952 | (void) cls; | 1954 | (void)cls; |
1953 | GNUNET_assert (client == app_ctx); | 1955 | GNUNET_assert(client == app_ctx); |
1954 | for (struct ServiceList *sl = running_head; NULL != sl; sl = sl->next) | 1956 | for (struct ServiceList *sl = running_head; NULL != sl; sl = sl->next) |
1955 | if (sl->killing_client == client) | 1957 | if (sl->killing_client == client) |
1956 | sl->killing_client = NULL; | 1958 | sl->killing_client = NULL; |
@@ -1966,18 +1968,18 @@ client_disconnect_cb (void *cls, | |||
1966 | * #GNUNET_SYSERR to close it (signal serious error) | 1968 | * #GNUNET_SYSERR to close it (signal serious error) |
1967 | */ | 1969 | */ |
1968 | static void | 1970 | static void |
1969 | handle_monitor (void *cls, const struct GNUNET_MessageHeader *message) | 1971 | handle_monitor(void *cls, const struct GNUNET_MessageHeader *message) |
1970 | { | 1972 | { |
1971 | struct GNUNET_SERVICE_Client *client = cls; | 1973 | struct GNUNET_SERVICE_Client *client = cls; |
1972 | 1974 | ||
1973 | (void) message; | 1975 | (void)message; |
1974 | /* FIXME: might want to start by letting monitor know about | 1976 | /* FIXME: might want to start by letting monitor know about |
1975 | services that are already running */ | 1977 | services that are already running */ |
1976 | /* Removal is handled by the server implementation, internally. */ | 1978 | /* Removal is handled by the server implementation, internally. */ |
1977 | GNUNET_notification_context_add (notifier, | 1979 | GNUNET_notification_context_add(notifier, |
1978 | GNUNET_SERVICE_client_get_mq (client)); | 1980 | GNUNET_SERVICE_client_get_mq(client)); |
1979 | broadcast_status ("arm", GNUNET_ARM_SERVICE_MONITORING_STARTED, client); | 1981 | broadcast_status("arm", GNUNET_ARM_SERVICE_MONITORING_STARTED, client); |
1980 | GNUNET_SERVICE_client_continue (client); | 1982 | GNUNET_SERVICE_client_continue(client); |
1981 | } | 1983 | } |
1982 | 1984 | ||
1983 | 1985 | ||
@@ -1989,71 +1991,71 @@ handle_monitor (void *cls, const struct GNUNET_MessageHeader *message) | |||
1989 | * @param c configuration to use | 1991 | * @param c configuration to use |
1990 | */ | 1992 | */ |
1991 | static void | 1993 | static void |
1992 | run (void *cls, | 1994 | run(void *cls, |
1993 | const struct GNUNET_CONFIGURATION_Handle *c, | 1995 | const struct GNUNET_CONFIGURATION_Handle *c, |
1994 | struct GNUNET_SERVICE_Handle *serv) | 1996 | struct GNUNET_SERVICE_Handle *serv) |
1995 | { | 1997 | { |
1996 | struct ServiceList *sl; | 1998 | struct ServiceList *sl; |
1997 | 1999 | ||
1998 | (void) cls; | 2000 | (void)cls; |
1999 | cfg = c; | 2001 | cfg = c; |
2000 | service = serv; | 2002 | service = serv; |
2001 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 2003 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
2002 | child_death_task = GNUNET_SCHEDULER_add_read_file ( | 2004 | child_death_task = GNUNET_SCHEDULER_add_read_file( |
2003 | GNUNET_TIME_UNIT_FOREVER_REL, | 2005 | GNUNET_TIME_UNIT_FOREVER_REL, |
2004 | GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), | 2006 | GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ), |
2005 | &maint_child_death, | 2007 | &maint_child_death, |
2006 | NULL); | 2008 | NULL); |
2007 | #if HAVE_WAIT4 | 2009 | #if HAVE_WAIT4 |
2008 | if (GNUNET_OK == | 2010 | if (GNUNET_OK == |
2009 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 2011 | GNUNET_CONFIGURATION_get_value_filename(cfg, |
2010 | "ARM", | 2012 | "ARM", |
2011 | "RESOURCE_DIAGNOSTICS", | 2013 | "RESOURCE_DIAGNOSTICS", |
2012 | &wait_filename)) | 2014 | &wait_filename)) |
2013 | { | ||
2014 | wait_file = fopen (wait_filename, "w"); | ||
2015 | if (NULL == wait_file) | ||
2016 | { | 2015 | { |
2017 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 2016 | wait_file = fopen(wait_filename, "w"); |
2018 | "fopen", | 2017 | if (NULL == wait_file) |
2019 | wait_filename); | 2018 | { |
2019 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, | ||
2020 | "fopen", | ||
2021 | wait_filename); | ||
2022 | } | ||
2020 | } | 2023 | } |
2021 | } | ||
2022 | #endif | 2024 | #endif |
2023 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | 2025 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, |
2024 | "ARM", | 2026 | "ARM", |
2025 | "GLOBAL_PREFIX", | 2027 | "GLOBAL_PREFIX", |
2026 | &prefix_command)) | 2028 | &prefix_command)) |
2027 | prefix_command = GNUNET_strdup (""); | 2029 | prefix_command = GNUNET_strdup(""); |
2028 | else | 2030 | else |
2029 | prefix_command = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix_command); | 2031 | prefix_command = GNUNET_CONFIGURATION_expand_dollar(cfg, prefix_command); |
2030 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | 2032 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, |
2031 | "ARM", | 2033 | "ARM", |
2032 | "GLOBAL_POSTFIX", | 2034 | "GLOBAL_POSTFIX", |
2033 | &final_option)) | 2035 | &final_option)) |
2034 | final_option = GNUNET_strdup (""); | 2036 | final_option = GNUNET_strdup(""); |
2035 | else | 2037 | else |
2036 | final_option = GNUNET_CONFIGURATION_expand_dollar (cfg, final_option); | 2038 | final_option = GNUNET_CONFIGURATION_expand_dollar(cfg, final_option); |
2037 | start_user = | 2039 | start_user = |
2038 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "ARM", "START_USER_SERVICES"); | 2040 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "ARM", "START_USER_SERVICES"); |
2039 | start_system = | 2041 | start_system = |
2040 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "ARM", "START_SYSTEM_SERVICES"); | 2042 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "ARM", "START_SYSTEM_SERVICES"); |
2041 | if ((GNUNET_NO == start_user) && (GNUNET_NO == start_system)) | 2043 | if ((GNUNET_NO == start_user) && (GNUNET_NO == start_system)) |
2042 | { | 2044 | { |
2043 | GNUNET_log ( | 2045 | GNUNET_log( |
2044 | GNUNET_ERROR_TYPE_ERROR, | 2046 | GNUNET_ERROR_TYPE_ERROR, |
2045 | "Please configure either START_USER_SERVICES or START_SYSTEM_SERVICES or both.\n"); | 2047 | "Please configure either START_USER_SERVICES or START_SYSTEM_SERVICES or both.\n"); |
2046 | GNUNET_SCHEDULER_shutdown (); | 2048 | GNUNET_SCHEDULER_shutdown(); |
2047 | global_ret = 1; | 2049 | global_ret = 1; |
2048 | return; | 2050 | return; |
2049 | } | 2051 | } |
2050 | GNUNET_CONFIGURATION_iterate_sections (cfg, &setup_service, NULL); | 2052 | GNUNET_CONFIGURATION_iterate_sections(cfg, &setup_service, NULL); |
2051 | 2053 | ||
2052 | /* start default services... */ | 2054 | /* start default services... */ |
2053 | for (sl = running_head; NULL != sl; sl = sl->next) | 2055 | for (sl = running_head; NULL != sl; sl = sl->next) |
2054 | if (GNUNET_YES == sl->force_start) | 2056 | if (GNUNET_YES == sl->force_start) |
2055 | start_process (sl, NULL, 0); | 2057 | start_process(sl, NULL, 0); |
2056 | notifier = GNUNET_notification_context_create (MAX_NOTIFY_QUEUE); | 2058 | notifier = GNUNET_notification_context_create(MAX_NOTIFY_QUEUE); |
2057 | } | 2059 | } |
2058 | 2060 | ||
2059 | 2061 | ||
@@ -2065,61 +2067,61 @@ run (void *cls, | |||
2065 | * @return 0 ok, 1 on error | 2067 | * @return 0 ok, 1 on error |
2066 | */ | 2068 | */ |
2067 | int | 2069 | int |
2068 | main (int argc, char *const *argv) | 2070 | main(int argc, char *const *argv) |
2069 | { | 2071 | { |
2070 | struct GNUNET_SIGNAL_Context *shc_chld; | 2072 | struct GNUNET_SIGNAL_Context *shc_chld; |
2071 | struct GNUNET_MQ_MessageHandler handlers[] = | 2073 | struct GNUNET_MQ_MessageHandler handlers[] = |
2072 | {GNUNET_MQ_hd_var_size (start, | 2074 | { GNUNET_MQ_hd_var_size(start, |
2073 | GNUNET_MESSAGE_TYPE_ARM_START, | 2075 | GNUNET_MESSAGE_TYPE_ARM_START, |
2074 | struct GNUNET_ARM_Message, | 2076 | struct GNUNET_ARM_Message, |
2077 | NULL), | ||
2078 | GNUNET_MQ_hd_var_size(stop, | ||
2079 | GNUNET_MESSAGE_TYPE_ARM_STOP, | ||
2080 | struct GNUNET_ARM_Message, | ||
2081 | NULL), | ||
2082 | GNUNET_MQ_hd_fixed_size(monitor, | ||
2083 | GNUNET_MESSAGE_TYPE_ARM_MONITOR, | ||
2084 | struct GNUNET_MessageHeader, | ||
2075 | NULL), | 2085 | NULL), |
2076 | GNUNET_MQ_hd_var_size (stop, | 2086 | GNUNET_MQ_hd_fixed_size(list, |
2077 | GNUNET_MESSAGE_TYPE_ARM_STOP, | 2087 | GNUNET_MESSAGE_TYPE_ARM_LIST, |
2078 | struct GNUNET_ARM_Message, | 2088 | struct GNUNET_ARM_Message, |
2079 | NULL), | 2089 | NULL), |
2080 | GNUNET_MQ_hd_fixed_size (monitor, | 2090 | GNUNET_MQ_hd_fixed_size(test, |
2081 | GNUNET_MESSAGE_TYPE_ARM_MONITOR, | 2091 | GNUNET_MESSAGE_TYPE_ARM_TEST, |
2082 | struct GNUNET_MessageHeader, | 2092 | struct GNUNET_MessageHeader, |
2083 | NULL), | 2093 | NULL), |
2084 | GNUNET_MQ_hd_fixed_size (list, | 2094 | GNUNET_MQ_handler_end() }; |
2085 | GNUNET_MESSAGE_TYPE_ARM_LIST, | 2095 | |
2086 | struct GNUNET_ARM_Message, | 2096 | sigpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); |
2087 | NULL), | 2097 | GNUNET_assert(NULL != sigpipe); |
2088 | GNUNET_MQ_hd_fixed_size (test, | ||
2089 | GNUNET_MESSAGE_TYPE_ARM_TEST, | ||
2090 | struct GNUNET_MessageHeader, | ||
2091 | NULL), | ||
2092 | GNUNET_MQ_handler_end ()}; | ||
2093 | |||
2094 | sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); | ||
2095 | GNUNET_assert (NULL != sigpipe); | ||
2096 | shc_chld = | 2098 | shc_chld = |
2097 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 2099 | GNUNET_SIGNAL_handler_install(GNUNET_SIGCHLD, &sighandler_child_death); |
2098 | if (0 != GNUNET_SERVICE_run_ (argc, | 2100 | if (0 != GNUNET_SERVICE_run_(argc, |
2099 | argv, | 2101 | argv, |
2100 | "arm", | 2102 | "arm", |
2101 | GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN, | 2103 | GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN, |
2102 | &run, | 2104 | &run, |
2103 | &client_connect_cb, | 2105 | &client_connect_cb, |
2104 | &client_disconnect_cb, | 2106 | &client_disconnect_cb, |
2105 | NULL, | 2107 | NULL, |
2106 | handlers)) | 2108 | handlers)) |
2107 | global_ret = 2; | 2109 | global_ret = 2; |
2108 | #if HAVE_WAIT4 | 2110 | #if HAVE_WAIT4 |
2109 | if (NULL != wait_file) | 2111 | if (NULL != wait_file) |
2110 | { | 2112 | { |
2111 | fclose (wait_file); | 2113 | fclose(wait_file); |
2112 | wait_file = NULL; | 2114 | wait_file = NULL; |
2113 | } | 2115 | } |
2114 | if (NULL != wait_filename) | 2116 | if (NULL != wait_filename) |
2115 | { | 2117 | { |
2116 | GNUNET_free (wait_filename); | 2118 | GNUNET_free(wait_filename); |
2117 | wait_filename = NULL; | 2119 | wait_filename = NULL; |
2118 | } | 2120 | } |
2119 | #endif | 2121 | #endif |
2120 | GNUNET_SIGNAL_handler_uninstall (shc_chld); | 2122 | GNUNET_SIGNAL_handler_uninstall(shc_chld); |
2121 | shc_chld = NULL; | 2123 | shc_chld = NULL; |
2122 | GNUNET_DISK_pipe_close (sigpipe); | 2124 | GNUNET_DISK_pipe_close(sigpipe); |
2123 | sigpipe = NULL; | 2125 | sigpipe = NULL; |
2124 | return global_ret; | 2126 | return global_ret; |
2125 | } | 2127 | } |
@@ -2131,11 +2133,11 @@ main (int argc, char *const *argv) | |||
2131 | /** | 2133 | /** |
2132 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 2134 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
2133 | */ | 2135 | */ |
2134 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () | 2136 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init() |
2135 | { | 2137 | { |
2136 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); | 2138 | mallopt(M_TRIM_THRESHOLD, 4 * 1024); |
2137 | mallopt (M_TOP_PAD, 1 * 1024); | 2139 | mallopt(M_TOP_PAD, 1 * 1024); |
2138 | malloc_trim (0); | 2140 | malloc_trim(0); |
2139 | } | 2141 | } |
2140 | #endif | 2142 | #endif |
2141 | 2143 | ||
diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c index 667556314..6134f17b3 100644 --- a/src/arm/mockup-service.c +++ b/src/arm/mockup-service.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include "platform.h" | 22 | #include "platform.h" |
@@ -33,15 +33,15 @@ static int special_ret = 0; | |||
33 | * @param message the actual message | 33 | * @param message the actual message |
34 | */ | 34 | */ |
35 | static void | 35 | static void |
36 | handle_stop (void *cls, const struct GNUNET_MessageHeader *message) | 36 | handle_stop(void *cls, const struct GNUNET_MessageHeader *message) |
37 | { | 37 | { |
38 | struct GNUNET_SERVICE_Client *client = cls; | 38 | struct GNUNET_SERVICE_Client *client = cls; |
39 | 39 | ||
40 | (void) message; | 40 | (void)message; |
41 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 41 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
42 | _ ("Initiating shutdown as requested by client.\n")); | 42 | _("Initiating shutdown as requested by client.\n")); |
43 | GNUNET_SERVICE_client_persist (client); | 43 | GNUNET_SERVICE_client_persist(client); |
44 | GNUNET_SCHEDULER_shutdown (); | 44 | GNUNET_SCHEDULER_shutdown(); |
45 | /* ARM won't exponentially increase restart delay if we | 45 | /* ARM won't exponentially increase restart delay if we |
46 | * terminate normally. This changes the return code. | 46 | * terminate normally. This changes the return code. |
47 | */ | 47 | */ |
@@ -58,12 +58,12 @@ handle_stop (void *cls, const struct GNUNET_MessageHeader *message) | |||
58 | * @return @a c | 58 | * @return @a c |
59 | */ | 59 | */ |
60 | static void * | 60 | static void * |
61 | client_connect_cb (void *cls, | 61 | client_connect_cb(void *cls, |
62 | struct GNUNET_SERVICE_Client *c, | 62 | struct GNUNET_SERVICE_Client *c, |
63 | struct GNUNET_MQ_Handle *mq) | 63 | struct GNUNET_MQ_Handle *mq) |
64 | { | 64 | { |
65 | (void) cls; | 65 | (void)cls; |
66 | (void) mq; | 66 | (void)mq; |
67 | return c; | 67 | return c; |
68 | } | 68 | } |
69 | 69 | ||
@@ -76,23 +76,23 @@ client_connect_cb (void *cls, | |||
76 | * @param internal_cls should be equal to @a c | 76 | * @param internal_cls should be equal to @a c |
77 | */ | 77 | */ |
78 | static void | 78 | static void |
79 | client_disconnect_cb (void *cls, | 79 | client_disconnect_cb(void *cls, |
80 | struct GNUNET_SERVICE_Client *c, | 80 | struct GNUNET_SERVICE_Client *c, |
81 | void *internal_cls) | 81 | void *internal_cls) |
82 | { | 82 | { |
83 | (void) cls; | 83 | (void)cls; |
84 | GNUNET_assert (c == internal_cls); | 84 | GNUNET_assert(c == internal_cls); |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | static void | 88 | static void |
89 | run (void *cls, | 89 | run(void *cls, |
90 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 90 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
91 | struct GNUNET_SERVICE_Handle *service) | 91 | struct GNUNET_SERVICE_Handle *service) |
92 | { | 92 | { |
93 | (void) cls; | 93 | (void)cls; |
94 | (void) cfg; | 94 | (void)cfg; |
95 | (void) service; | 95 | (void)service; |
96 | /* nothing to do */ | 96 | /* nothing to do */ |
97 | } | 97 | } |
98 | 98 | ||
@@ -100,20 +100,23 @@ run (void *cls, | |||
100 | /** | 100 | /** |
101 | * Define "main" method using service macro. | 101 | * Define "main" method using service macro. |
102 | */ | 102 | */ |
103 | GNUNET_SERVICE_MAIN ("do-nothing", | 103 | GNUNET_SERVICE_MAIN("do-nothing", |
104 | GNUNET_SERVICE_OPTION_NONE, | 104 | GNUNET_SERVICE_OPTION_NONE, |
105 | &run, | 105 | &run, |
106 | &client_connect_cb, | 106 | &client_connect_cb, |
107 | &client_disconnect_cb, | 107 | &client_disconnect_cb, |
108 | NULL, | 108 | NULL, |
109 | GNUNET_MQ_hd_fixed_size (stop, | 109 | GNUNET_MQ_hd_fixed_size(stop, |
110 | GNUNET_MESSAGE_TYPE_ARM_STOP, | 110 | GNUNET_MESSAGE_TYPE_ARM_STOP, |
111 | struct GNUNET_MessageHeader, | 111 | struct GNUNET_MessageHeader, |
112 | NULL), | 112 | NULL), |
113 | GNUNET_MQ_handler_end ()); | 113 | GNUNET_MQ_handler_end()); |
114 | 114 | ||
115 | 115 | ||
116 | /** | 116 | /** |
117 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 117 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
118 | */ | 118 | */ |
119 | void __attribute__ ((destructor)) GNUNET_mockup_done () { _exit (special_ret); } | 119 | void __attribute__ ((destructor)) GNUNET_mockup_done() |
120 | { | ||
121 | _exit(special_ret); | ||
122 | } | ||
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c index f851595b0..84d6f1bfd 100644 --- a/src/arm/test_arm_api.c +++ b/src/arm/test_arm_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 arm/test_arm_api.c | 21 | * @file arm/test_arm_api.c |
22 | * @brief testcase for arm_api.c | 22 | * @brief testcase for arm_api.c |
@@ -26,9 +26,9 @@ | |||
26 | #include "gnunet_arm_service.h" | 26 | #include "gnunet_arm_service.h" |
27 | #include "gnunet_resolver_service.h" | 27 | #include "gnunet_resolver_service.h" |
28 | 28 | ||
29 | #define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 29 | #define LOG(...) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
30 | 30 | ||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 31 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) |
32 | 32 | ||
33 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 33 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
34 | 34 | ||
@@ -42,139 +42,139 @@ static int phase = 0; | |||
42 | 42 | ||
43 | 43 | ||
44 | static void | 44 | static void |
45 | arm_stop_cb (void *cls, | 45 | arm_stop_cb(void *cls, |
46 | enum GNUNET_ARM_RequestStatus status, | 46 | enum GNUNET_ARM_RequestStatus status, |
47 | enum GNUNET_ARM_Result result) | 47 | enum GNUNET_ARM_Result result) |
48 | { | 48 | { |
49 | op = NULL; | 49 | op = NULL; |
50 | /* (6), a stop request should be sent to ARM successfully */ | 50 | /* (6), a stop request should be sent to ARM successfully */ |
51 | /* ARM should report that it is stopping */ | 51 | /* ARM should report that it is stopping */ |
52 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 52 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); |
53 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); | 53 | GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); |
54 | GNUNET_break (phase == 6); | 54 | GNUNET_break(phase == 6); |
55 | phase++; | 55 | phase++; |
56 | LOG ("Sent 'STOP' request for arm to ARM %s\n", | 56 | LOG("Sent 'STOP' request for arm to ARM %s\n", |
57 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 57 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
58 | GNUNET_SCHEDULER_shutdown (); | 58 | GNUNET_SCHEDULER_shutdown(); |
59 | } | 59 | } |
60 | 60 | ||
61 | 61 | ||
62 | static void | 62 | static void |
63 | resolver_stop_cb (void *cls, | 63 | resolver_stop_cb(void *cls, |
64 | enum GNUNET_ARM_RequestStatus status, | 64 | enum GNUNET_ARM_RequestStatus status, |
65 | enum GNUNET_ARM_Result result) | 65 | enum GNUNET_ARM_Result result) |
66 | { | 66 | { |
67 | op = NULL; | 67 | op = NULL; |
68 | /* (5), a stop request should be sent to ARM successfully. | 68 | /* (5), a stop request should be sent to ARM successfully. |
69 | * ARM should report that resolver is stopped. | 69 | * ARM should report that resolver is stopped. |
70 | */ | 70 | */ |
71 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 71 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); |
72 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); | 72 | GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); |
73 | GNUNET_break (phase == 5); | 73 | GNUNET_break(phase == 5); |
74 | LOG ("Sent 'STOP' request for resolver to ARM %s\n", | 74 | LOG("Sent 'STOP' request for resolver to ARM %s\n", |
75 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 75 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
76 | phase++; | 76 | phase++; |
77 | GNUNET_assert (NULL == op); | 77 | GNUNET_assert(NULL == op); |
78 | op = GNUNET_ARM_request_service_stop (arm, | 78 | op = GNUNET_ARM_request_service_stop(arm, |
79 | "arm", | 79 | "arm", |
80 | &arm_stop_cb, | 80 | &arm_stop_cb, |
81 | NULL); | 81 | NULL); |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | static void | 85 | static void |
86 | dns_notify (void *cls, | 86 | dns_notify(void *cls, |
87 | const struct sockaddr *addr, | 87 | const struct sockaddr *addr, |
88 | socklen_t addrlen) | 88 | socklen_t addrlen) |
89 | { | 89 | { |
90 | if (addr == NULL) | 90 | if (addr == NULL) |
91 | { | 91 | { |
92 | /* (4), resolver should finish resolving localhost */ | 92 | /* (4), resolver should finish resolving localhost */ |
93 | GNUNET_break (phase == 4); | 93 | GNUNET_break(phase == 4); |
94 | phase++; | 94 | phase++; |
95 | LOG ("Finished resolving localhost\n"); | 95 | LOG("Finished resolving localhost\n"); |
96 | if (ok != 0) | 96 | if (ok != 0) |
97 | ok = 2; | 97 | ok = 2; |
98 | GNUNET_assert (NULL == op); | 98 | GNUNET_assert(NULL == op); |
99 | op = GNUNET_ARM_request_service_stop (arm, | 99 | op = GNUNET_ARM_request_service_stop(arm, |
100 | "resolver", | 100 | "resolver", |
101 | &resolver_stop_cb, | 101 | &resolver_stop_cb, |
102 | NULL); | 102 | NULL); |
103 | return; | 103 | return; |
104 | } | 104 | } |
105 | /* (3), resolver should resolve localhost */ | 105 | /* (3), resolver should resolve localhost */ |
106 | GNUNET_break (phase == 3); | 106 | GNUNET_break(phase == 3); |
107 | LOG ("Resolved localhost\n"); | 107 | LOG("Resolved localhost\n"); |
108 | phase++; | 108 | phase++; |
109 | GNUNET_break (addr != NULL); | 109 | GNUNET_break(addr != NULL); |
110 | ok = 0; | 110 | ok = 0; |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | static void | 114 | static void |
115 | resolver_start_cb (void *cls, | 115 | resolver_start_cb(void *cls, |
116 | enum GNUNET_ARM_RequestStatus status, | 116 | enum GNUNET_ARM_RequestStatus status, |
117 | enum GNUNET_ARM_Result result) | 117 | enum GNUNET_ARM_Result result) |
118 | { | 118 | { |
119 | op = NULL; | 119 | op = NULL; |
120 | /* (2), the start request for resolver should be sent successfully | 120 | /* (2), the start request for resolver should be sent successfully |
121 | * ARM should report that resolver service is starting. | 121 | * ARM should report that resolver service is starting. |
122 | */ | 122 | */ |
123 | GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK); | 123 | GNUNET_assert(status == GNUNET_ARM_REQUEST_SENT_OK); |
124 | GNUNET_break (phase == 2); | 124 | GNUNET_break(phase == 2); |
125 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | 125 | GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); |
126 | LOG ("Sent 'START' request for resolver to ARM %s\n", | 126 | LOG("Sent 'START' request for resolver to ARM %s\n", |
127 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 127 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
128 | phase++; | 128 | phase++; |
129 | GNUNET_RESOLVER_ip_get ("localhost", | 129 | GNUNET_RESOLVER_ip_get("localhost", |
130 | AF_INET, | 130 | AF_INET, |
131 | TIMEOUT, | 131 | TIMEOUT, |
132 | &dns_notify, NULL); | 132 | &dns_notify, NULL); |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | static void | 136 | static void |
137 | arm_conn (void *cls, | 137 | arm_conn(void *cls, |
138 | int connected) | 138 | int connected) |
139 | { | 139 | { |
140 | if (GNUNET_SYSERR == connected) | 140 | if (GNUNET_SYSERR == connected) |
141 | { | 141 | { |
142 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 142 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
143 | _("Fatal error initializing ARM API.\n")); | 143 | _("Fatal error initializing ARM API.\n")); |
144 | GNUNET_SCHEDULER_shutdown (); | 144 | GNUNET_SCHEDULER_shutdown(); |
145 | GNUNET_assert (0); | 145 | GNUNET_assert(0); |
146 | return; | 146 | return; |
147 | } | 147 | } |
148 | if (GNUNET_YES == connected) | 148 | if (GNUNET_YES == connected) |
149 | { | 149 | { |
150 | /* (1), arm connection should be established */ | 150 | /* (1), arm connection should be established */ |
151 | LOG ("Connected to ARM\n"); | 151 | LOG("Connected to ARM\n"); |
152 | GNUNET_break (phase == 1); | 152 | GNUNET_break(phase == 1); |
153 | phase++; | 153 | phase++; |
154 | GNUNET_assert (NULL == op); | 154 | GNUNET_assert(NULL == op); |
155 | op = GNUNET_ARM_request_service_start (arm, | 155 | op = GNUNET_ARM_request_service_start(arm, |
156 | "resolver", | 156 | "resolver", |
157 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 157 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
158 | &resolver_start_cb, | 158 | &resolver_start_cb, |
159 | NULL); | 159 | NULL); |
160 | } | 160 | } |
161 | else | 161 | else |
162 | { | 162 | { |
163 | /* (7), ARM should stop (we disconnect from it) */ | 163 | /* (7), ARM should stop (we disconnect from it) */ |
164 | LOG ("Disconnected from ARM\n"); | 164 | LOG("Disconnected from ARM\n"); |
165 | GNUNET_break (phase == 7); | 165 | GNUNET_break(phase == 7); |
166 | if (phase != 7) | 166 | if (phase != 7) |
167 | ok = 3; | 167 | ok = 3; |
168 | else if (ok == 1) | 168 | else if (ok == 1) |
169 | ok = 0; | 169 | ok = 0; |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | static void | 174 | static void |
175 | arm_start_cb (void *cls, | 175 | arm_start_cb(void *cls, |
176 | enum GNUNET_ARM_RequestStatus status, | 176 | enum GNUNET_ARM_RequestStatus status, |
177 | enum GNUNET_ARM_Result result) | 177 | enum GNUNET_ARM_Result result) |
178 | { | 178 | { |
179 | op = NULL; | 179 | op = NULL; |
180 | /* (0) The request should be "sent" successfully | 180 | /* (0) The request should be "sent" successfully |
@@ -182,55 +182,55 @@ arm_start_cb (void *cls, | |||
182 | * by itself). | 182 | * by itself). |
183 | * ARM API should report that ARM service is starting. | 183 | * ARM API should report that ARM service is starting. |
184 | */ | 184 | */ |
185 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 185 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); |
186 | GNUNET_break (phase == 0); | 186 | GNUNET_break(phase == 0); |
187 | LOG ("Sent 'START' request for arm to ARM %s\n", | 187 | LOG("Sent 'START' request for arm to ARM %s\n", |
188 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 188 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
189 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | 189 | GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); |
190 | phase++; | 190 | phase++; |
191 | } | 191 | } |
192 | 192 | ||
193 | 193 | ||
194 | static void | 194 | static void |
195 | do_shutdown (void *cls) | 195 | do_shutdown(void *cls) |
196 | { | 196 | { |
197 | if (NULL != op) | 197 | if (NULL != op) |
198 | { | 198 | { |
199 | GNUNET_ARM_operation_cancel (op); | 199 | GNUNET_ARM_operation_cancel(op); |
200 | op = NULL; | 200 | op = NULL; |
201 | } | 201 | } |
202 | if (NULL != arm) | 202 | if (NULL != arm) |
203 | { | 203 | { |
204 | GNUNET_ARM_disconnect (arm); | 204 | GNUNET_ARM_disconnect(arm); |
205 | arm = NULL; | 205 | arm = NULL; |
206 | } | 206 | } |
207 | } | 207 | } |
208 | 208 | ||
209 | 209 | ||
210 | static void | 210 | static void |
211 | task (void *cls, | 211 | task(void *cls, |
212 | char *const *args, | 212 | char *const *args, |
213 | const char *cfgfile, | 213 | const char *cfgfile, |
214 | const struct GNUNET_CONFIGURATION_Handle *c) | 214 | const struct GNUNET_CONFIGURATION_Handle *c) |
215 | { | 215 | { |
216 | cfg = c; | 216 | cfg = c; |
217 | arm = GNUNET_ARM_connect (cfg, | 217 | arm = GNUNET_ARM_connect(cfg, |
218 | &arm_conn, | 218 | &arm_conn, |
219 | NULL); | 219 | NULL); |
220 | if (NULL == arm) | 220 | if (NULL == arm) |
221 | return; | 221 | return; |
222 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 222 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
223 | NULL); | 223 | NULL); |
224 | op = GNUNET_ARM_request_service_start (arm, | 224 | op = GNUNET_ARM_request_service_start(arm, |
225 | "arm", | 225 | "arm", |
226 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 226 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
227 | &arm_start_cb, | 227 | &arm_start_cb, |
228 | NULL); | 228 | NULL); |
229 | } | 229 | } |
230 | 230 | ||
231 | 231 | ||
232 | int | 232 | int |
233 | main (int argc, char *argvx[]) | 233 | main(int argc, char *argvx[]) |
234 | { | 234 | { |
235 | char *const argv[] = { | 235 | char *const argv[] = { |
236 | "test-arm-api", | 236 | "test-arm-api", |
@@ -240,13 +240,14 @@ main (int argc, char *argvx[]) | |||
240 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 240 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
241 | GNUNET_GETOPT_OPTION_END | 241 | GNUNET_GETOPT_OPTION_END |
242 | }; | 242 | }; |
243 | GNUNET_log_setup ("test-arm-api", | 243 | |
244 | "WARNING", | 244 | GNUNET_log_setup("test-arm-api", |
245 | NULL); | 245 | "WARNING", |
246 | GNUNET_assert (GNUNET_OK == | 246 | NULL); |
247 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 247 | GNUNET_assert(GNUNET_OK == |
248 | argv, "test-arm-api", "nohelp", options, | 248 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, |
249 | &task, NULL)); | 249 | argv, "test-arm-api", "nohelp", options, |
250 | &task, NULL)); | ||
250 | return ok; | 251 | return ok; |
251 | } | 252 | } |
252 | 253 | ||
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c index 43984f9bf..8190d29c2 100644 --- a/src/arm/test_exponential_backoff.c +++ b/src/arm/test_exponential_backoff.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 arm/test_exponential_backoff.c | 21 | * @file arm/test_exponential_backoff.c |
22 | * @brief testcase for gnunet-service-arm.c | 22 | * @brief testcase for gnunet-service-arm.c |
@@ -27,15 +27,15 @@ | |||
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_protocols.h" | 28 | #include "gnunet_protocols.h" |
29 | 29 | ||
30 | #define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 30 | #define LOG(...) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
31 | 31 | ||
32 | #define LOG_BACKOFF GNUNET_NO | 32 | #define LOG_BACKOFF GNUNET_NO |
33 | 33 | ||
34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 34 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) |
35 | 35 | ||
36 | #define SERVICE_TEST_TIMEOUT GNUNET_TIME_UNIT_FOREVER_REL | 36 | #define SERVICE_TEST_TIMEOUT GNUNET_TIME_UNIT_FOREVER_REL |
37 | 37 | ||
38 | #define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 5) | 38 | #define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 5) |
39 | 39 | ||
40 | #define SERVICE "do-nothing" | 40 | #define SERVICE "do-nothing" |
41 | 41 | ||
@@ -74,8 +74,7 @@ static char *killLogFileName; | |||
74 | /** | 74 | /** |
75 | * Context for handling the shutdown of a service. | 75 | * Context for handling the shutdown of a service. |
76 | */ | 76 | */ |
77 | struct ShutdownContext | 77 | struct ShutdownContext { |
78 | { | ||
79 | /** | 78 | /** |
80 | * Connection to the service that is being shutdown. | 79 | * Connection to the service that is being shutdown. |
81 | */ | 80 | */ |
@@ -85,12 +84,11 @@ struct ShutdownContext | |||
85 | * Task set up to cancel the shutdown request on timeout. | 84 | * Task set up to cancel the shutdown request on timeout. |
86 | */ | 85 | */ |
87 | struct GNUNET_SCHEDULER_Task *cancel_task; | 86 | struct GNUNET_SCHEDULER_Task *cancel_task; |
88 | |||
89 | }; | 87 | }; |
90 | 88 | ||
91 | 89 | ||
92 | static void | 90 | static void |
93 | kill_task (void *cbData); | 91 | kill_task(void *cbData); |
94 | 92 | ||
95 | 93 | ||
96 | /** | 94 | /** |
@@ -99,9 +97,9 @@ kill_task (void *cbData); | |||
99 | * @param cls closure | 97 | * @param cls closure |
100 | */ | 98 | */ |
101 | static void | 99 | static void |
102 | service_shutdown_timeout (void *cls) | 100 | service_shutdown_timeout(void *cls) |
103 | { | 101 | { |
104 | GNUNET_assert (0); | 102 | GNUNET_assert(0); |
105 | } | 103 | } |
106 | 104 | ||
107 | 105 | ||
@@ -114,196 +112,196 @@ service_shutdown_timeout (void *cls) | |||
114 | * @param error error code | 112 | * @param error error code |
115 | */ | 113 | */ |
116 | static void | 114 | static void |
117 | mq_error_handler (void *cls, | 115 | mq_error_handler(void *cls, |
118 | enum GNUNET_MQ_Error error) | 116 | enum GNUNET_MQ_Error error) |
119 | { | 117 | { |
120 | struct ShutdownContext *shutdown_ctx = cls; | 118 | struct ShutdownContext *shutdown_ctx = cls; |
121 | 119 | ||
122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 120 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
123 | "Service shutdown complete (MQ error).\n"); | 121 | "Service shutdown complete (MQ error).\n"); |
124 | GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task); | 122 | GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task); |
125 | GNUNET_MQ_destroy (shutdown_ctx->mq); | 123 | GNUNET_MQ_destroy(shutdown_ctx->mq); |
126 | GNUNET_free (shutdown_ctx); | 124 | GNUNET_free(shutdown_ctx); |
127 | } | 125 | } |
128 | 126 | ||
129 | 127 | ||
130 | static void | 128 | static void |
131 | kill_task (void *cbData) | 129 | kill_task(void *cbData) |
132 | { | 130 | { |
133 | struct ShutdownContext *shutdown_ctx | 131 | struct ShutdownContext *shutdown_ctx |
134 | = GNUNET_new (struct ShutdownContext); | 132 | = GNUNET_new(struct ShutdownContext); |
135 | struct GNUNET_MQ_Envelope *env; | 133 | struct GNUNET_MQ_Envelope *env; |
136 | struct GNUNET_MessageHeader *msg; | 134 | struct GNUNET_MessageHeader *msg; |
137 | struct GNUNET_MQ_MessageHandler handlers[] = { | 135 | struct GNUNET_MQ_MessageHandler handlers[] = { |
138 | GNUNET_MQ_handler_end () | 136 | GNUNET_MQ_handler_end() |
139 | }; | 137 | }; |
140 | 138 | ||
141 | kt = NULL; | 139 | kt = NULL; |
142 | if (trialCount == 13) | 140 | if (trialCount == 13) |
143 | { | 141 | { |
144 | LOG ("Saw enough kills, asking ARM to stop mock service for good\n"); | 142 | LOG("Saw enough kills, asking ARM to stop mock service for good\n"); |
145 | GNUNET_ARM_request_service_stop (arm, | 143 | GNUNET_ARM_request_service_stop(arm, |
146 | SERVICE, | 144 | SERVICE, |
147 | NULL, | 145 | NULL, |
148 | NULL); | 146 | NULL); |
149 | ok = 0; | 147 | ok = 0; |
150 | trialCount++; | 148 | trialCount++; |
151 | GNUNET_free (shutdown_ctx); | 149 | GNUNET_free(shutdown_ctx); |
152 | return; | 150 | return; |
153 | } | 151 | } |
154 | shutdown_ctx->mq = GNUNET_CLIENT_connect (cfg, | 152 | shutdown_ctx->mq = GNUNET_CLIENT_connect(cfg, |
155 | SERVICE, | 153 | SERVICE, |
156 | handlers, | 154 | handlers, |
157 | &mq_error_handler, | 155 | &mq_error_handler, |
158 | shutdown_ctx); | 156 | shutdown_ctx); |
159 | GNUNET_assert (NULL != shutdown_ctx->mq); | 157 | GNUNET_assert(NULL != shutdown_ctx->mq); |
160 | trialCount++; | 158 | trialCount++; |
161 | LOG ("Sending a shutdown request to the mock service\n"); | 159 | LOG("Sending a shutdown request to the mock service\n"); |
162 | env = GNUNET_MQ_msg (msg, | 160 | env = GNUNET_MQ_msg(msg, |
163 | GNUNET_MESSAGE_TYPE_ARM_STOP); /* FIXME: abuse of message type */ | 161 | GNUNET_MESSAGE_TYPE_ARM_STOP); /* FIXME: abuse of message type */ |
164 | GNUNET_MQ_send (shutdown_ctx->mq, | 162 | GNUNET_MQ_send(shutdown_ctx->mq, |
165 | env); | 163 | env); |
166 | shutdown_ctx->cancel_task | 164 | shutdown_ctx->cancel_task |
167 | = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 165 | = GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
168 | &service_shutdown_timeout, | 166 | &service_shutdown_timeout, |
169 | shutdown_ctx); | 167 | shutdown_ctx); |
170 | } | 168 | } |
171 | 169 | ||
172 | 170 | ||
173 | static void | 171 | static void |
174 | trigger_disconnect (void *cls) | 172 | trigger_disconnect(void *cls) |
175 | { | 173 | { |
176 | GNUNET_ARM_disconnect (arm); | 174 | GNUNET_ARM_disconnect(arm); |
177 | GNUNET_ARM_monitor_stop (mon); | 175 | GNUNET_ARM_monitor_stop(mon); |
178 | if (NULL != kt) | 176 | if (NULL != kt) |
179 | { | 177 | { |
180 | GNUNET_SCHEDULER_cancel (kt); | 178 | GNUNET_SCHEDULER_cancel(kt); |
181 | kt = NULL; | 179 | kt = NULL; |
182 | } | 180 | } |
183 | } | 181 | } |
184 | 182 | ||
185 | 183 | ||
186 | static void | 184 | static void |
187 | arm_stop_cb (void *cls, | 185 | arm_stop_cb(void *cls, |
188 | enum GNUNET_ARM_RequestStatus status, | 186 | enum GNUNET_ARM_RequestStatus status, |
189 | enum GNUNET_ARM_Result result) | 187 | enum GNUNET_ARM_Result result) |
190 | { | 188 | { |
191 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 189 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); |
192 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); | 190 | GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); |
193 | LOG ("ARM service stopped\n"); | 191 | LOG("ARM service stopped\n"); |
194 | GNUNET_SCHEDULER_shutdown (); | 192 | GNUNET_SCHEDULER_shutdown(); |
195 | } | 193 | } |
196 | 194 | ||
197 | 195 | ||
198 | static void | 196 | static void |
199 | srv_status (void *cls, | 197 | srv_status(void *cls, |
200 | const char *service, | 198 | const char *service, |
201 | enum GNUNET_ARM_ServiceStatus status) | 199 | enum GNUNET_ARM_ServiceStatus status) |
202 | { | 200 | { |
203 | if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED) | 201 | if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED) |
204 | { | 202 | { |
205 | LOG ("ARM monitor started, starting mock service\n"); | 203 | LOG("ARM monitor started, starting mock service\n"); |
206 | phase++; | 204 | phase++; |
207 | GNUNET_ARM_request_service_start (arm, | 205 | GNUNET_ARM_request_service_start(arm, |
208 | SERVICE, | 206 | SERVICE, |
209 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 207 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
210 | NULL, | 208 | NULL, |
211 | NULL); | 209 | NULL); |
212 | return; | 210 | return; |
213 | } | 211 | } |
214 | if (0 != strcasecmp (service, SERVICE)) | 212 | if (0 != strcasecmp(service, SERVICE)) |
215 | return; /* not what we care about */ | 213 | return; /* not what we care about */ |
216 | if (phase == 1) | 214 | if (phase == 1) |
217 | { | ||
218 | GNUNET_break (status == GNUNET_ARM_SERVICE_STARTING); | ||
219 | GNUNET_break (phase == 1); | ||
220 | LOG ("do-nothing is starting\n"); | ||
221 | phase++; | ||
222 | ok = 1; | ||
223 | GNUNET_assert (NULL == kt); | ||
224 | startedWaitingAt = GNUNET_TIME_absolute_get (); | ||
225 | kt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
226 | &kill_task, | ||
227 | NULL); | ||
228 | } | ||
229 | else if (phase == 2) | ||
230 | { | ||
231 | /* We passively monitor ARM for status updates. ARM should tell us | ||
232 | * when do-nothing dies (no need to run a service upness test ourselves). | ||
233 | */ | ||
234 | if (status == GNUNET_ARM_SERVICE_STARTING) | ||
235 | { | 215 | { |
236 | waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt); | 216 | GNUNET_break(status == GNUNET_ARM_SERVICE_STARTING); |
237 | LOG ("Waited for: %s\n", | 217 | GNUNET_break(phase == 1); |
238 | GNUNET_STRINGS_relative_time_to_string (waitedFor, | 218 | LOG("do-nothing is starting\n"); |
239 | GNUNET_YES)); | 219 | phase++; |
240 | 220 | ok = 1; | |
241 | LOG ("do-nothing is starting, killing it...\n"); | 221 | GNUNET_assert(NULL == kt); |
242 | GNUNET_assert (NULL == kt); | 222 | startedWaitingAt = GNUNET_TIME_absolute_get(); |
243 | kt = GNUNET_SCHEDULER_add_now (&kill_task, &ok); | 223 | kt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
224 | &kill_task, | ||
225 | NULL); | ||
244 | } | 226 | } |
245 | else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14)) | 227 | else if (phase == 2) |
246 | { | 228 | { |
247 | phase++; | 229 | /* We passively monitor ARM for status updates. ARM should tell us |
248 | LOG ("do-nothing stopped working %u times, we are done here\n", | 230 | * when do-nothing dies (no need to run a service upness test ourselves). |
249 | (unsigned int) trialCount); | 231 | */ |
250 | GNUNET_ARM_request_service_stop (arm, | 232 | if (status == GNUNET_ARM_SERVICE_STARTING) |
251 | "arm", | 233 | { |
252 | &arm_stop_cb, | 234 | waitedFor = GNUNET_TIME_absolute_get_duration(startedWaitingAt); |
253 | NULL); | 235 | LOG("Waited for: %s\n", |
236 | GNUNET_STRINGS_relative_time_to_string(waitedFor, | ||
237 | GNUNET_YES)); | ||
238 | |||
239 | LOG("do-nothing is starting, killing it...\n"); | ||
240 | GNUNET_assert(NULL == kt); | ||
241 | kt = GNUNET_SCHEDULER_add_now(&kill_task, &ok); | ||
242 | } | ||
243 | else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14)) | ||
244 | { | ||
245 | phase++; | ||
246 | LOG("do-nothing stopped working %u times, we are done here\n", | ||
247 | (unsigned int)trialCount); | ||
248 | GNUNET_ARM_request_service_stop(arm, | ||
249 | "arm", | ||
250 | &arm_stop_cb, | ||
251 | NULL); | ||
252 | } | ||
254 | } | 253 | } |
255 | } | ||
256 | } | 254 | } |
257 | 255 | ||
258 | 256 | ||
259 | static void | 257 | static void |
260 | arm_start_cb (void *cls, | 258 | arm_start_cb(void *cls, |
261 | enum GNUNET_ARM_RequestStatus status, | 259 | enum GNUNET_ARM_RequestStatus status, |
262 | enum GNUNET_ARM_Result result) | 260 | enum GNUNET_ARM_Result result) |
263 | { | 261 | { |
264 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 262 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); |
265 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | 263 | GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); |
266 | GNUNET_break (phase == 0); | 264 | GNUNET_break(phase == 0); |
267 | LOG ("Sent 'START' request for arm to ARM %s\n", | 265 | LOG("Sent 'START' request for arm to ARM %s\n", |
268 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 266 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
269 | } | 267 | } |
270 | 268 | ||
271 | 269 | ||
272 | static void | 270 | static void |
273 | task (void *cls, | 271 | task(void *cls, |
274 | char *const *args, | 272 | char *const *args, |
275 | const char *cfgfile, | 273 | const char *cfgfile, |
276 | const struct GNUNET_CONFIGURATION_Handle *c) | 274 | const struct GNUNET_CONFIGURATION_Handle *c) |
277 | { | 275 | { |
278 | cfg = c; | 276 | cfg = c; |
279 | arm = GNUNET_ARM_connect (cfg, NULL, NULL); | 277 | arm = GNUNET_ARM_connect(cfg, NULL, NULL); |
280 | if (NULL == arm) | 278 | if (NULL == arm) |
281 | { | 279 | { |
282 | GNUNET_break (0); | 280 | GNUNET_break(0); |
283 | return; | 281 | return; |
284 | } | 282 | } |
285 | mon = GNUNET_ARM_monitor_start (cfg, | 283 | mon = GNUNET_ARM_monitor_start(cfg, |
286 | &srv_status, | 284 | &srv_status, |
287 | NULL); | ||
288 | if (NULL == mon) | ||
289 | { | ||
290 | GNUNET_break (0); | ||
291 | GNUNET_ARM_disconnect (arm); | ||
292 | arm = NULL; | ||
293 | return; | ||
294 | } | ||
295 | GNUNET_ARM_request_service_start (arm, | ||
296 | "arm", | ||
297 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
298 | &arm_start_cb, | ||
299 | NULL); | ||
300 | GNUNET_SCHEDULER_add_shutdown (&trigger_disconnect, | ||
301 | NULL); | 285 | NULL); |
286 | if (NULL == mon) | ||
287 | { | ||
288 | GNUNET_break(0); | ||
289 | GNUNET_ARM_disconnect(arm); | ||
290 | arm = NULL; | ||
291 | return; | ||
292 | } | ||
293 | GNUNET_ARM_request_service_start(arm, | ||
294 | "arm", | ||
295 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
296 | &arm_start_cb, | ||
297 | NULL); | ||
298 | GNUNET_SCHEDULER_add_shutdown(&trigger_disconnect, | ||
299 | NULL); | ||
302 | } | 300 | } |
303 | 301 | ||
304 | 302 | ||
305 | static int | 303 | static int |
306 | check () | 304 | check() |
307 | { | 305 | { |
308 | char *const argv[] = { | 306 | char *const argv[] = { |
309 | "test-exponential-backoff", | 307 | "test-exponential-backoff", |
@@ -315,14 +313,14 @@ check () | |||
315 | }; | 313 | }; |
316 | 314 | ||
317 | /* Running ARM and running the do_nothing task */ | 315 | /* Running ARM and running the do_nothing task */ |
318 | GNUNET_assert (GNUNET_OK == | 316 | GNUNET_assert(GNUNET_OK == |
319 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 317 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, |
320 | argv, | 318 | argv, |
321 | "test-exponential-backoff", | 319 | "test-exponential-backoff", |
322 | "nohelp", | 320 | "nohelp", |
323 | options, | 321 | options, |
324 | &task, | 322 | &task, |
325 | NULL)); | 323 | NULL)); |
326 | return ok; | 324 | return ok; |
327 | } | 325 | } |
328 | 326 | ||
@@ -336,47 +334,47 @@ check () | |||
336 | 334 | ||
337 | 335 | ||
338 | static int | 336 | static int |
339 | init () | 337 | init() |
340 | { | 338 | { |
341 | struct GNUNET_CONFIGURATION_Handle *cfg; | 339 | struct GNUNET_CONFIGURATION_Handle *cfg; |
342 | char pwd[PATH_MAX]; | 340 | char pwd[PATH_MAX]; |
343 | char *binary; | 341 | char *binary; |
344 | 342 | ||
345 | cfg = GNUNET_CONFIGURATION_create (); | 343 | cfg = GNUNET_CONFIGURATION_create(); |
346 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, | 344 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse(cfg, |
347 | "test_arm_api_data.conf")) | 345 | "test_arm_api_data.conf")) |
348 | { | 346 | { |
349 | GNUNET_CONFIGURATION_destroy (cfg); | 347 | GNUNET_CONFIGURATION_destroy(cfg); |
350 | return GNUNET_SYSERR; | 348 | return GNUNET_SYSERR; |
351 | } | 349 | } |
352 | if (NULL == getcwd (pwd, PATH_MAX)) | 350 | if (NULL == getcwd(pwd, PATH_MAX)) |
353 | return GNUNET_SYSERR; | ||
354 | GNUNET_assert (0 < GNUNET_asprintf (&binary, | ||
355 | "%s/%s", | ||
356 | pwd, | ||
357 | BINARY)); | ||
358 | GNUNET_CONFIGURATION_set_value_string (cfg, | ||
359 | SERVICE, | ||
360 | "BINARY", | ||
361 | binary); | ||
362 | GNUNET_free (binary); | ||
363 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, | ||
364 | CFGFILENAME)) | ||
365 | { | ||
366 | GNUNET_CONFIGURATION_destroy (cfg); | ||
367 | return GNUNET_SYSERR; | 351 | return GNUNET_SYSERR; |
368 | } | 352 | GNUNET_assert(0 < GNUNET_asprintf(&binary, |
369 | GNUNET_CONFIGURATION_destroy (cfg); | 353 | "%s/%s", |
354 | pwd, | ||
355 | BINARY)); | ||
356 | GNUNET_CONFIGURATION_set_value_string(cfg, | ||
357 | SERVICE, | ||
358 | "BINARY", | ||
359 | binary); | ||
360 | GNUNET_free(binary); | ||
361 | if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, | ||
362 | CFGFILENAME)) | ||
363 | { | ||
364 | GNUNET_CONFIGURATION_destroy(cfg); | ||
365 | return GNUNET_SYSERR; | ||
366 | } | ||
367 | GNUNET_CONFIGURATION_destroy(cfg); | ||
370 | 368 | ||
371 | #if LOG_BACKOFF | 369 | #if LOG_BACKOFF |
372 | killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log"); | 370 | killLogFileName = GNUNET_DISK_mktemp("exponential-backoff-waiting.log"); |
373 | if (NULL == (killLogFilePtr = fopen (killLogFileName, | 371 | if (NULL == (killLogFilePtr = fopen(killLogFileName, |
374 | "w"))) | 372 | "w"))) |
375 | { | 373 | { |
376 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 374 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, |
377 | "fopen", | 375 | "fopen", |
378 | killLogFileName); | 376 | killLogFileName); |
379 | GNUNET_free (killLogFileName); | 377 | GNUNET_free(killLogFileName); |
380 | return GNUNET_SYSERR; | 378 | return GNUNET_SYSERR; |
381 | } | 379 | } |
382 | #endif | 380 | #endif |
@@ -385,29 +383,29 @@ init () | |||
385 | 383 | ||
386 | 384 | ||
387 | static void | 385 | static void |
388 | houseKeep () | 386 | houseKeep() |
389 | { | 387 | { |
390 | #if LOG_BACKOFF | 388 | #if LOG_BACKOFF |
391 | GNUNET_assert (0 == fclose (killLogFilePtr)); | 389 | GNUNET_assert(0 == fclose(killLogFilePtr)); |
392 | GNUNET_free (killLogFileName); | 390 | GNUNET_free(killLogFileName); |
393 | #endif | 391 | #endif |
394 | (void) unlink (CFGFILENAME); | 392 | (void)unlink(CFGFILENAME); |
395 | } | 393 | } |
396 | 394 | ||
397 | 395 | ||
398 | int | 396 | int |
399 | main (int argc, char *argv[]) | 397 | main(int argc, char *argv[]) |
400 | { | 398 | { |
401 | int ret; | 399 | int ret; |
402 | 400 | ||
403 | GNUNET_log_setup ("test-exponential-backoff", | 401 | GNUNET_log_setup("test-exponential-backoff", |
404 | "WARNING", | 402 | "WARNING", |
405 | NULL); | 403 | NULL); |
406 | 404 | ||
407 | if (GNUNET_OK != init ()) | 405 | if (GNUNET_OK != init()) |
408 | return 1; | 406 | return 1; |
409 | ret = check (); | 407 | ret = check(); |
410 | houseKeep (); | 408 | houseKeep(); |
411 | return ret; | 409 | return ret; |
412 | } | 410 | } |
413 | 411 | ||
diff --git a/src/arm/test_gnunet_service_arm.c b/src/arm/test_gnunet_service_arm.c index 9508581de..8c8c664f9 100644 --- a/src/arm/test_gnunet_service_arm.c +++ b/src/arm/test_gnunet_service_arm.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 arm/test_gnunet_service_arm.c | 21 | * @file arm/test_gnunet_service_arm.c |
22 | * @brief testcase for gnunet-service-arm.c; tests ARM by making it start the resolver | 22 | * @brief testcase for gnunet-service-arm.c; tests ARM by making it start the resolver |
@@ -34,9 +34,9 @@ | |||
34 | * (by checking if running before starting, so really this time is always waited on | 34 | * (by checking if running before starting, so really this time is always waited on |
35 | * startup (annoying)). | 35 | * startup (annoying)). |
36 | */ | 36 | */ |
37 | #define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 50) | 37 | #define START_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 50) |
38 | 38 | ||
39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) |
40 | 40 | ||
41 | 41 | ||
42 | static int ret = 1; | 42 | static int ret = 1; |
@@ -51,141 +51,141 @@ static const char hostname[] = "www.gnu.org"; /* any domain should do */ | |||
51 | 51 | ||
52 | 52 | ||
53 | static void | 53 | static void |
54 | trigger_disconnect (void *cls) | 54 | trigger_disconnect(void *cls) |
55 | { | 55 | { |
56 | GNUNET_ARM_disconnect (arm); | 56 | GNUNET_ARM_disconnect(arm); |
57 | arm = NULL; | 57 | arm = NULL; |
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | static void | 61 | static void |
62 | arm_stop_cb (void *cls, | 62 | arm_stop_cb(void *cls, |
63 | enum GNUNET_ARM_RequestStatus status, | 63 | enum GNUNET_ARM_RequestStatus status, |
64 | enum GNUNET_ARM_Result result) | 64 | enum GNUNET_ARM_Result result) |
65 | { | 65 | { |
66 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 66 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); |
67 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); | 67 | GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); |
68 | if (result != GNUNET_ARM_RESULT_STOPPED) | 68 | if (result != GNUNET_ARM_RESULT_STOPPED) |
69 | { | 69 | { |
70 | GNUNET_break (0); | 70 | GNUNET_break(0); |
71 | ret = 4; | 71 | ret = 4; |
72 | } | 72 | } |
73 | GNUNET_SCHEDULER_add_now (&trigger_disconnect, NULL); | 73 | GNUNET_SCHEDULER_add_now(&trigger_disconnect, NULL); |
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
77 | static void | 77 | static void |
78 | service_list (void *cls, | 78 | service_list(void *cls, |
79 | enum GNUNET_ARM_RequestStatus rs, | 79 | enum GNUNET_ARM_RequestStatus rs, |
80 | unsigned int count, | 80 | unsigned int count, |
81 | const char *const*list) | 81 | const char *const*list) |
82 | { | 82 | { |
83 | unsigned int i; | 83 | unsigned int i; |
84 | 84 | ||
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 85 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
86 | "%u services are are currently running\n", | 86 | "%u services are are currently running\n", |
87 | count); | 87 | count); |
88 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 88 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
89 | goto stop_arm; | 89 | goto stop_arm; |
90 | for (i=0;i<count;i++) | 90 | for (i = 0; i < count; i++) |
91 | { | ||
92 | if (0 == strcasecmp (list[i], | ||
93 | "resolver (gnunet-service-resolver)")) | ||
94 | { | 91 | { |
95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 92 | if (0 == strcasecmp(list[i], |
96 | "Got service list, now stopping arm\n"); | 93 | "resolver (gnunet-service-resolver)")) |
97 | ret = 0; | 94 | { |
95 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
96 | "Got service list, now stopping arm\n"); | ||
97 | ret = 0; | ||
98 | } | ||
98 | } | 99 | } |
99 | } | ||
100 | 100 | ||
101 | stop_arm: | 101 | stop_arm: |
102 | GNUNET_ARM_request_service_stop (arm, | 102 | GNUNET_ARM_request_service_stop(arm, |
103 | "arm", | 103 | "arm", |
104 | &arm_stop_cb, | 104 | &arm_stop_cb, |
105 | NULL); | 105 | NULL); |
106 | } | 106 | } |
107 | 107 | ||
108 | 108 | ||
109 | static void | 109 | static void |
110 | hostname_resolve_cb (void *cls, | 110 | hostname_resolve_cb(void *cls, |
111 | const struct sockaddr *addr, | 111 | const struct sockaddr *addr, |
112 | socklen_t addrlen) | 112 | socklen_t addrlen) |
113 | { | 113 | { |
114 | if ((0 == ret) || (4 == ret) || (1 == resolved_ok)) | 114 | if ((0 == ret) || (4 == ret) || (1 == resolved_ok)) |
115 | return; | 115 | return; |
116 | if (NULL == addr) | 116 | if (NULL == addr) |
117 | { | 117 | { |
118 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 118 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
119 | "Failed to resolve hostname!\n"); | 119 | "Failed to resolve hostname!\n"); |
120 | GNUNET_break (0); | 120 | GNUNET_break(0); |
121 | ret = 3; | 121 | ret = 3; |
122 | GNUNET_ARM_request_service_stop (arm, | 122 | GNUNET_ARM_request_service_stop(arm, |
123 | "arm", | 123 | "arm", |
124 | &arm_stop_cb, | 124 | &arm_stop_cb, |
125 | NULL); | 125 | NULL); |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | if (0 == asked_for_a_list) | 128 | if (0 == asked_for_a_list) |
129 | { | 129 | { |
130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 130 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
131 | "Resolved hostname, now checking the service list\n"); | 131 | "Resolved hostname, now checking the service list\n"); |
132 | GNUNET_ARM_request_service_list (arm, | 132 | GNUNET_ARM_request_service_list(arm, |
133 | &service_list, | 133 | &service_list, |
134 | NULL); | 134 | NULL); |
135 | asked_for_a_list = 1; | 135 | asked_for_a_list = 1; |
136 | resolved_ok = 1; | 136 | resolved_ok = 1; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | static void | 141 | static void |
142 | arm_start_cb (void *cls, | 142 | arm_start_cb(void *cls, |
143 | enum GNUNET_ARM_RequestStatus status, | 143 | enum GNUNET_ARM_RequestStatus status, |
144 | enum GNUNET_ARM_Result result) | 144 | enum GNUNET_ARM_Result result) |
145 | { | 145 | { |
146 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 146 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); |
147 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | 147 | GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); |
148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 148 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
149 | "Trying to resolve a hostname via the resolver service!\n"); | 149 | "Trying to resolve a hostname via the resolver service!\n"); |
150 | /* connect to the resolver service */ | 150 | /* connect to the resolver service */ |
151 | if (NULL == | 151 | if (NULL == |
152 | GNUNET_RESOLVER_ip_get (hostname, | 152 | GNUNET_RESOLVER_ip_get(hostname, |
153 | AF_UNSPEC, | 153 | AF_UNSPEC, |
154 | TIMEOUT, | 154 | TIMEOUT, |
155 | &hostname_resolve_cb, | 155 | &hostname_resolve_cb, |
156 | NULL)) | 156 | NULL)) |
157 | { | 157 | { |
158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 158 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
159 | "Unable initiate connection to resolver service\n"); | 159 | "Unable initiate connection to resolver service\n"); |
160 | GNUNET_break (0); | 160 | GNUNET_break(0); |
161 | ret = 2; | 161 | ret = 2; |
162 | GNUNET_ARM_request_service_stop (arm, | 162 | GNUNET_ARM_request_service_stop(arm, |
163 | "arm", | 163 | "arm", |
164 | &arm_stop_cb, | 164 | &arm_stop_cb, |
165 | NULL); | 165 | NULL); |
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
169 | 169 | ||
170 | static void | 170 | static void |
171 | run (void *cls, | 171 | run(void *cls, |
172 | char *const *args, | 172 | char *const *args, |
173 | const char *cfgfile, | 173 | const char *cfgfile, |
174 | const struct GNUNET_CONFIGURATION_Handle *c) | 174 | const struct GNUNET_CONFIGURATION_Handle *c) |
175 | { | 175 | { |
176 | arm = GNUNET_ARM_connect (c, | 176 | arm = GNUNET_ARM_connect(c, |
177 | NULL, | 177 | NULL, |
178 | NULL); | 178 | NULL); |
179 | GNUNET_ARM_request_service_start (arm, | 179 | GNUNET_ARM_request_service_start(arm, |
180 | "arm", | 180 | "arm", |
181 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 181 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
182 | &arm_start_cb, | 182 | &arm_start_cb, |
183 | NULL); | 183 | NULL); |
184 | } | 184 | } |
185 | 185 | ||
186 | 186 | ||
187 | int | 187 | int |
188 | main (int argc, char *av[]) | 188 | main(int argc, char *av[]) |
189 | { | 189 | { |
190 | static char *const argv[] = { | 190 | static char *const argv[] = { |
191 | "test-gnunet-service-arm", | 191 | "test-gnunet-service-arm", |
@@ -203,27 +203,27 @@ main (int argc, char *av[]) | |||
203 | struct addrinfo *ai; | 203 | struct addrinfo *ai; |
204 | int ret; | 204 | int ret; |
205 | 205 | ||
206 | if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai))) | 206 | if (0 != (ret = getaddrinfo(hostname, NULL, NULL, &ai))) |
207 | { | 207 | { |
208 | fprintf (stderr, | 208 | fprintf(stderr, |
209 | "Failed to resolve `%s', testcase not run.\n", | 209 | "Failed to resolve `%s', testcase not run.\n", |
210 | hostname); | 210 | hostname); |
211 | return 77; | 211 | return 77; |
212 | } | 212 | } |
213 | freeaddrinfo (ai); | 213 | freeaddrinfo(ai); |
214 | } | 214 | } |
215 | #elif HAVE_GETHOSTBYNAME2 | 215 | #elif HAVE_GETHOSTBYNAME2 |
216 | { | 216 | { |
217 | struct hostent *host; | 217 | struct hostent *host; |
218 | 218 | ||
219 | host = gethostbyname2 (hostname, AF_INET); | 219 | host = gethostbyname2(hostname, AF_INET); |
220 | if (NULL == host) | 220 | if (NULL == host) |
221 | host = gethostbyname2 (hostname, AF_INET6); | 221 | host = gethostbyname2(hostname, AF_INET6); |
222 | if (NULL == host) | 222 | if (NULL == host) |
223 | { | 223 | { |
224 | fprintf (stderr, | 224 | fprintf(stderr, |
225 | "Failed to resolve `%s', testcase not run.\n", | 225 | "Failed to resolve `%s', testcase not run.\n", |
226 | hostname); | 226 | hostname); |
227 | return 77; | 227 | return 77; |
228 | } | 228 | } |
229 | } | 229 | } |
@@ -231,34 +231,34 @@ main (int argc, char *av[]) | |||
231 | { | 231 | { |
232 | struct hostent *host; | 232 | struct hostent *host; |
233 | 233 | ||
234 | host = gethostbyname (hostname); | 234 | host = gethostbyname(hostname); |
235 | if (NULL == host) | 235 | if (NULL == host) |
236 | { | 236 | { |
237 | fprintf (stderr, | 237 | fprintf(stderr, |
238 | "Failed to resolve `%s', testcase not run.\n", | 238 | "Failed to resolve `%s', testcase not run.\n", |
239 | hostname); | 239 | hostname); |
240 | return 77; | 240 | return 77; |
241 | } | 241 | } |
242 | } | 242 | } |
243 | #else | 243 | #else |
244 | fprintf (stderr, | 244 | fprintf(stderr, |
245 | "libc fails to have resolver function, testcase not run.\n"); | 245 | "libc fails to have resolver function, testcase not run.\n"); |
246 | return 77; | 246 | return 77; |
247 | #endif | 247 | #endif |
248 | GNUNET_log_setup ("test-gnunet-service-arm", | 248 | GNUNET_log_setup("test-gnunet-service-arm", |
249 | "WARNING", | 249 | "WARNING", |
250 | NULL); | 250 | NULL); |
251 | GNUNET_break (GNUNET_OK == | 251 | GNUNET_break(GNUNET_OK == |
252 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 252 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, |
253 | argv, "test-gnunet-service-arm", | 253 | argv, "test-gnunet-service-arm", |
254 | "nohelp", options, | 254 | "nohelp", options, |
255 | &run, NULL)); | 255 | &run, NULL)); |
256 | if (0 != ret) | 256 | if (0 != ret) |
257 | { | 257 | { |
258 | fprintf (stderr, | 258 | fprintf(stderr, |
259 | "Test failed with error code %d\n", | 259 | "Test failed with error code %d\n", |
260 | ret); | 260 | ret); |
261 | } | 261 | } |
262 | return ret; | 262 | return ret; |
263 | } | 263 | } |
264 | 264 | ||