# HG changeset patch # User Sebastien Decugis # Date 1363106610 -3600 # Node ID 6808de4558107ad1ca0a79aaf794042d85776a9c # Parent 8862d9dece667a477f7631e3fb17bcb571e871ad# Parent 652713ce3596642509e078e69f279cafb409bcc9 Remerged diff -r 8862d9dece66 -r 6808de455810 include/freeDiameter/libfdcore.h --- a/include/freeDiameter/libfdcore.h Tue Mar 12 17:38:24 2013 +0100 +++ b/include/freeDiameter/libfdcore.h Tue Mar 12 17:43:30 2013 +0100 @@ -384,6 +384,23 @@ */ int fd_peer_get_state(struct peer_hdr *peer); +/* + * FUNCTION: fd_peer_get_load_pending + * + * PARAMETERS: + * peer : The peer which load to read + * + * DESCRIPTION: + * Returns the current number of requests sent to this peer + * that have not been answered yet. This is an empirical indication + * of the workload of this peer. + * + * RETURN VALUE: + * 0 : The load parameter has been updated. (it should have a positive value always) + * !0 : An error occurred + */ +int fd_peer_get_load_pending(struct peer_hdr *peer, int * load); + /* * FUNCTION: fd_peer_validate_register * diff -r 8862d9dece66 -r 6808de455810 libfdcore/fdcore-internal.h --- a/libfdcore/fdcore-internal.h Tue Mar 12 17:38:24 2013 +0100 +++ b/libfdcore/fdcore-internal.h Tue Mar 12 17:43:30 2013 +0100 @@ -125,6 +125,7 @@ struct sr_list { struct fd_list srs; /* requests ordered by hop-by-hop id */ struct fd_list exp; /* requests that have a timeout set, ordered by timeout */ + int cnt; /* number of requests in the srs list */ pthread_mutex_t mtx; /* mutex to protect these lists */ pthread_cond_t cnd; /* cond var used by the thread that handles timeouts */ pthread_t thr; /* the thread that handles timeouts (and calls the anscb) */ diff -r 8862d9dece66 -r 6808de455810 libfdcore/fdd.l --- a/libfdcore/fdd.l Tue Mar 12 17:38:24 2013 +0100 +++ b/libfdcore/fdd.l Tue Mar 12 17:43:30 2013 +0100 @@ -51,7 +51,7 @@ #define YY_USER_ACTION { \ yylloc->first_column = yylloc->last_column + 1; \ yylloc->last_column = yylloc->first_column + yyleng - 1; \ - TRACE_ERROR( \ + fd_log_debug( \ "(%d:%d-%d:%d) matched rule %d, length=%d, txt='%s'\n", \ yylloc->first_line, yylloc->first_column, \ yylloc->last_line, yylloc->last_column, \ diff -r 8862d9dece66 -r 6808de455810 libfdcore/fdd.y --- a/libfdcore/fdd.y Tue Mar 12 17:38:24 2013 +0100 +++ b/libfdcore/fdd.y Tue Mar 12 17:43:30 2013 +0100 @@ -322,15 +322,18 @@ CHECK_MALLOC_DO( fname = malloc( strlen(bkp) + strlen(DEFAULT_EXTENSIONS_PATH) + 2 ), { yyerror (&yylloc, conf, "Not enough memory"); YYERROR; } ); sprintf(fname, DEFAULT_EXTENSIONS_PATH "/%s", bkp); - free(bkp); fd = fopen(fname, "r"); + if (fd == NULL) { + free(fname); + fname = bkp; + } else { + free(bkp); + } } - if (fd == NULL) { - int ret = errno; - TRACE_ERROR("WARNING: Unable to open extension file %s for reading: %s\nLD_LIBRARY_PATH will be used.\n", fname, strerror(ret)); - } else { + if (fd != NULL) { fclose(fd); - } + } /* otherwise, LD_LIBRARY_PATH will be tested by dl_open. + This should not give any security issue, otherwise we can add an "else fail" here. */ /* Try and open the configuration file (optional) */ cfname = $4; diff -r 8862d9dece66 -r 6808de455810 libfdcore/p_sr.c --- a/libfdcore/p_sr.c Tue Mar 12 17:38:24 2013 +0100 +++ b/libfdcore/p_sr.c Tue Mar 12 17:43:30 2013 +0100 @@ -225,6 +225,7 @@ /* Save in the list */ *req = NULL; fd_list_insert_before(next, &sr->chain); + srlist->cnt++; srl_dump("Saved new request, ", &srlist->srs); /* In case of request with a timeout, also store in the timeout list */ @@ -280,6 +281,7 @@ *((uint32_t *)sr->chain.o) = sr->prevhbh; /* Unlink */ fd_list_unlink(&sr->chain); + srlist->cnt--; fd_list_unlink(&sr->expire); *req = sr->req; free(sr); @@ -299,6 +301,7 @@ while (!FD_IS_LIST_EMPTY(&srlist->srs)) { struct sentreq * sr = (struct sentreq *)(srlist->srs.next); fd_list_unlink(&sr->chain); + srlist->cnt--; fd_list_unlink(&sr->expire); if (fd_msg_is_routable(sr->req)) { struct msg_hdr * hdr = NULL; diff -r 8862d9dece66 -r 6808de455810 libfdcore/peers.c --- a/libfdcore/peers.c Tue Mar 12 17:38:24 2013 +0100 +++ b/libfdcore/peers.c Tue Mar 12 17:43:30 2013 +0100 @@ -256,6 +256,21 @@ return; } +/* Return the value of srlist->cnt */ +int fd_peer_get_load_pending(struct peer_hdr *peer, int * load) +{ + struct fd_peer * p = (struct fd_peer *)peer; + TRACE_ENTRY("%p %p", peer, load); + CHECK_PARAMS(CHECK_PEER(peer) && load); + + CHECK_POSIX( pthread_mutex_lock(&p->p_sr.mtx) ); + *load = p->p_sr.cnt; + CHECK_POSIX( pthread_mutex_unlock(&p->p_sr.mtx) ); + + return 0; +} + + /* Destroy a structure once cleanups have been performed (fd_psm_abord, ...) */ int fd_peer_free(struct fd_peer ** ptr) { @@ -394,7 +409,7 @@ return; } - fd_log_debug("> %s\t%s", STATE_STR(fd_peer_getstate(peer)), peer->p_hdr.info.pi_diamid); + fd_log_debug("> %s\t%s\t[%dsr]", STATE_STR(fd_peer_getstate(peer)), peer->p_hdr.info.pi_diamid, peer->p_sr.cnt); if (details > INFO) { fd_log_debug("\t(rlm:%s)", peer->p_hdr.info.runtime.pir_realm ?: ""); if (peer->p_hdr.info.runtime.pir_prodname)