From b58b1faf9210812c2c68b1fa69d98e765896c368 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. Reviewed-on: http://gerrit.openafs.org/2987 Reviewed-by: Derrick Brashear Tested-by: BuildBot Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman (cherry picked from commit 3616cdc306f58f90be1cb4f524aa5720d8d638fe) Change-Id: I45f839aeba7d7611ab170f6c58cc30547a2e640f Reviewed-on: http://gerrit.openafs.org/3169 Tested-by: Derrick Brashear --- src/des/stats.h | 15 +++++------ 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 ++-- 15 files changed, 53 insertions(+), 83 deletions(-) diff --git a/src/des/stats.h b/src/des/stats.h index bbb188a21..17d4f1140 100644 --- a/src/des/stats.h +++ b/src/des/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 diff --git a/src/rx/rx.c b/src/rx/rx.c index 05df264ae..2f885ded7 100644 --- a/src/rx/rx.c +++ b/src/rx/rx.c @@ -160,7 +160,6 @@ static unsigned int rxi_rpc_process_stat_cnt; #endif #ifdef AFS_PTHREAD_ENV -#include /* * Use procedural initialization of mutexes/condition variables @@ -217,12 +216,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(); @@ -247,8 +246,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 572f64d36..d2ce7e9d2 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 d62420408..506935a7e 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 f381e1152..bdae086b9 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 7620481d4..5554b4f57 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 fd15de580..2a81b0365 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_globals.h" # include @@ -179,8 +178,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) @@ -335,11 +333,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; @@ -369,11 +367,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 288384982..bdbeab295 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 a8b84cb34..1850da9ff 100644 --- a/src/rx/rx_packet.c +++ b/src/rx/rx_packet.c @@ -79,7 +79,6 @@ #include "rx_packet.h" #include "rx_globals.h" #include -#include #include #ifdef HAVE_UNISTD_H #include @@ -2534,7 +2533,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", 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 c4e176484..0576d767e 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 @@ -108,14 +108,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"); } /* @@ -123,8 +120,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(); } @@ -228,8 +224,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 */ } } @@ -260,12 +255,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; @@ -307,13 +302,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; @@ -338,22 +333,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"); } MUTEX_ENTER(&rx_pthread_mutex); ++rxi_pthread_hinum; @@ -378,21 +368,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"); } MUTEX_ENTER(&rx_pthread_mutex); ++rxi_pthread_hinum; @@ -451,7 +436,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 d0d6a37fc..50bad2ccc 100644 --- a/src/rx/rx_rdwr.c +++ b/src/rx/rx_rdwr.c @@ -263,7 +263,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 1b6d829e8..2e44176d8 100644 --- a/src/rx/rx_user.c +++ b/src/rx/rx_user.c @@ -61,7 +61,6 @@ # include "rx_globals.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 a5c410a91..04f3ecbc4 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 11c4d60b7..ad06d3420 100644 --- a/src/rxkad/rxkad_common.c +++ b/src/rxkad/rxkad_common.c @@ -103,12 +103,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)); } @@ -116,7 +116,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); @@ -126,7 +126,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 7ba99fb05..25467d3cf 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 -- 2.39.5