@@ -2508,7 +2508,7 @@ void release_clientstats_lock()
25082508 Pthread_rwlock_unlock (& clientstats_lk );
25092509}
25102510
2511- static void init_clientstats (nodestats_t * entry , int task_len , char * host , int fd )
2511+ static void init_clientstats (nodestats_t * entry , int task_len , char * host , struct sockaddr_in * addr )
25122512{
25132513 entry -> task = entry -> mem ;
25142514 entry -> stack = entry -> mem + task_len ;
@@ -2521,21 +2521,10 @@ static void init_clientstats(nodestats_t *entry, int task_len, char *host, int f
25212521 Pthread_mutex_init (& entry -> mtx , 0 );
25222522 Pthread_mutex_init (& entry -> rawtotals .lk , NULL );
25232523
2524- if (fd < 0 ) {
2524+ if (addr == NULL ) {
25252525 bzero (& (entry -> addr ), sizeof (struct in_addr ));
25262526 } else {
2527- struct sockaddr_in peeraddr ;
2528- socklen_t len = sizeof (peeraddr );
2529- bzero (& peeraddr , sizeof (peeraddr ));
2530- if (getpeername (fd , (struct sockaddr * )& peeraddr , & len ) < 0 ) {
2531- if (errno != ENOTCONN )
2532- logmsg (LOGMSG_ERROR , "%s: getpeername failed fd %d: %d %s\n" , __func__ , fd , errno ,
2533- strerror (errno ));
2534- bzero (& (entry -> addr ), sizeof (struct in_addr ));
2535- } else {
2536- memcpy (& (entry -> addr ), & peeraddr .sin_addr ,
2537- sizeof (struct in_addr ));
2538- }
2527+ memcpy (& (entry -> addr ), & addr -> sin_addr , sizeof (struct in_addr ));
25392528 }
25402529}
25412530
@@ -2549,9 +2538,8 @@ static void update_clientstats_cache(nodestats_t *entry) {
25492538 Pthread_mutex_unlock (& clientstats_cache_mtx );
25502539}
25512540
2552- static nodestats_t * add_clientstats (unsigned checksum ,
2553- const char * task_and_stack , int task_len ,
2554- int stack_len , char * host , int node , int fd )
2541+ static nodestats_t * add_clientstats (unsigned checksum , const char * task_and_stack , int task_len , int stack_len ,
2542+ char * host , int node , struct sockaddr_in * addr )
25552543{
25562544 nodestats_t * entry = calloc (1 , offsetof(nodestats_t , mem ) + task_len + stack_len );
25572545 if (entry == NULL ) {
@@ -2606,15 +2594,15 @@ static nodestats_t *add_clientstats(unsigned checksum,
26062594 goto done ;
26072595 }
26082596
2609- init_clientstats (entry , task_len , host , fd );
2597+ init_clientstats (entry , task_len , host , addr );
26102598 hash_add (clientstats , entry );
26112599
26122600done :
26132601 release_clientstats_lock ();
26142602 return entry ;
26152603}
26162604
2617- static nodestats_t * find_clientstats (unsigned checksum , int node , int fd )
2605+ static nodestats_t * find_clientstats (unsigned checksum , int node , struct sockaddr_in * addr )
26182606{
26192607 nodestats_t key ;
26202608 key .checksum = checksum ;
@@ -2630,19 +2618,8 @@ static nodestats_t *find_clientstats(unsigned checksum, int node, int fd)
26302618 entry -> ref ++ ;
26312619 update_clientstats_cache (entry );
26322620
2633- if (* (unsigned * )& (entry -> addr ) == 0 && fd > 0 ) {
2634- struct sockaddr_in peeraddr ;
2635- socklen_t len = sizeof (peeraddr );
2636- bzero (& peeraddr , sizeof (peeraddr ));
2637- if (getpeername (fd , (struct sockaddr * )& peeraddr , & len ) < 0 ) {
2638- if (errno != ENOTCONN )
2639- logmsg (LOGMSG_ERROR , "%s: getpeername failed fd %d: %d %s\n" , __func__ , fd , errno ,
2640- strerror (errno ));
2641- bzero (& (entry -> addr ), sizeof (struct in_addr ));
2642- } else {
2643- memcpy (& (entry -> addr ), & peeraddr .sin_addr ,
2644- sizeof (struct in_addr ));
2645- }
2621+ if (* (unsigned * )& (entry -> addr ) == 0 && addr != NULL ) {
2622+ memcpy (& (entry -> addr ), & addr -> sin_addr , sizeof (struct in_addr ));
26462623 }
26472624 Pthread_mutex_unlock (& entry -> mtx );
26482625
@@ -2692,8 +2669,8 @@ nodestats_t *get_next_clientstats_entry(void **curr, unsigned int *iter)
26922669 return entry ;
26932670}
26942671
2695- struct rawnodestats * get_raw_node_stats (const char * task , const char * stack ,
2696- char * host , int fd , int is_ssl )
2672+ struct rawnodestats * get_raw_node_stats (const char * task , const char * stack , char * host , struct sockaddr_in * addr ,
2673+ int is_ssl )
26972674{
26982675 unsigned checksum ;
26992676 int namelen , node ;
@@ -2718,10 +2695,10 @@ struct rawnodestats *get_raw_node_stats(const char *task, const char *stack,
27182695 memcpy (tmp , task , task_len );
27192696 memcpy (tmp + task_len , stack , stack_len );
27202697 checksum = crc32c ((const uint8_t * )tmp , namelen );
2721-
2722- nodestats_t * nodestats = find_clientstats (checksum , node , fd );
2698+
2699+ nodestats_t * nodestats = find_clientstats (checksum , node , addr );
27232700 if (!nodestats ) {
2724- nodestats = add_clientstats (checksum , tmp , task_len , stack_len , host , node , fd );
2701+ nodestats = add_clientstats (checksum , tmp , task_len , stack_len , host , node , addr );
27252702 }
27262703
27272704 if (nodestats ) {
0 commit comments