From 238b4ac9407e047a7a2d6f0c951e70ef6e400d82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Wed, 15 Jun 2011 07:15:39 +0000 Subject: [PATCH] fix bugs found by compiling with -Wextra --- src/mesh/mesh_api.c | 11 ++++++++++- src/vpn/gnunet-daemon-exit.c | 18 ++++++++---------- src/vpn/gnunet-daemon-vpn-helper.c | 1 - src/vpn/gnunet-daemon-vpn.c | 5 ++++- src/vpn/gnunet-helper-vpn-api.c | 3 +-- src/vpn/gnunet-helper-vpn-api.h | 4 +--- src/vpn/gnunet-service-dns.c | 13 +++++++++---- 7 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index edbc549b8..c1875854e 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -127,6 +127,9 @@ static void send_end_connect(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { + if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) + return; + struct GNUNET_MESH_Tunnel* tunnel = cls; tunnel->connect_handler(tunnel->handler_cls, NULL, NULL); @@ -136,6 +139,9 @@ static void send_self_connect(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { + if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) + return; + struct GNUNET_MESH_Tunnel* tunnel = cls; tunnel->connect_handler(tunnel->handler_cls, &tunnel->handle->myself, NULL); @@ -146,6 +152,9 @@ static void call_connect_handler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) + return; + struct GNUNET_MESH_Tunnel *tunnel = cls; tunnel->connect_handler (tunnel->handler_cls, &tunnel->peer, @@ -689,7 +698,7 @@ GNUNET_MESH_connect (const struct build_hello_message(ret, stypes); - const static struct GNUNET_CORE_MessageHandler core_handlers[] = { + static const struct GNUNET_CORE_MessageHandler core_handlers[] = { {&core_receive, GNUNET_MESSAGE_TYPE_MESH, 0}, {&receive_hello, GNUNET_MESSAGE_TYPE_MESH_HELLO, 0}, {NULL, 0, 0} diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c index 87b795edd..0ee07fead 100644 --- a/src/vpn/gnunet-daemon-exit.c +++ b/src/vpn/gnunet-daemon-exit.c @@ -243,8 +243,7 @@ send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf) * @param version 4 or 6 */ static void -udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen, - unsigned int version) +udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen) { struct redirect_info u_i; struct GNUNET_MESH_Tunnel *tunnel; @@ -337,7 +336,7 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen, */ static void tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, - unsigned int version, size_t pktlen) + size_t pktlen) { struct redirect_info u_i; struct GNUNET_MESH_Tunnel *tunnel; @@ -421,10 +420,10 @@ message_token (void *cls, struct ip6_pkt *pkt6 = (struct ip6_pkt *) pkt_tun; if (0x11 == pkt6->ip6_hdr.nxthdr) udp_from_helper (&((struct ip6_udp *) pkt6)->udp_hdr, - (unsigned char *) &pkt6->ip6_hdr.dadr, 16, 6); + (unsigned char *) &pkt6->ip6_hdr.dadr, 16); else if (0x06 == pkt6->ip6_hdr.nxthdr) tcp_from_helper (&((struct ip6_tcp *) pkt6)->tcp_hdr, - (unsigned char *) &pkt6->ip6_hdr.dadr, 16, 6, + (unsigned char *) &pkt6->ip6_hdr.dadr, 16, ntohs (pkt6->ip6_hdr.paylgth)); } else if (ntohs (pkt_tun->tun.type) == 0x0800) @@ -433,7 +432,7 @@ message_token (void *cls, uint32_t tmp = pkt4->ip_hdr.dadr; if (0x11 == pkt4->ip_hdr.proto) udp_from_helper (&((struct ip_udp *) pkt4)->udp_hdr, - (unsigned char *) &tmp, 4, 4); + (unsigned char *) &tmp, 4); else if (0x06 == pkt4->ip_hdr.proto) { size_t pktlen = ntohs(pkt4->ip_hdr.tot_lngth); @@ -441,7 +440,7 @@ message_token (void *cls, pktlen -= 4*pkt4->ip_hdr.hdr_lngth; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "-hdr: %d\n", pktlen); tcp_from_helper (&((struct ip_tcp *) pkt4)->tcp_hdr, - (unsigned char *) &tmp, 4, 4, pktlen); + (unsigned char *) &tmp, 4, pktlen); } } else @@ -634,7 +633,6 @@ start_helper_and_schedule(void *cls, "exit-gnunet", start_helper_and_schedule, message_token, - NULL, NULL); GNUNET_free(ipv6addr); @@ -1189,7 +1187,7 @@ run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg_) { - const static struct GNUNET_MESH_MessageHandler handlers[] = { + static const struct GNUNET_MESH_MessageHandler handlers[] = { {receive_udp_service, GNUNET_MESSAGE_TYPE_SERVICE_UDP, 0}, {receive_tcp_service, GNUNET_MESSAGE_TYPE_SERVICE_TCP, 0}, {receive_udp_remote, GNUNET_MESSAGE_TYPE_REMOTE_UDP, 0}, @@ -1197,7 +1195,7 @@ run (void *cls, {NULL, 0, 0} }; - const static GNUNET_MESH_ApplicationType apptypes[] = + static const GNUNET_MESH_ApplicationType apptypes[] = { GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY, GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY, diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c index 1c7ee7987..100f08c97 100644 --- a/src/vpn/gnunet-daemon-vpn-helper.c +++ b/src/vpn/gnunet-daemon-vpn-helper.c @@ -111,7 +111,6 @@ start_helper_and_schedule(void *cls, "vpn-gnunet", start_helper_and_schedule, message_token, - NULL, NULL); GNUNET_free(ipv6addr); diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 49a33a7bb..1be010685 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -275,6 +275,9 @@ new_ip6addr_remote (unsigned char *buf, unsigned char *addr, char addrlen) */ void process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { + if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) + return; + struct answer_packet* pkt = cls; struct answer_packet_list* list; @@ -701,7 +704,7 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg_) { - const static struct GNUNET_MESH_MessageHandler handlers[] = { + static const struct GNUNET_MESH_MessageHandler handlers[] = { {receive_udp_back, GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK, 0}, {receive_tcp_back, GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK, 0}, {receive_udp_back, GNUNET_MESSAGE_TYPE_REMOTE_UDP_BACK, 0}, diff --git a/src/vpn/gnunet-helper-vpn-api.c b/src/vpn/gnunet-helper-vpn-api.c index 5736df2b1..195a79217 100644 --- a/src/vpn/gnunet-helper-vpn-api.c +++ b/src/vpn/gnunet-helper-vpn-api.c @@ -109,8 +109,7 @@ start_helper (const char *ifname, const char *ipv4addr, const char *ipv4mask, const char *process_name, GNUNET_SCHEDULER_Task restart_task, - GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls, - void *client) + GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls) { struct GNUNET_VPN_HELPER_Handle *handle = GNUNET_malloc (sizeof (struct GNUNET_VPN_HELPER_Handle)); diff --git a/src/vpn/gnunet-helper-vpn-api.h b/src/vpn/gnunet-helper-vpn-api.h index 00eb7db62..4e8f76611 100644 --- a/src/vpn/gnunet-helper-vpn-api.h +++ b/src/vpn/gnunet-helper-vpn-api.h @@ -92,7 +92,6 @@ struct GNUNET_VPN_HELPER_Handle * @param restart_task The task called when the helper dies. Will be called with the handle as cls * @param cb A callback for messages from the helper * @param cb_cls Closure for the callback - * @param client client_name for the callback * * @return A pointer to the new Handle, NULL on error */ @@ -105,8 +104,7 @@ struct GNUNET_VPN_HELPER_Handle *start_helper (const char *ifname, GNUNET_SCHEDULER_Task restart_task, GNUNET_SERVER_MessageTokenizerCallback - cb, void *cb_cls, - void *client); + cb, void *cb_cls); /** * @brief Kills the helper, closes the pipe and free()s the handle diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 9ee63bbda..7b96a180d 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c @@ -113,6 +113,9 @@ struct receive_dht_cls { static void hijack (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + return; + char port_s[6]; char *virt_dns; struct GNUNET_OS_Process *proc; @@ -197,8 +200,8 @@ send_answer(void* cls, size_t size, void* buf) { struct tunnel_cls { struct GNUNET_MESH_Tunnel *tunnel GNUNET_PACKED; - struct GNUNET_MessageHeader hdr GNUNET_PACKED; - struct dns_pkt dns GNUNET_PACKED; + struct GNUNET_MessageHeader hdr; + struct dns_pkt dns; }; struct tunnel_cls *remote_pending[UINT16_MAX]; @@ -704,7 +707,7 @@ receive_query(void *cls, } char* virt_dns; - int virt_dns_bytes; + unsigned int virt_dns_bytes; if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", &virt_dns)) @@ -899,6 +902,8 @@ static void cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + GNUNET_assert(0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); + unhijack(dnsoutport); GNUNET_DHT_disconnect(dht); } @@ -1156,7 +1161,7 @@ run (void *cls, {NULL, 0, 0} }; - const static GNUNET_MESH_ApplicationType apptypes[] = + static const GNUNET_MESH_ApplicationType apptypes[] = { GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, GNUNET_APPLICATION_TYPE_END }; -- 2.25.1