From 3616cdc306f58f90be1cb4f524aa5720d8d638fe Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 14 Oct 2010 17:24:33 -0400 Subject: [PATCH] Rx: use osi_Assert/osi_Panic instead of assert Avoid using the openafs src/util/assert.h implementation for Rx and Rx security classes. Use the built-in osi_Assert() and osi_Panic() functionality instead. This avoids all references to assert.h except for rx_pthread.c (Unix only) which requires it for the assert() references in the src/util/pthread_nosigs.h macros. Change-Id: I5fbfcd57da381e02e716e7688a58918aed05c50f Reviewed-on: http://gerrit.openafs.org/2987 Reviewed-by: Derrick Brashear Tested-by: BuildBot Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman --- src/rx/rx.c | 12 +++++------ src/rx/rx_clock.c | 7 ++---- src/rx/rx_conncache.c | 1 - src/rx/rx_event.c | 1 - src/rx/rx_globals.h | 2 +- src/rx/rx_lwp.c | 16 ++++++-------- src/rx/rx_misc.c | 1 - src/rx/rx_packet.c | 3 +-- src/rx/rx_pthread.c | 55 ++++++++++++++++++------------------------------ src/rx/rx_rdwr.c | 2 +- src/rx/rx_user.c | 1 - src/rxkad/rxkad_client.c | 5 ++--- src/rxkad/rxkad_common.c | 10 ++++----- src/rxkad/rxkad_server.c | 5 ++--- src/rxkad/stats.h | 15 ++++++------- 15 files changed, 53 insertions(+), 83 deletions(-) diff --git a/src/rx/rx.c b/src/rx/rx.c index 29f76b1..ff89d7e 100644 --- a/src/rx/rx.c +++ b/src/rx/rx.c @@ -173,7 +173,6 @@ afs_kmutex_t rx_atomic_mutex; #endif #ifdef AFS_PTHREAD_ENV -#include /* * Use procedural initialization of mutexes/condition variables @@ -230,12 +229,12 @@ rxi_InitPthread(void) MUTEX_INIT(&rxkad_random_mutex, "rxkad random", MUTEX_DEFAULT, 0); MUTEX_INIT(&rx_debug_mutex, "debug", MUTEX_DEFAULT, 0); - assert(pthread_cond_init + osi_Assert(pthread_cond_init (&rx_event_handler_cond, (const pthread_condattr_t *)0) == 0); - assert(pthread_cond_init(&rx_listener_cond, (const pthread_condattr_t *)0) + osi_Assert(pthread_cond_init(&rx_listener_cond, (const pthread_condattr_t *)0) == 0); - assert(pthread_key_create(&rx_thread_id_key, NULL) == 0); - assert(pthread_key_create(&rx_ts_info_key, NULL) == 0); + osi_Assert(pthread_key_create(&rx_thread_id_key, NULL) == 0); + osi_Assert(pthread_key_create(&rx_ts_info_key, NULL) == 0); rxkad_global_stats_init(); @@ -260,8 +259,7 @@ rxi_InitPthread(void) } pthread_once_t rx_once_init = PTHREAD_ONCE_INIT; -#define INIT_PTHREAD_LOCKS \ -assert(pthread_once(&rx_once_init, rxi_InitPthread)==0) +#define INIT_PTHREAD_LOCKS osi_Assert(pthread_once(&rx_once_init, rxi_InitPthread)==0) /* * The rx_stats_mutex mutex protects the following global variables: * rxi_lowConnRefCount diff --git a/src/rx/rx_clock.c b/src/rx/rx_clock.c index 572f64d..d2ce7e9 100644 --- a/src/rx/rx_clock.c +++ b/src/rx/rx_clock.c @@ -41,7 +41,6 @@ #include #include #include -#include #include "rx.h" #include "rx_clock.h" #endif @@ -74,10 +73,8 @@ clock_Sync(void) signal(SIGALRM, SIG_IGN); if (setitimer(ITIMER_REAL, &itimer, &otimer) != 0) { - fprintf(stderr, "clock: could not set interval timer; \ - aborted(errno=%d)\n", errno); - fflush(stderr); - assert(0); + osi_Panic("clock: could not set interval timer; aborted(errno=%d)\n", + errno); } if (relclock_epoch.usec + startvalue.usec >= otimer.it_value.tv_usec) { relclock_epoch.sec = relclock_epoch.sec + diff --git a/src/rx/rx_conncache.c b/src/rx/rx_conncache.c index d624204..506935a 100644 --- a/src/rx/rx_conncache.c +++ b/src/rx/rx_conncache.c @@ -16,7 +16,6 @@ #include #include -#include #include "rx.h" /* diff --git a/src/rx/rx_event.c b/src/rx/rx_event.c index f677392..04f5a18 100644 --- a/src/rx/rx_event.c +++ b/src/rx/rx_event.c @@ -106,7 +106,6 @@ afs_kmutex_t rxevent_lock; * rxevent_initialized */ -#include afs_kmutex_t rx_event_mutex; #define LOCK_EV_INIT MUTEX_ENTER(&rx_event_mutex) #define UNLOCK_EV_INIT MUTEX_EXIT(&rx_event_mutex) diff --git a/src/rx/rx_globals.h b/src/rx/rx_globals.h index e8b947b..85e6215 100644 --- a/src/rx/rx_globals.h +++ b/src/rx/rx_globals.h @@ -196,7 +196,7 @@ EXT struct rx_ts_info_t * rx_ts_info_init(void); /* init function for thread-s do { \ ts_info_p = (struct rx_ts_info_t*)pthread_getspecific(rx_ts_info_key); \ if (ts_info_p == NULL) { \ - assert((ts_info_p = rx_ts_info_init()) != NULL); \ + osi_Assert((ts_info_p = rx_ts_info_init()) != NULL); \ } \ } while(0) #endif /* AFS_PTHREAD_ENV */ diff --git a/src/rx/rx_lwp.c b/src/rx/rx_lwp.c index c87ce23..8675992 100644 --- a/src/rx/rx_lwp.c +++ b/src/rx/rx_lwp.c @@ -42,7 +42,6 @@ # include # include #endif -# include # include "rx.h" # include "rx_atomic.h" # include "rx_globals.h" @@ -181,8 +180,7 @@ rxi_ListenerProc(fd_set * rfds, int *tnop, struct rx_call **newcallp) nextPollTime = 0; code = LWP_CurrentProcess(&pid); if (code) { - fprintf(stderr, "rxi_Listener: Can't get my pid.\n"); - assert(0); + osi_Panic("rxi_Listener: Can't get my pid.\n"); } rx_listenerPid = pid; if (swapNameProgram) @@ -338,11 +336,11 @@ rx_ListenerProc(void *dummy) newcall = NULL; threadID = -1; rxi_ListenerProc(rfds, &threadID, &newcall); - /* assert(threadID != -1); */ - /* assert(newcall != NULL); */ + /* osi_Assert(threadID != -1); */ + /* osi_Assert(newcall != NULL); */ sock = OSI_NULLSOCKET; rxi_ServerProc(threadID, newcall, &sock); - /* assert(sock != OSI_NULLSOCKET); */ + /* osi_Assert(sock != OSI_NULLSOCKET); */ } /* not reached */ return NULL; @@ -372,11 +370,11 @@ rx_ServerProc(void * unused) while (1) { sock = OSI_NULLSOCKET; rxi_ServerProc(threadID, newcall, &sock); - /* assert(sock != OSI_NULLSOCKET); */ + /* osi_Assert(sock != OSI_NULLSOCKET); */ newcall = NULL; rxi_ListenerProc(rfds, &threadID, &newcall); - /* assert(threadID != -1); */ - /* assert(newcall != NULL); */ + /* osi_Assert(threadID != -1); */ + /* osi_Assert(newcall != NULL); */ } /* not reached */ return NULL; diff --git a/src/rx/rx_misc.c b/src/rx/rx_misc.c index 2883849..bdbeab2 100644 --- a/src/rx/rx_misc.c +++ b/src/rx/rx_misc.c @@ -103,7 +103,6 @@ ntoh_syserr_conv(int code) * osi_allocsize */ -#include afs_kmutex_t osi_malloc_mutex; #define LOCK_MALLOC_STATS MUTEX_ENTER(&osi_malloc_mutex); #define UNLOCK_MALLOC_STATS MUTEX_EXIT(&osi_malloc_mutex); diff --git a/src/rx/rx_packet.c b/src/rx/rx_packet.c index aba4689..69471d9 100644 --- a/src/rx/rx_packet.c +++ b/src/rx/rx_packet.c @@ -88,7 +88,6 @@ #include "rx_internal.h" #include "rx_stats.h" #include -#include #include #ifdef HAVE_UNISTD_H #include @@ -2545,7 +2544,7 @@ rxi_SendPacketList(struct rx_call *call, struct rx_connection *conn, #ifdef RXDEBUG } - assert(p != NULL); + osi_Assert(p != NULL); dpf(("%c %d %s: %x.%u.%u.%u.%u.%u.%u flags %d, packet %"AFS_PTR_FMT" resend %d.%.3d len %d\n", deliveryType, p->header.serial, rx_packetTypes[p->header.type - 1], ntohl(peer->host), diff --git a/src/rx/rx_pthread.c b/src/rx/rx_pthread.c index 9d73b87..ae92c67 100644 --- a/src/rx/rx_pthread.c +++ b/src/rx/rx_pthread.c @@ -35,11 +35,11 @@ # include # include # include +# include #endif #include #include #include -#include #include #include #include "rx_atomic.h" @@ -116,14 +116,11 @@ rxi_StartServerProc(void *(*proc) (void *), int stacksize) AFS_SIGSET_DECL; if (pthread_attr_init(&tattr) != 0) { - dpf(("Unable to Create Rx server thread (pthread_attr_init)\n")); - assert(0); + osi_Panic("Unable to Create Rx server thread (pthread_attr_init)\n"); } if (pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) != 0) { - dpf - (("Unable to Create Rx server thread (pthread_attr_setdetachstate)\n")); - assert(0); + osi_Panic("Unable to Create Rx server thread (pthread_attr_setdetachstate)\n"); } /* @@ -131,8 +128,7 @@ rxi_StartServerProc(void *(*proc) (void *), int stacksize) */ AFS_SIGSET_CLEAR(); if (pthread_create(&thread, &tattr, server_entry, (void *)proc) != 0) { - dpf(("Unable to Create Rx server thread\n")); - assert(0); + osi_Panic("Unable to Create Rx server thread\n"); } AFS_SIGSET_RESTORE(); } @@ -236,8 +232,7 @@ rxi_ListenerProc(osi_socket sock, int *tnop, struct rx_call **newcallp) } else { if (!(p = rxi_AllocPacket(RX_PACKET_CLASS_RECEIVE))) { /* Could this happen with multiple socket listeners? */ - dpf(("rxi_Listener: no packets!")); /* Shouldn't happen */ - assert(0); + osi_Panic("rxi_Listener: no packets!"); /* Shouldn't happen */ } } @@ -268,12 +263,12 @@ rx_ListenerProc(void *argp) newcall = NULL; threadID = -1; rxi_ListenerProc(sock, &threadID, &newcall); - /* assert(threadID != -1); */ - /* assert(newcall != NULL); */ + /* osi_Assert(threadID != -1); */ + /* osi_Assert(newcall != NULL); */ sock = OSI_NULLSOCKET; - assert(pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)threadID) == 0); + osi_Assert(pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)threadID) == 0); rxi_ServerProc(threadID, newcall, &sock); - /* assert(sock != OSI_NULLSOCKET); */ + /* osi_Assert(sock != OSI_NULLSOCKET); */ } /* not reached */ return NULL; @@ -315,13 +310,13 @@ rx_ServerProc(void * dummy) while (1) { sock = OSI_NULLSOCKET; - assert(pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)threadID) == 0); + osi_Assert(pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)threadID) == 0); rxi_ServerProc(threadID, newcall, &sock); - /* assert(sock != OSI_NULLSOCKET); */ + /* osi_Assert(sock != OSI_NULLSOCKET); */ newcall = NULL; rxi_ListenerProc(sock, &threadID, &newcall); - /* assert(threadID != -1); */ - /* assert(newcall != NULL); */ + /* osi_Assert(threadID != -1); */ + /* osi_Assert(newcall != NULL); */ } /* not reached */ return NULL; @@ -346,22 +341,17 @@ rxi_StartListener(void) return; if (pthread_attr_init(&tattr) != 0) { - dpf - (("Unable to create Rx event handling thread (pthread_attr_init)\n")); - assert(0); + osi_Panic("Unable to create Rx event handling thread (pthread_attr_init)\n"); } if (pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) != 0) { - dpf - (("Unable to create Rx event handling thread (pthread_attr_setdetachstate)\n")); - assert(0); + osi_Panic("Unable to create Rx event handling thread (pthread_attr_setdetachstate)\n"); } AFS_SIGSET_CLEAR(); if (pthread_create(&event_handler_thread, &tattr, event_handler, NULL) != 0) { - dpf(("Unable to create Rx event handling thread\n")); - assert(0); + osi_Panic("Unable to create Rx event handling thread\n"); } rx_NewThreadId(); AFS_SIGSET_RESTORE(); @@ -384,21 +374,16 @@ rxi_Listen(osi_socket sock) AFS_SIGSET_DECL; if (pthread_attr_init(&tattr) != 0) { - dpf - (("Unable to create socket listener thread (pthread_attr_init)\n")); - assert(0); + osi_Panic("Unable to create socket listener thread (pthread_attr_init)\n"); } if (pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) != 0) { - dpf - (("Unable to create socket listener thread (pthread_attr_setdetachstate)\n")); - assert(0); + osi_Panic("Unable to create socket listener thread (pthread_attr_setdetachstate)\n"); } AFS_SIGSET_CLEAR(); if (pthread_create(&thread, &tattr, rx_ListenerProc, (void *)(intptr_t)sock) != 0) { - dpf(("Unable to create socket listener thread\n")); - assert(0); + osi_Panic("Unable to create socket listener thread\n"); } rx_NewThreadId(); AFS_SIGSET_RESTORE(); @@ -455,7 +440,7 @@ rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags) struct rx_ts_info_t * rx_ts_info_init(void) { struct rx_ts_info_t * rx_ts_info; rx_ts_info = (rx_ts_info_t *) malloc(sizeof(rx_ts_info_t)); - assert(rx_ts_info != NULL && pthread_setspecific(rx_ts_info_key, rx_ts_info) == 0); + osi_Assert(rx_ts_info != NULL && pthread_setspecific(rx_ts_info_key, rx_ts_info) == 0); memset(rx_ts_info, 0, sizeof(rx_ts_info_t)); #ifdef RX_ENABLE_TSFPQ queue_Init(&rx_ts_info->_FPQ); diff --git a/src/rx/rx_rdwr.c b/src/rx/rx_rdwr.c index 1752a8d..90f2015 100644 --- a/src/rx/rx_rdwr.c +++ b/src/rx/rx_rdwr.c @@ -265,7 +265,7 @@ rxi_ReadProc(struct rx_call *call, char *buf, } MUTEX_EXIT(&call->lock); } else - /* assert(cp); */ + /* osi_Assert(cp); */ /* MTUXXX this should be replaced by some error-recovery code before shipping */ /* yes, the following block is allowed to be the ELSE clause (or not) */ /* It's possible for call->nLeft to be smaller than any particular diff --git a/src/rx/rx_user.c b/src/rx/rx_user.c index 26cc01d..32f4c06 100644 --- a/src/rx/rx_user.c +++ b/src/rx/rx_user.c @@ -62,7 +62,6 @@ #include "rx_globals.h" #include "rx_stats.h" #ifdef AFS_PTHREAD_ENV -#include /* * The rx_if_init_mutex mutex protects the following global variables: diff --git a/src/rxkad/rxkad_client.c b/src/rxkad/rxkad_client.c index a17787b..4d564cc 100644 --- a/src/rxkad/rxkad_client.c +++ b/src/rxkad/rxkad_client.c @@ -96,10 +96,9 @@ static struct rx_securityOps rxkad_client_ops = { * counter * rxkad_EpochWasSet */ -#include pthread_mutex_t rxkad_client_uid_mutex; -#define LOCK_CUID assert(pthread_mutex_lock(&rxkad_client_uid_mutex)==0) -#define UNLOCK_CUID assert(pthread_mutex_unlock(&rxkad_client_uid_mutex)==0) +#define LOCK_CUID osi_Assert(pthread_mutex_lock(&rxkad_client_uid_mutex)==0) +#define UNLOCK_CUID osi_Assert(pthread_mutex_unlock(&rxkad_client_uid_mutex)==0) #else #define LOCK_CUID #define UNLOCK_CUID diff --git a/src/rxkad/rxkad_common.c b/src/rxkad/rxkad_common.c index de57f42..1db7361 100644 --- a/src/rxkad/rxkad_common.c +++ b/src/rxkad/rxkad_common.c @@ -99,12 +99,12 @@ struct rxkad_stats rxkad_stats = { { 0 } }; (ptr)->prev->next = (ptr); \ else \ (head) = (ptr); \ - assert((head) && ((head)->prev == NULL)); \ + osi_Assert((head) && ((head)->prev == NULL)); \ } while(0) void rxkad_global_stats_init(void) { - assert(pthread_mutex_init(&rxkad_global_stats_lock, (const pthread_mutexattr_t *)0) == 0); - assert(pthread_key_create(&rxkad_stats_key, NULL) == 0); + osi_Assert(pthread_mutex_init(&rxkad_global_stats_lock, (const pthread_mutexattr_t *)0) == 0); + osi_Assert(pthread_key_create(&rxkad_stats_key, NULL) == 0); memset(&rxkad_global_stats, 0, sizeof(rxkad_global_stats)); } @@ -112,7 +112,7 @@ rxkad_stats_t * rxkad_thr_stats_init(void) { rxkad_stats_t * rxkad_stats; rxkad_stats = (rxkad_stats_t *)malloc(sizeof(rxkad_stats_t)); - assert(rxkad_stats != NULL && pthread_setspecific(rxkad_stats_key,rxkad_stats) == 0); + osi_Assert(rxkad_stats != NULL && pthread_setspecific(rxkad_stats_key,rxkad_stats) == 0); memset(rxkad_stats,0,sizeof(rxkad_stats_t)); RXKAD_GLOBAL_STATS_LOCK; DLL_INSERT_TAIL(rxkad_stats, rxkad_global_stats.first, rxkad_global_stats.last, next, prev); @@ -122,7 +122,7 @@ rxkad_thr_stats_init(void) { int rxkad_stats_agg(rxkad_stats_t * rxkad_stats) { rxkad_stats_t * thr_stats; - assert(rxkad_stats != NULL); + osi_Assert(rxkad_stats != NULL); memset(rxkad_stats, 0, sizeof(rxkad_stats_t)); RXKAD_GLOBAL_STATS_LOCK; for (thr_stats = rxkad_global_stats.first; thr_stats != NULL; thr_stats = thr_stats->next) { diff --git a/src/rxkad/rxkad_server.c b/src/rxkad/rxkad_server.c index a0ca534..4bb6009 100644 --- a/src/rxkad/rxkad_server.c +++ b/src/rxkad/rxkad_server.c @@ -80,14 +80,13 @@ static fc_KeySchedule random_int32_schedule; * seed */ -#include pthread_mutex_t rxkad_random_mutex #ifdef PTHREAD_MUTEX_INITIALIZER = PTHREAD_MUTEX_INITIALIZER #endif ; -#define LOCK_RM assert(pthread_mutex_lock(&rxkad_random_mutex)==0) -#define UNLOCK_RM assert(pthread_mutex_unlock(&rxkad_random_mutex)==0) +#define LOCK_RM osi_Assert(pthread_mutex_lock(&rxkad_random_mutex)==0) +#define UNLOCK_RM osi_Assert(pthread_mutex_unlock(&rxkad_random_mutex)==0) #else #define LOCK_RM #define UNLOCK_RM diff --git a/src/rxkad/stats.h b/src/rxkad/stats.h index 9e878c1..3df9c3e 100644 --- a/src/rxkad/stats.h +++ b/src/rxkad/stats.h @@ -66,7 +66,6 @@ struct rxkad_global_stats { }; #include -#include extern pthread_mutex_t rxkad_global_stats_lock; extern pthread_key_t rxkad_stats_key; @@ -78,14 +77,14 @@ extern int rxkad_stats_agg(rxkad_stats_t *); #define BEGIN do { #define END } while(0) #endif -#define RXKAD_GLOBAL_STATS_LOCK assert(pthread_mutex_lock(&rxkad_global_stats_lock)==0) -#define RXKAD_GLOBAL_STATS_UNLOCK assert(pthread_mutex_unlock(&rxkad_global_stats_lock)==0) +#define RXKAD_GLOBAL_STATS_LOCK osi_Assert(pthread_mutex_lock(&rxkad_global_stats_lock)==0) +#define RXKAD_GLOBAL_STATS_UNLOCK osi_Assert(pthread_mutex_unlock(&rxkad_global_stats_lock)==0) #define GET_RXKAD_STATS(stats) rxkad_stats_agg(stats) #define GET_RXKAD_THR_STATS(rxkad_stats) \ BEGIN \ (rxkad_stats) = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \ if ((rxkad_stats) == NULL) { \ - assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \ + osi_Assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \ } \ END #define INC_RXKAD_STATS(stats_elem) \ @@ -93,7 +92,7 @@ extern int rxkad_stats_agg(rxkad_stats_t *); rxkad_stats_t * rxkad_stats; \ rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \ if (rxkad_stats == NULL) { \ - assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \ + osi_Assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \ } \ rxkad_stats->stats_elem++; \ END @@ -102,7 +101,7 @@ extern int rxkad_stats_agg(rxkad_stats_t *); rxkad_stats_t * rxkad_stats; \ rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \ if (rxkad_stats == NULL) { \ - assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \ + osi_Assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \ } \ rxkad_stats->stats_elem--; \ END @@ -112,7 +111,7 @@ extern int rxkad_stats_agg(rxkad_stats_t *); rxkad_stats_t * rxkad_stats; \ rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \ if (rxkad_stats == NULL) { \ - assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \ + osi_Assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \ } \ rxkad_stats->stats_elem += inc_value; \ END @@ -121,7 +120,7 @@ extern int rxkad_stats_agg(rxkad_stats_t *); rxkad_stats_t * rxkad_stats; \ rxkad_stats = ((rxkad_stats_t*)pthread_getspecific(rxkad_stats_key)); \ if (rxkad_stats == NULL) { \ - assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \ + osi_Assert(((rxkad_stats) = rxkad_thr_stats_init()) != NULL); \ } \ rxkad_stats->stats_elem -= dec_value; \ END -- 1.9.4