From b9e05ddfffa6e716b1e725d367d6dc3e2a1cde02 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 13 Nov 2013 22:07:29 +0000 Subject: [PATCH] -fix message alignment to avoid bus error, indentation, style fixes --- src/arm/arm.h | 11 +++-- src/arm/arm_api.c | 5 +++ src/arm/gnunet-service-arm.c | 84 +++++++++++++++++++----------------- 3 files changed, 58 insertions(+), 42 deletions(-) diff --git a/src/arm/arm.h b/src/arm/arm.h index 7010a0842..bf2f7e797 100644 --- a/src/arm/arm.h +++ b/src/arm/arm.h @@ -57,13 +57,18 @@ struct GNUNET_ARM_StatusMessage struct GNUNET_ARM_Message { /** - * Reply to client, type is GNUNET_MESSAGE_TYPE_ARM_RESULT or - * GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT. + * Reply to client, type is #GNUNET_MESSAGE_TYPE_ARM_RESULT or + * #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT. * OR - * Request from client, type is GNUNET_MESSAGE_TYPE_ARM_REQUEST + * Request from client, type is #GNUNET_MESSAGE_TYPE_ARM_REQUEST */ struct GNUNET_MessageHeader header; + /** + * For alignment. + */ + uint32_t reserved; + /** * ID of a request that is being replied to. * OR diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index 6dfe65702..9644026d6 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c @@ -348,6 +348,7 @@ client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) return; } arm_msg = (const struct GNUNET_ARM_Message *) msg; + GNUNET_break (0 == ntohl (arm_msg->reserved)); id = GNUNET_ntohll (arm_msg->request_id); cm = find_cm_by_id (h, id); if (NULL == cm) @@ -529,6 +530,7 @@ transmit_arm_message (void *cls, size_t size, void *buf) LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting control message with %u bytes of type %u to arm with id %llu\n", (unsigned int) msize, (unsigned int) ntohs (cm->msg->header.type), request_id); + arm_msg->reserved = htonl (0); arm_msg->request_id = GNUNET_htonll (request_id); memcpy (buf, cm->msg, msize); /* Otherwise we won't be able to find it later! */ @@ -712,6 +714,7 @@ control_message_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t { struct ARMControlMessage *cm = cls; struct GNUNET_ARM_Message *arm_msg; + LOG (GNUNET_ERROR_TYPE_DEBUG, "Control message timed out\n"); arm_msg = cm->msg; @@ -908,6 +911,7 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name, msg = GNUNET_malloc (sizeof (struct GNUNET_ARM_Message) + slen); msg->header.size = htons (sizeof (struct GNUNET_ARM_Message) + slen); msg->header.type = htons (type); + msg->reserved = htonl (0); memcpy (&msg[1], service_name, slen); cm->msg = msg; LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -1068,6 +1072,7 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, msg = GNUNET_malloc (sizeof (struct GNUNET_ARM_Message)); msg->header.size = htons (sizeof (struct GNUNET_ARM_Message)); msg->header.type = htons (GNUNET_MESSAGE_TYPE_ARM_LIST); + msg->reserved = htonl (0); cm->msg = msg; GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, h->control_pending_tail, cm); diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index eccd8d566..44decaa7f 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c @@ -731,31 +731,34 @@ handle_start (void *cls, struct GNUNET_SERVER_Client *client, size -= sizeof (struct GNUNET_ARM_Message); servicename = (const char *) &amsg[1]; if ((size == 0) || (servicename[size - 1] != '\0')) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - return; - } + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } if (GNUNET_YES == in_shutdown) - { - signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_IN_SHUTDOWN); - GNUNET_SERVER_receive_done (client, GNUNET_OK); - return; - } + { + signal_result (client, servicename, request_id, + GNUNET_ARM_RESULT_IN_SHUTDOWN); + GNUNET_SERVER_receive_done (client, GNUNET_OK); + return; + } sl = find_service (servicename); if (NULL == sl) - { - signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_IS_NOT_KNOWN); - GNUNET_SERVER_receive_done (client, GNUNET_OK); - return; - } + { + signal_result (client, servicename, request_id, + GNUNET_ARM_RESULT_IS_NOT_KNOWN); + GNUNET_SERVER_receive_done (client, GNUNET_OK); + return; + } sl->is_default = GNUNET_YES; - if (sl->proc != NULL) - { - signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_IS_STARTED_ALREADY); - GNUNET_SERVER_receive_done (client, GNUNET_OK); - return; - } + if (NULL != sl->proc) + { + signal_result (client, servicename, request_id, + GNUNET_ARM_RESULT_IS_STARTED_ALREADY); + GNUNET_SERVER_receive_done (client, GNUNET_OK); + return; + } start_process (sl, client, request_id); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -806,7 +809,8 @@ handle_stop (void *cls, struct GNUNET_SERVER_Client *client, return; } GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Preparing to stop `%s'\n"), servicename); + _("Preparing to stop `%s'\n"), + servicename); if (0 == strcasecmp (servicename, "arm")) { broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL); @@ -831,22 +835,22 @@ handle_stop (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } - if (sl->killing_client != NULL) - { - /* killing already in progress */ - signal_result (client, servicename, request_id, - GNUNET_ARM_RESULT_IS_STOPPING_ALREADY); - GNUNET_SERVER_receive_done (client, GNUNET_OK); - return; - } - if (sl->proc == NULL) - { - /* process is down */ - signal_result (client, servicename, request_id, - GNUNET_ARM_RESULT_IS_STOPPED_ALREADY); - GNUNET_SERVER_receive_done (client, GNUNET_OK); - return; - } + if (NULL != sl->killing_client) + { + /* killing already in progress */ + signal_result (client, servicename, request_id, + GNUNET_ARM_RESULT_IS_STOPPING_ALREADY); + GNUNET_SERVER_receive_done (client, GNUNET_OK); + return; + } + if (NULL == sl->proc) + { + /* process is down */ + signal_result (client, servicename, request_id, + GNUNET_ARM_RESULT_IS_STOPPED_ALREADY); + GNUNET_SERVER_receive_done (client, GNUNET_OK); + return; + } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending kill signal to service `%s', waiting for process to die.\n", servicename); @@ -884,10 +888,11 @@ handle_list (void *cls, struct GNUNET_SERVER_Client *client, return; request = (struct GNUNET_ARM_Message *) message; + GNUNET_break (0 == ntohl (request->reserved)); count = 0; string_list_size = 0; /* first count the running processes get their name's size */ - for (sl = running_head; sl != NULL; sl = sl->next) + for (sl = running_head; NULL != sl; sl = sl->next) { if (sl->proc != NULL) { @@ -903,6 +908,7 @@ handle_list (void *cls, struct GNUNET_SERVER_Client *client, msg = GNUNET_malloc (total_size); msg->arm_msg.header.size = total_size; msg->arm_msg.header.type = GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT; + msg->arm_msg.reserved = htonl (0); msg->arm_msg.request_id = GNUNET_ntohll (request->request_id); msg->count = count; -- 2.25.1