summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-28 16:21:34 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-28 16:21:34 +0000
commitde30f210414a1f1f296c0cfb4406b171c1fc7b62 (patch)
tree570cc93d141bb7e250c4e73fafc53eba7d6e70bc
parent652e255add3511262060f3a13517716a72e3cb52 (diff)
generally use GNUNET_assert() instead of GNUNET_abort() to also log the error
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c6
-rw-r--r--src/cadet/test_cadet.c2
-rw-r--r--src/consensus/test_consensus_api.c2
-rw-r--r--src/core/test_core_api_mq.c4
-rw-r--r--src/include/gnunet_common.h8
-rw-r--r--src/mysql/mysql.c2
-rw-r--r--src/regex/gnunet-regex-profiler.c6
-rw-r--r--src/rps/gnunet-service-rps_sampler.c2
-rw-r--r--src/util/common_allocation.c6
-rw-r--r--src/util/common_logging.c4
-rw-r--r--src/util/crypto_random.c2
-rw-r--r--src/util/mq.c4
-rw-r--r--src/util/network.c2
-rw-r--r--src/util/os_installation.c4
-rw-r--r--src/util/scheduler.c4
-rw-r--r--src/util/test_mq_client.c2
16 files changed, 31 insertions, 29 deletions
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index 3d9db4d4c..bfb11fc7f 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -519,7 +519,7 @@ core_init (void *cls,
GNUNET_NO, /* For header-only out notification */
core_handlers); /* Register these handlers */
if (10 < i++)
- GNUNET_abort();
+ GNUNET_assert (0);
}
GML_start ();
return;
@@ -1069,7 +1069,7 @@ fill_buf (struct CadetPeerQueue *queue, void *buf, size_t size, uint32_t *pid)
case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY:
/* This should be encapsulted */
msg_size = 0;
- GNUNET_abort ();
+ GNUNET_assert (0);
break;
default:
GNUNET_break (0);
@@ -1340,7 +1340,7 @@ GCP_queue_add (struct CadetPeer *peer, void *cls, uint16_t type,
GCC_2s (c), c, GC_f2s (fwd), GCP_2s (peer), size);
if (error_level == GNUNET_ERROR_TYPE_ERROR)
- GNUNET_abort ();
+ GNUNET_assert (0);
if (NULL == peer->connections)
{
/* We are not connected to this peer, ignore request. */
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index 432369bd2..4c8b3e354 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -599,7 +599,7 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Client %li not valid.\n", client);
- GNUNET_abort ();
+ GNUNET_assert (0);
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: (%d/%d)\n", ok, ok_goal);
data = (uint32_t *) &message[1];
diff --git a/src/consensus/test_consensus_api.c b/src/consensus/test_consensus_api.c
index bfd73c655..631215f14 100644
--- a/src/consensus/test_consensus_api.c
+++ b/src/consensus/test_consensus_api.c
@@ -40,7 +40,7 @@ conclude_done (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "conclude over\n");
if (2 != elements_received)
- GNUNET_abort ();
+ GNUNET_assert (0);
GNUNET_SCHEDULER_shutdown ();
}
diff --git a/src/core/test_core_api_mq.c b/src/core/test_core_api_mq.c
index 9b2603a6c..b9ef9ea05 100644
--- a/src/core/test_core_api_mq.c
+++ b/src/core/test_core_api_mq.c
@@ -88,7 +88,7 @@ handle_test (void *cls,
}
if (num_received > NUM_MSG)
{
- GNUNET_abort ();
+ GNUNET_assert (0);
return GNUNET_SYSERR;
}
return GNUNET_OK;
@@ -127,7 +127,7 @@ run (void *cls,
GNUNET_NO, handlers);
if (NULL == core)
{
- GNUNET_abort ();
+ GNUNET_assert (0);
return;
}
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL);
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index f2fa4b16f..fc5cb80d9 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -443,9 +443,11 @@ GNUNET_log_config_invalid (enum GNUNET_ErrorType kind,
/**
* @ingroup logging
* Abort the process, generate a core dump if possible.
+ * Most code should use `GNUNET_assert (0)` instead to
+ * first log the location of the failure.
*/
void
-GNUNET_abort (void) GNUNET_NORETURN;
+GNUNET_abort_ (void) GNUNET_NORETURN;
/**
@@ -585,14 +587,14 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
* @ingroup logging
* Use this for fatal errors that cannot be handled
*/
-#define GNUNET_assert(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), __FILE__, __LINE__); GNUNET_abort(); } } while(0)
+#define GNUNET_assert(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), __FILE__, __LINE__); GNUNET_abort_(); } } while(0)
/**
* @ingroup logging
* Use this for fatal errors that cannot be handled
*/
-#define GNUNET_assert_at(cond, f, l) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), f, l); GNUNET_abort(); } } while(0)
+#define GNUNET_assert_at(cond, f, l) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), f, l); GNUNET_abort_(); } } while(0)
/**
diff --git a/src/mysql/mysql.c b/src/mysql/mysql.c
index 6ee685b34..2955bcf9c 100644
--- a/src/mysql/mysql.c
+++ b/src/mysql/mysql.c
@@ -38,7 +38,7 @@
* a failure of the command 'cmd' with the message given
* by strerror(errno).
*/
-#define DIE_MYSQL(cmd, dbh) do { GNUNET_log_from (GNUNET_ERROR_TYPE__ERROR, "mysql", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, mysql_error((dbh)->dbf)); GNUNET_abort(); } while(0);
+#define DIE_MYSQL(cmd, dbh) do { GNUNET_log_from (GNUNET_ERROR_TYPE__ERROR, "mysql", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, mysql_error((dbh)->dbf)); GNUNET_assert (0); } while(0);
/**
* Log an error message at log-level 'level' that indicates
diff --git a/src/regex/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c
index aa482d672..5bbae2730 100644
--- a/src/regex/gnunet-regex-profiler.c
+++ b/src/regex/gnunet-regex-profiler.c
@@ -927,7 +927,7 @@ daemon_started (void *cls, struct GNUNET_TESTBED_Operation *op,
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to start/stop daemon at peer %u: %s\n", peer->id, emsg);
- GNUNET_abort ();
+ GNUNET_assert (0);
}
else
{
@@ -942,7 +942,7 @@ daemon_started (void *cls, struct GNUNET_TESTBED_Operation *op,
{
search_peer = (search_peer + 1) % num_peers;
if (i > num_peers)
- GNUNET_abort (); /* we ran out of peers, must be a bug */
+ GNUNET_assert (0); /* we ran out of peers, must be a bug */
}
peers[search_peer].search_str = search_strings[peer->id];
peers[search_peer].search_str_matched = GNUNET_NO;
@@ -1038,7 +1038,7 @@ dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
if (NULL != emsg || NULL == op || NULL == ca_result)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "DHT connect failed: %s\n", emsg);
- GNUNET_abort ();
+ GNUNET_assert (0);
}
GNUNET_assert (NULL != peer->dht_handle);
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c
index 27c65fff6..0cbfc901b 100644
--- a/src/rps/gnunet-service-rps_sampler.c
+++ b/src/rps/gnunet-service-rps_sampler.c
@@ -748,7 +748,7 @@ RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
else if (GNUNET_NO == for_client)
gpc->get_peer_task = GNUNET_SCHEDULER_add_now (&sampler_get_rand_peer2, gpc);
else
- GNUNET_abort ();
+ GNUNET_assert (0);
GNUNET_CONTAINER_DLL_insert (gpc_head, gpc_tail, gpc);
}
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index f89af191c..c31ad6253 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -72,7 +72,7 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
if (ret == NULL)
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc");
- GNUNET_abort ();
+ GNUNET_assert (0);
}
return ret;
}
@@ -108,7 +108,7 @@ GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename,
if (ret == NULL)
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc");
- GNUNET_abort ();
+ GNUNET_assert (0);
}
#ifdef W32_MEM_LIMIT
*((size_t *) ret) = size;
@@ -178,7 +178,7 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber)
if ((NULL == ptr) && (n > 0))
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc");
- GNUNET_abort ();
+ GNUNET_assert (0);
}
#ifdef W32_MEM_LIMIT
ptr = &((size_t *) ptr)[1];
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 747b80a63..695b49913 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -281,7 +281,7 @@ resize_logdefs ()
* Abort the process, generate a core dump if possible.
*/
void
-GNUNET_abort ()
+GNUNET_abort_ ()
{
#if WINDOWS
DebugBreak ();
@@ -1253,7 +1253,7 @@ GNUNET_util_cl_init ()
#endif
#if WINDOWS
if (!InitializeCriticalSectionAndSpinCount (&output_message_cs, 0x00000400))
- GNUNET_abort ();
+ GNUNET_abort_ ();
#endif
}
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 616f5534c..2960af17e 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -283,7 +283,7 @@ GNUNET_CRYPTO_random_init ()
FPRINTF (stderr,
_("libgcrypt has not the expected version (version %s is required).\n"),
NEED_LIBGCRYPT_VERSION);
- GNUNET_abort ();
+ GNUNET_assert (0);
}
if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0)))
FPRINTF (stderr,
diff --git a/src/util/mq.c b/src/util/mq.c
index b73cf176f..14e0816e2 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -398,9 +398,9 @@ const struct GNUNET_MessageHeader *
GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq)
{
if (NULL == mq->current_envelope)
- GNUNET_abort ();
+ GNUNET_assert (0);
if (NULL == mq->current_envelope->mh)
- GNUNET_abort ();
+ GNUNET_assert (0);
return mq->current_envelope->mh;
}
diff --git a/src/util/network.c b/src/util/network.c
index 22e77818d..63dfe330b 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -1923,7 +1923,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
wfds ? awrite.fd_count : 0,
aexcept.fd_count,
GetLastError ());
- GNUNET_abort ();
+ GNUNET_assert (0);
}
/* Check aexcept, if something is in there and we copied that
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index cf3c027e9..bc7e49512 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -173,7 +173,7 @@ get_path_from_module_filename ()
real_pathlen = GetModuleFileNameW (dll_instance, modulepath, pathlen * sizeof (wchar_t));
} while (real_pathlen >= pathlen && pathlen < 16*1024);
if (real_pathlen >= pathlen)
- GNUNET_abort ();
+ GNUNET_assert (0);
/* To be safe */
modulepath[real_pathlen] = '\0';
@@ -215,7 +215,7 @@ get_path_from_module_filename ()
/* modulepath is GNUNET_PREFIX */
u8_string = u16_to_u8 (modulepath, wcslen (modulepath), NULL, &u8_string_length);
if (NULL == u8_string)
- GNUNET_abort ();
+ GNUNET_assert (0);
upath = GNUNET_malloc (u8_string_length + 1);
memcpy (upath, u8_string, u8_string_length);
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 351b20f22..d78de9468 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -580,7 +580,7 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs,
if ((0 != (tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) &&
(-1 != pos->write_fd) &&
(!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd)))
- GNUNET_abort (); // added to ready in previous select loop!
+ GNUNET_assert (0); // added to ready in previous select loop!
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Running task: %p\n",
pos);
@@ -801,7 +801,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
"system");
#endif
#endif
- GNUNET_abort ();
+ GNUNET_assert (0);
break;
}
if ( (0 == ret) &&
diff --git a/src/util/test_mq_client.c b/src/util/test_mq_client.c
index a8a1a64a0..61e027df5 100644
--- a/src/util/test_mq_client.c
+++ b/src/util/test_mq_client.c
@@ -105,7 +105,7 @@ send_cb (void *cls)
static void
send_trap_cb (void *cls)
{
- GNUNET_abort ();
+ GNUNET_assert (0);
}