From 70486ed8cb9e5d7c64842a4721c8d106c01dccd6 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 29 Aug 2009 20:00:36 +0000 Subject: [PATCH] fix check for close --- src/util/disk.c | 43 ++++++++++------------- src/util/server.c | 8 +++-- src/util/test_connection.c | 8 +++-- src/util/test_connection_addressing.c | 4 ++- src/util/test_connection_receive_cancel.c | 4 ++- src/util/test_connection_timeout.c | 4 ++- src/util/test_crypto_hash.c | 2 +- src/util/test_scheduler.c | 2 +- 8 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/util/disk.c b/src/util/disk.c index ef7a62351..412f8fb16 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -1481,18 +1481,17 @@ GNUNET_DISK_pipe (int blocking) return p; } + /** * Closes an interprocess channel - * @param p pipe + * + * @param p pipe to close * @return GNUNET_OK on success, GNUNET_SYSERR otherwise */ int GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) { - int ret; - - ret = GNUNET_OK; - + int ret = GNUNET_OK; #ifdef MINGW if (!CloseHandle (p->fd[0].h)) { @@ -1506,30 +1505,26 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) ret = GNUNET_SYSERR; } #else - { - int save; - - if (close (p->fd[0].fd) != -1) - { - ret = GNUNET_SYSERR; - save = errno; - } - else - save = 0; - - if (close (p->fd[1].fd) != -1) - { - ret = GNUNET_SYSERR; - } - else - errno = save; - } + int save; + + if (0 != close (p->fd[0].fd)) + { + ret = GNUNET_SYSERR; + save = errno; + } + else + save = 0; + + if (0 != close (p->fd[1].fd)) + ret = GNUNET_SYSERR; + else + errno = save; #endif GNUNET_free (p); - return ret; } + /** * Get the handle to a particular pipe end * @param p pipe diff --git a/src/util/server.c b/src/util/server.c index 8fcc20830..c05247a63 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -282,7 +282,9 @@ destroy_server (struct GNUNET_SERVER_Handle *server) "Server shutting down.\n"); #endif GNUNET_assert (server->listen_socket == NULL); - GNUNET_break (GNUNET_YES == GNUNET_DISK_pipe_close (server->shutpipe)); + if (GNUNET_OK != GNUNET_DISK_pipe_close (server->shutpipe)) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, + "pipe-close"); while (server->clients != NULL) { pos = server->clients; @@ -455,7 +457,7 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched, struct GNUNET_NETWORK_Descriptor *lsock; struct GNUNET_NETWORK_FDSet *r; - lsock = NULL; // FIXME NILS: this was -2, does that have a special meaning? + lsock = NULL; if (serverAddr != NULL) { lsock = open_listen_socket (serverAddr, socklen); @@ -464,7 +466,7 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched, } ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Handle)); ret->shutpipe = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileDescriptor *[2])); - if ((ret->shutpipe = GNUNET_DISK_pipe (GNUNET_NO)) == NULL) + if (NULL == (ret->shutpipe = GNUNET_DISK_pipe (GNUNET_NO))) { GNUNET_break (0 == GNUNET_NETWORK_socket_close (lsock)); GNUNET_free (ret->shutpipe); diff --git a/src/util/test_connection.c b/src/util/test_connection.c index 3ca09281d..770b34e8c 100644 --- a/src/util/test_connection.c +++ b/src/util/test_connection.c @@ -40,7 +40,7 @@ static struct GNUNET_CONNECTION_Handle *lsock; static size_t sofar; -static int ls; +static struct GNUNET_NETWORK_Descriptor *ls; @@ -64,7 +64,9 @@ open_listen_socket () if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); - GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, &sa, sizeof (sa)) >= 0); + GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, + (const struct sockaddr*) &sa, + sizeof (sa)) >= 0); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } @@ -113,7 +115,7 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test accepts connection\n"); #endif asock = GNUNET_CONNECTION_create_from_accept (tc->sched, - NULL, NULL, ls, 1024); + NULL, NULL, ls, 1024); GNUNET_assert (asock != NULL); GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); #if VERBOSE diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c index 650b716af..de11560d3 100644 --- a/src/util/test_connection_addressing.c +++ b/src/util/test_connection_addressing.c @@ -63,7 +63,9 @@ open_listen_socket () if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); - GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, &sa, sizeof (sa)) >= 0); + GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, + (const struct sockaddr*) &sa, + sizeof (sa)) >= 0); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c index 338caa737..eb9d906ff 100644 --- a/src/util/test_connection_receive_cancel.c +++ b/src/util/test_connection_receive_cancel.c @@ -64,7 +64,9 @@ open_listen_socket () if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); - GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, &sa, sizeof (sa)) >= 0); + GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, + (const struct sockaddr*) &sa, + sizeof (sa)) >= 0); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } diff --git a/src/util/test_connection_timeout.c b/src/util/test_connection_timeout.c index 61d9a2d07..289bb102a 100644 --- a/src/util/test_connection_timeout.c +++ b/src/util/test_connection_timeout.c @@ -57,7 +57,9 @@ open_listen_socket () if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); - GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, &sa, sizeof (sa)) >= 0); + GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, + (const struct sockaddr*) &sa, + sizeof (sa)) >= 0); GNUNET_NETWORK_socket_listen (desc, 5); return desc; } diff --git a/src/util/test_crypto_hash.c b/src/util/test_crypto_hash.c index a22a0e16a..e10aee9b1 100644 --- a/src/util/test_crypto_hash.c +++ b/src/util/test_crypto_hash.c @@ -98,7 +98,7 @@ testArithmetic () if (1 != GNUNET_CRYPTO_hash_get_bit (&d, 6)) return 1; memset (&d, 0, sizeof (d)); - GNUNET_CRYPTO_hash_to_AES_key (&d, &skey, &iv); + GNUNET_CRYPTO_hash_to_aes_key (&d, &skey, &iv); if ((0 != memcmp (&skey, &zskey, sizeof (skey) - sizeof (unsigned int))) || (0 != memcmp (&iv, &ziv, sizeof (iv)))) return 1; diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c index 34def7b1e..6ae293058 100644 --- a/src/util/test_scheduler.c +++ b/src/util/test_scheduler.c @@ -57,7 +57,7 @@ task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } struct GNUNET_DISK_PipeHandle *p; -static struct GNUNET_DISK_FileHandle *fds[2]; +static const struct GNUNET_DISK_FileHandle *fds[2]; static void -- 2.25.1