Changeset 691:78b665400097 in freeDiameter
- Timestamp:
- Jan 20, 2011, 7:44:27 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/test_netemul/tne_process.c
r656 r691 247 247 248 248 CHECK_POSIX_DO( pthread_mutex_lock(&mtx), goto error ); 249 pthread_cleanup_push( fd_cleanup_mutex, &mtx ); 249 250 250 251 /* The loop */ 251 252 while (1) { 252 253 /* First, test if we are canceled */ 253 CHECK_POSIX_DO( pthread_mutex_unlock(&mtx), goto error );254 254 pthread_testcancel(); 255 CHECK_POSIX_DO( pthread_mutex_lock(&mtx), goto error );256 257 pthread_cleanup_push( fd_cleanup_mutex, &mtx );258 255 259 256 /* Send all messages that are ready (free resources before using new ones) */ 260 CHECK_FCT_DO( send_all_ready(), goto error_ul);257 CHECK_FCT_DO( send_all_ready(), break ); 261 258 262 259 /* Now process the new messages in input list for duplicate filter */ 263 CHECK_FCT_DO( do_duplicates(), goto error_ul);260 CHECK_FCT_DO( do_duplicates(), break ); 264 261 265 262 /* Now compute the latency for each new item */ 266 CHECK_FCT_DO( do_latency(), goto error_ul);263 CHECK_FCT_DO( do_latency(), break ); 267 264 268 265 /* Now, wait then loop */ 269 266 if (FD_IS_LIST_EMPTY(&waitlist)) { 270 CHECK_POSIX_DO( pthread_cond_wait(&cnd, &mtx), goto error_ul);267 CHECK_POSIX_DO( pthread_cond_wait(&cnd, &mtx), break ); 271 268 } else { 272 269 CHECK_POSIX_DO2( pthread_cond_timedwait(&cnd, &mtx, &((struct process_item *)(waitlist.next))->ts), 273 270 ETIMEDOUT, /* ETIMEDOUT is a normal return value, continue */, 274 /* on other error, */ goto error_ul);271 /* on other error, */ break ); 275 272 } 276 273 277 pthread_cleanup_pop( 0 );278 274 /* loop */ 279 275 } 280 276 281 error_ul: 277 pthread_cleanup_pop( 0 ); 282 278 CHECK_POSIX_DO( pthread_mutex_unlock(&mtx), ); 283 279 error: -
libfdcore/core.c
r689 r691 241 241 int fd_core_waitstartcomplete(void) 242 242 { 243 int ret = 0; 244 243 245 TRACE_ENTRY(""); 244 246 … … 246 248 pthread_cleanup_push( fd_cleanup_mutex, &is_ready_mtx ); 247 249 248 while (! is_ready) {249 CHECK_POSIX ( pthread_cond_wait( &is_ready_cnd, &is_ready_mtx ));250 while (!ret && !is_ready) { 251 CHECK_POSIX_DO( ret = pthread_cond_wait( &is_ready_cnd, &is_ready_mtx ), ); 250 252 } 251 253 … … 253 255 CHECK_POSIX( pthread_mutex_unlock( &is_ready_mtx ) ); 254 256 255 return 0;257 return ret; 256 258 } 257 259 -
libfdcore/p_cnx.c
r662 r691 211 211 struct next_conn * nc = NULL; 212 212 int rebuilt = 0; 213 int fatal_error=0; 213 214 214 215 TRACE_ENTRY("%p", arg); … … 226 227 if (FD_IS_LIST_EMPTY(&peer->p_connparams)) { 227 228 if (! rebuilt) { 228 CHECK_FCT_DO( prepare_connection_list(peer), goto fatal_error);229 CHECK_FCT_DO( fatal_error = prepare_connection_list(peer), goto out ); 229 230 rebuilt ++; 230 231 } … … 232 233 /* We encountered an error or we have looped over all the addresses of the peer. */ 233 234 TRACE_DEBUG(INFO, "Unable to connect to the peer %s, aborting attempts for now.", peer->p_hdr.info.pi_diamid); 234 CHECK_FCT_DO( f d_event_send(peer->p_events, FDEVP_CNX_FAILED, 0, NULL), goto fatal_error);235 CHECK_FCT_DO( fatal_error = fd_event_send(peer->p_events, FDEVP_CNX_FAILED, 0, NULL), goto out ); 235 236 return NULL; 236 237 } … … 277 278 empty_connection_list(peer); 278 279 fd_ep_filter(&peer->p_hdr.info.pi_endpoints, EP_FL_CONF); 279 return NULL;280 goto out_pop; 280 281 } ); 281 282 } else { 282 283 /* Prepare to receive the next message */ 283 CHECK_FCT_DO( f d_cnx_start_clear(cnx, 0), goto fatal_error);284 CHECK_FCT_DO( fatal_error = fd_cnx_start_clear(cnx, 0), goto out_pop ); 284 285 } 285 286 286 287 /* Upon success, generate FDEVP_CNX_ESTABLISHED */ 287 CHECK_FCT_DO( fd_event_send(peer->p_events, FDEVP_CNX_ESTABLISHED, 0, cnx), goto fatal_error ); 288 288 CHECK_FCT_DO( fatal_error = fd_event_send(peer->p_events, FDEVP_CNX_ESTABLISHED, 0, cnx), ); 289 out_pop: 290 ; 289 291 pthread_cleanup_pop(0); 290 292 291 return NULL; 292 293 fatal_error: 294 /* Cleanup the connection */ 295 if (cnx) 296 fd_cnx_destroy(cnx); 297 298 /* Generate a termination event */ 299 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), ); 293 out: 294 295 if (fatal_error) { 296 297 /* Cleanup the connection */ 298 if (cnx) 299 fd_cnx_destroy(cnx); 300 301 /* Generate a termination event */ 302 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), ); 303 } 300 304 301 305 return NULL; -
libfdcore/p_expiry.c
r686 r691 98 98 TRACE_ENTRY( "%p", arg ); 99 99 100 CHECK_POSIX_DO( pthread_mutex_lock(&exp_mtx), goto error);100 CHECK_POSIX_DO( pthread_mutex_lock(&exp_mtx), { ASSERT(0); } ); 101 101 pthread_cleanup_push( fd_cleanup_mutex, &exp_mtx ); 102 102 … … 108 108 if (FD_IS_LIST_EMPTY(&exp_list)) { 109 109 /* Just wait for a change or cancelation */ 110 CHECK_POSIX_DO( pthread_cond_wait( &exp_cnd, &exp_mtx ), goto error);110 CHECK_POSIX_DO( pthread_cond_wait( &exp_cnd, &exp_mtx ), { ASSERT(0); } ); 111 111 /* Restart the loop on wakeup */ 112 112 continue; … … 118 118 119 119 /* Get the current time */ 120 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), goto error);120 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), { ASSERT(0); } ); 121 121 122 122 /* If first peer is not expired, we just wait until it happens */ … … 125 125 CHECK_POSIX_DO2( pthread_cond_timedwait( &exp_cnd, &exp_mtx, &first->p_exp_timer ), 126 126 ETIMEDOUT, /* ETIMEDOUT is a normal return value, continue */, 127 /* on other error, */ goto error);127 /* on other error, */ { ASSERT(0); } ); 128 128 129 129 /* on wakeup, loop */ … … 133 133 /* Now, the first peer in the list is expired; signal it */ 134 134 fd_list_unlink( &first->p_expiry ); 135 CHECK_FCT_DO( fd_event_send(first->p_events, FDEVP_TERMINATE, 0, "DO_NOT_WANT_TO_TALK_TO_YOU"), goto error);135 CHECK_FCT_DO( fd_event_send(first->p_events, FDEVP_TERMINATE, 0, "DO_NOT_WANT_TO_TALK_TO_YOU"), break ); 136 136 137 137 } while (1); 138 138 139 139 pthread_cleanup_pop( 1 ); 140 error: 140 141 141 TRACE_DEBUG(INFO, "An error occurred in peers module! Expiry thread is terminating..."); 142 ASSERT(0);143 142 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), ); 144 143 return NULL; -
libfdcore/p_out.c
r688 r691 69 69 /* Save a request before sending so that there is no race condition with the answer */ 70 70 if (msg_is_a_req) { 71 CHECK_FCT_DO( ret = fd_p_sr_store(srl, msg, &hdr->msg_hbhid, bkp_hbh), { free(buf); return ret; });71 CHECK_FCT_DO( ret = fd_p_sr_store(srl, msg, &hdr->msg_hbhid, bkp_hbh), goto out ); 72 72 } 73 73 74 74 /* Send the message */ 75 CHECK_FCT_DO( ret = fd_cnx_send(cnx, buf, sz, flags), { free(buf); return ret; } ); 75 CHECK_FCT_DO( ret = fd_cnx_send(cnx, buf, sz, flags), ); 76 out: 77 ; 76 78 pthread_cleanup_pop(1); 79 80 if (ret) 81 return ret; 77 82 78 83 /* Free remaining messages (i.e. answers) */ -
libfdcore/p_psm.c
r688 r691 55 55 static int fd_psm_waitstart() 56 56 { 57 int ret = 0; 57 58 TRACE_ENTRY(""); 58 59 CHECK_POSIX( pthread_mutex_lock(&started_mtx) ); 59 60 awake: 60 if (! 61 if (!ret && !started) { 61 62 pthread_cleanup_push( fd_cleanup_mutex, &started_mtx ); 62 CHECK_POSIX ( pthread_cond_wait(&started_cnd, &started_mtx));63 CHECK_POSIX_DO( ret = pthread_cond_wait(&started_cnd, &started_mtx), ); 63 64 pthread_cleanup_pop( 0 ); 64 65 goto awake; 65 66 } 66 67 CHECK_POSIX( pthread_mutex_unlock(&started_mtx) ); 67 return 0;68 return ret; 68 69 } 69 70 -
libfdcore/p_sr.c
r688 r691 117 117 } 118 118 119 /* thread that handles messages expiring. The thread is started / stopped only when needed */119 /* thread that handles messages expiring. The thread is started / cancelled only when needed */ 120 120 static void * sr_expiry_th(void * arg) { 121 121 struct sr_list * srlist = arg; … … 184 184 ; /* pthread_cleanup_pop sometimes expands as "} ..." and the label beofre this cause some compilers to complain... */ 185 185 pthread_cleanup_pop( 1 ); 186 ASSERT(0); /* we have encountered a problem, maybe time to signal the framework to terminate? */ 186 187 return NULL; 187 188 } -
libfdcore/peers.c
r688 r691 533 533 int auth = 0; 534 534 pthread_cleanup_push(fd_cleanup_rwlock, &validators_rw); 535 CHECK_FCT_DO( ret = ((int(*)(struct peer_info *, int *, int (**)(struct peer_info *)))(v->o)) (&peer->p_hdr.info, &auth, &peer->p_cb2), goto out);535 CHECK_FCT_DO( ret = ((int(*)(struct peer_info *, int *, int (**)(struct peer_info *)))(v->o)) (&peer->p_hdr.info, &auth, &peer->p_cb2), ); 536 536 pthread_cleanup_pop(0); 537 if (ret) 538 goto out; 537 539 if (auth) { 538 540 ret = (auth > 0) ? 0 : -1; -
libfdcore/routing_dispatch.c
r688 r691 1000 1000 { 1001 1001 int must_stop; 1002 CHECK_POSIX_DO( pthread_mutex_lock(&order_lock), goto end); /* we lock to flush the caches */1002 CHECK_POSIX_DO( pthread_mutex_lock(&order_lock), { ASSERT(0); } ); /* we lock to flush the caches */ 1003 1003 must_stop = (order_val == STOP); 1004 CHECK_POSIX_DO( pthread_mutex_unlock(&order_lock), goto end);1004 CHECK_POSIX_DO( pthread_mutex_unlock(&order_lock), { ASSERT(0); } ); 1005 1005 if (must_stop) 1006 1006 goto end; -
libfdcore/sctp.c
r662 r691 822 822 823 823 /* Set the socket options */ 824 CHECK_FCT_DO( ret = fd_setsockopt_prebind(*sock), goto fail);824 CHECK_FCT_DO( ret = fd_setsockopt_prebind(*sock), goto out ); 825 825 826 826 /* Create the array of addresses, add first the configured addresses, then the discovered, then the other ones */ 827 CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &size, &count, family, htons(port), list, EP_FL_CONF, EP_FL_CONF ), goto fail);828 CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &size, &count, family, htons(port), list, EP_FL_CONF | EP_FL_DISC, EP_FL_DISC ), goto fail);829 CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &size, &count, family, htons(port), list, EP_FL_CONF | EP_FL_DISC, 0 ), goto fail);827 CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &size, &count, family, htons(port), list, EP_FL_CONF, EP_FL_CONF ), goto out ); 828 CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &size, &count, family, htons(port), list, EP_FL_CONF | EP_FL_DISC, EP_FL_DISC ), goto out ); 829 CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &size, &count, family, htons(port), list, EP_FL_CONF | EP_FL_DISC, 0 ), goto out ); 830 830 831 831 /* Try connecting */ … … 866 866 /* Some errors are expected, we log at different level */ 867 867 TRACE_DEBUG( lvl, "sctp_connectx returned an error: %s", strerror(ret)); 868 goto fail;868 goto out; 869 869 } 870 870 … … 872 872 873 873 /* Set the remaining sockopts */ 874 CHECK_FCT_DO( ret = fd_setsockopt_postbind(*sock, 1), goto fail_deco ); 875 876 /* Done! */ 874 CHECK_FCT_DO( ret = fd_setsockopt_postbind(*sock, 1), 875 { 876 CHECK_SYS_DO( shutdown(*sock, SHUT_RDWR), /* continue */ ); 877 } ); 878 879 out: 880 ; 877 881 pthread_cleanup_pop(0); 878 return 0; 879 880 fail_deco: 881 CHECK_SYS_DO( shutdown(*sock, SHUT_RDWR), /* continue */ ); 882 fail: 883 if (*sock > 0) { 884 CHECK_SYS_DO( close(*sock), /* continue */ ); 885 *sock = -1; 886 } 887 free(sar.buf); 882 883 if (ret) { 884 if (*sock > 0) { 885 CHECK_SYS_DO( close(*sock), /* continue */ ); 886 *sock = -1; 887 } 888 free(sar.buf); 889 } 888 890 return ret; 889 891 } -
libfdcore/server.c
r688 r691 151 151 pthread_cleanup_push((void *)fd_cnx_destroy, c->conn); 152 152 pthread_cleanup_push((void *)fd_msg_free, msg); 153 CHECK_FCT_DO( fd_peer_handle_newCER( &msg, &c->conn ), goto cleanup);153 CHECK_FCT_DO( fd_peer_handle_newCER( &msg, &c->conn ), ); 154 154 pthread_cleanup_pop(0); 155 155 pthread_cleanup_pop(0); -
libfdcore/tcp.c
r662 r691 134 134 CHECK_SYS( s = socket(sa->sa_family, SOCK_STREAM, IPPROTO_TCP) ); 135 135 136 /* Set the socket options */ 137 CHECK_FCT( fd_tcp_setsockopt(sa->sa_family, s) ); 138 136 139 /* Cleanup if we are cancelled */ 137 140 pthread_cleanup_push(fd_cleanup_socket, &s); 138 139 /* Set the socket options */140 CHECK_FCT( fd_tcp_setsockopt(sa->sa_family, s) );141 141 142 142 TRACE_DEBUG_sSA(FULL, "Attempting TCP connection with peer: ", sa, NI_NUMERICHOST | NI_NUMERICSERV, "..." ); -
libfdproto/sessions.c
r686 r691 176 176 if (FD_IS_LIST_EMPTY(&exp_sentinel)) { 177 177 /* Just wait for a change or cancelation */ 178 CHECK_POSIX_DO( pthread_cond_wait( &exp_cond, &exp_lock ), break );178 CHECK_POSIX_DO( pthread_cond_wait( &exp_cond, &exp_lock ), break /* this might not pop the cleanup handler, but since we ASSERT(0), it is not the big issue... */ ); 179 179 /* Restart the loop on wakeup */ 180 180 goto again; … … 207 207 } while (1); 208 208 209 TRACE_DEBUG(INFO, "A nerror occurred in session module! Expiry thread is terminating...");209 TRACE_DEBUG(INFO, "A system error occurred in session module! Expiry thread is terminating..."); 210 210 ASSERT(0); 211 211 return NULL; … … 442 442 /* We added a new expiring element, we must signal */ 443 443 if (li == &exp_sentinel) { 444 CHECK_POSIX ( pthread_cond_signal(&exp_cond) );444 CHECK_POSIX_DO( pthread_cond_signal(&exp_cond), { ASSERT(0); } ); /* if it fails, we might not pop the cleanup handlers, but this should not happen -- and we'd have a serious problem otherwise */ 445 445 } 446 446 … … 458 458 /* We're done */ 459 459 pthread_cleanup_pop(0); 460 CHECK_POSIX ( pthread_mutex_unlock( &exp_lock ) );460 CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); } ); /* if it fails, we might not pop the cleanup handler, but this should not happen -- and we'd have a serious problem otherwise */ 461 461 } 462 462 … … 540 540 /* We added a new expiring element, we must signal if it was in first position */ 541 541 if (session->expire.prev == &exp_sentinel) { 542 CHECK_POSIX ( pthread_cond_signal(&exp_cond));542 CHECK_POSIX_DO( pthread_cond_signal(&exp_cond), { ASSERT(0); /* so that we don't have a pending cancellation handler */ } ); 543 543 } 544 544 … … 573 573 574 574 /* Unlink and invalidate */ 575 CHECK_ FCT( pthread_mutex_lock( H_LOCK(sess->hash) ) );575 CHECK_POSIX( pthread_mutex_lock( H_LOCK(sess->hash) ) ); 576 576 pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(sess->hash) ); 577 CHECK_ FCT( pthread_mutex_lock( &exp_lock ));577 CHECK_POSIX_DO( pthread_mutex_lock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } ); 578 578 fd_list_unlink( &sess->chain_h ); 579 579 fd_list_unlink( &sess->expire ); /* no need to signal the condition here */ 580 580 sess->eyec = 0xdead; 581 CHECK_ FCT( pthread_mutex_unlock( &exp_lock ));581 CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } ); 582 582 pthread_cleanup_pop(0); 583 CHECK_ FCT( pthread_mutex_unlock( H_LOCK(sess->hash) ) );583 CHECK_POSIX( pthread_mutex_unlock( H_LOCK(sess->hash) ) ); 584 584 585 585 /* Now destroy all states associated -- we don't take the lock since nobody can access this session anymore (in theory) */ … … 614 614 CHECK_POSIX( pthread_mutex_lock( H_LOCK(sess->hash) ) ); 615 615 pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(sess->hash) ); 616 CHECK_POSIX ( pthread_mutex_lock( &exp_lock ));616 CHECK_POSIX_DO( pthread_mutex_lock( &exp_lock ), { ASSERT(0); /* otherwise, cleanup not poped on FreeBSD */ } ); 617 617 if (FD_IS_LIST_EMPTY(&sess->states)) { 618 618 fd_list_unlink( &sess->chain_h ); … … 622 622 free(sess); 623 623 } 624 CHECK_POSIX ( pthread_mutex_unlock( &exp_lock ));624 CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); /* otherwise, cleanup not poped on FreeBSD */ } ); 625 625 pthread_cleanup_pop(0); 626 626 CHECK_POSIX( pthread_mutex_unlock( H_LOCK(hash) ) ); … … 635 635 struct fd_list * li; 636 636 int already = 0; 637 int ret = 0; 637 638 638 639 TRACE_ENTRY("%p %p %p", handler, session, state); … … 644 645 645 646 /* Create the new state object */ 646 CHECK_MALLOC (new = malloc(sizeof(struct state)));647 CHECK_MALLOC_DO(new = malloc(sizeof(struct state)), { ret = ENOMEM; goto out; } ); 647 648 memset(new, 0, sizeof(struct state)); 648 649 … … 661 662 if (st->hdl->id == handler->id) { 662 663 TRACE_DEBUG(INFO, "A state was already stored for session '%s' and handler '%p', at location %p", session->sid, st->hdl, st->state); 663 already = 1;664 already = EALREADY; 664 665 } 665 666 … … 673 674 free(new); 674 675 } 675 676 out: 677 ; 676 678 pthread_cleanup_pop(0); 677 679 CHECK_POSIX( pthread_mutex_unlock(&session->stlock) ); 678 680 679 return already ? EALREADY : 0;681 return ret ?: already; 680 682 } 681 683
Note: See TracChangeset
for help on using the changeset viewer.