Navigation


Changeset 1369:f1bbcab403a6 in freeDiameter


Ignore:
Timestamp:
Jun 10, 2019, 11:27:54 PM (5 years ago)
Author:
Thomas Klausner <tk@giga.or.at>
Branch:
default
Phase:
public
Message:

Clean up trailing whitespace in sessions.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/sessions.c

    r1093 r1369  
    3535
    3636/* Sessions module.
    37  * 
     37 *
    3838 * Basic functionalities to help implementing User sessions state machines from RFC3588.
    3939 */
     
    9292struct session {
    9393        int             eyec;   /* Eyecatcher, SI_EYEC */
    94        
     94
    9595        os0_t           sid;    /* The \0-terminated Session-Id */
    9696        size_t          sidlen; /* cached length of sid */
    9797        uint32_t        hash;   /* computed hash of sid */
    9898        struct fd_list  chain_h;/* chaining in the hash table of sessions. */
    99        
     99
    100100        struct timespec timeout;/* Timeout date for the session */
    101101        struct fd_list  expire; /* List of expiring sessions, ordered by timeouts. */
    102        
     102
    103103        pthread_mutex_t stlock; /* A lock to protect the list of states associated with this session */
    104104        struct fd_list  states; /* Sentinel for the list of states of this session. */
     
    126126static struct fd_list   exp_sentinel = FD_LIST_INITIALIZER(exp_sentinel);       /* list of sessions ordered by their timeout date */
    127127static pthread_mutex_t  exp_lock = PTHREAD_MUTEX_INITIALIZER;   /* lock protecting the list. */
    128 static pthread_cond_t   exp_cond = PTHREAD_COND_INITIALIZER;    /* condvar used by the expiry mecahinsm. */
     128static pthread_cond_t   exp_cond = PTHREAD_COND_INITIALIZER;    /* condvar used by the expiry mechainsm. */
    129129static pthread_t        exp_thr = (pthread_t)NULL;      /* The expiry thread that handles cleanup of expired sessions */
    130130
     
    141141{
    142142        struct session * sess;
    143        
     143
    144144        TRACE_ENTRY("%p %zd", sid, sidlen);
    145145        CHECK_PARAMS_DO( sid && sidlen, return NULL );
    146        
     146
    147147        CHECK_MALLOC_DO( sess = malloc(sizeof(struct session)), return NULL );
    148148        memset(sess, 0, sizeof(struct session));
    149        
     149
    150150        sess->eyec = SI_EYEC;
    151        
     151
    152152        sess->sid  = sid;
    153153        sess->sidlen = sidlen;
    154154        sess->hash = hash;
    155155        fd_list_init(&sess->chain_h, sess);
    156        
     156
    157157        CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &sess->timeout), return NULL );
    158158        sess->timeout.tv_sec += SESS_DEFAULT_LIFETIME;
    159159        fd_list_init(&sess->expire, sess);
    160        
     160
    161161        CHECK_POSIX_DO( pthread_mutex_init(&sess->stlock, NULL), return NULL );
    162162        fd_list_init(&sess->states, sess);
    163        
     163
    164164        return sess;
    165165}
     
    175175        free(s);
    176176}
    177        
     177
    178178/* The expiry thread */
    179179static void * exp_fct(void * arg)
     
    181181        fd_log_threadname ( "Session/expire" );
    182182        TRACE_ENTRY( "" );
    183        
    184        
     183
     184
    185185        do {
    186186                struct timespec now;
    187187                struct session * first;
    188                
     188
    189189                CHECK_POSIX_DO( pthread_mutex_lock(&exp_lock),  break );
    190190                pthread_cleanup_push( fd_cleanup_mutex, &exp_lock );
    191 again:         
     191again:
    192192                /* Check if there are expiring sessions available */
    193193                if (FD_IS_LIST_EMPTY(&exp_sentinel)) {
     
    197197                        goto again;
    198198                }
    199                
     199
    200200                /* Get the pointer to the session that expires first */
    201201                first = (struct session *)(exp_sentinel.next->o);
    202202                ASSERT( VALIDATE_SI(first) );
    203                
     203
    204204                /* Get the current time */
    205205                CHECK_SYS_DO(  clock_gettime(CLOCK_REALTIME, &now),  break  );
     
    207207                /* If first session is not expired, we just wait until it happens */
    208208                if ( TS_IS_INFERIOR( &now, &first->timeout ) ) {
    209                        
    210                         CHECK_POSIX_DO2(  pthread_cond_timedwait( &exp_cond, &exp_lock, &first->timeout ), 
     209                        CHECK_POSIX_DO2(  pthread_cond_timedwait( &exp_cond, &exp_lock, &first->timeout ),
    211210                                        ETIMEDOUT, /* ETIMEDOUT is a normal error, continue */,
    212211                                        /* on other error, */ break );
    213        
     212
    214213                        /* on wakeup, loop */
    215214                        goto again;
    216215                }
    217                
     216
    218217                /* Now, the first session in the list is expired; destroy it */
    219218                pthread_cleanup_pop( 0 );
    220219                CHECK_POSIX_DO( pthread_mutex_unlock(&exp_lock),  break );
    221                
     220
    222221                CHECK_FCT_DO( fd_sess_destroy( &first ), break );
    223                
     222
    224223        } while (1);
    225        
     224
    226225        TRACE_DEBUG(INFO, "A system error occurred in session module! Expiry thread is terminating...");
    227226        ASSERT(0);
    228227        return NULL;
    229228}
    230        
    231        
     229
     230
    232231
    233232/********************************************************************************************************/
     
    237236{
    238237        int i;
    239        
     238
    240239        TRACE_ENTRY( "" );
    241        
     240
    242241        /* Initialize the global counters */
    243242        sid_h = (uint32_t) time(NULL);
    244243        sid_l = 0;
    245        
     244
    246245        /* Initialize the hash table */
    247246        for (i = 0; i < sizeof(sess_hash) / sizeof(sess_hash[0]); i++) {
     
    249248                CHECK_POSIX(  pthread_mutex_init(&sess_hash[i].lock, NULL)  );
    250249        }
    251        
     250
    252251        return 0;
    253252}
     
    258257        /* Start session garbage collector (expiry) */
    259258        CHECK_POSIX(  pthread_create(&exp_thr, NULL, exp_fct, NULL)  );
    260        
     259
    261260        return 0;
    262261}
     
    267266        TRACE_ENTRY("");
    268267        CHECK_FCT_DO( fd_thr_term(&exp_thr), /* continue */ );
    269        
     268
    270269        /* Destroy all sessions in the hash table, and the hash table itself? -- How to do it without a race condition ? */
    271        
     270
    272271        return;
    273272}
     
    277276{
    278277        struct session_handler *new;
    279        
     278
    280279        TRACE_ENTRY("%p %p", handler, cleanup);
    281        
     280
    282281        CHECK_PARAMS( handler && cleanup );
    283        
     282
    284283        CHECK_MALLOC( new = malloc(sizeof(struct session_handler)) );
    285284        memset(new, 0, sizeof(struct session_handler));
    286        
     285
    287286        CHECK_POSIX( pthread_mutex_lock(&hdl_lock) );
    288287        new->id = ++hdl_id;
    289288        CHECK_POSIX( pthread_mutex_unlock(&hdl_lock) );
    290        
     289
    291290        new->eyec = SH_EYEC;
    292291        new->cleanup = cleanup;
    293292        new->state_dump = dumper;
    294293        new->opaque = opaque;
    295        
     294
    296295        *handler = new;
    297296        return 0;
    298297}
    299298
    300 /* Destroy a handler, and all states attached to this handler. This operation is very slow but we don't care since it's rarely used. 
     299/* Destroy a handler, and all states attached to this handler. This operation is very slow but we don't care since it's rarely used.
    301300 * Note that it's better to call this function after all sessions have been deleted... */
    302301int fd_sess_handler_destroy ( struct session_handler ** handler, void ** opaque )
     
    306305        struct fd_list deleted_states = FD_LIST_INITIALIZER( deleted_states );
    307306        int i;
    308        
     307
    309308        TRACE_ENTRY("%p", handler);
    310309        CHECK_PARAMS( handler && VALIDATE_SH(*handler) );
    311        
     310
    312311        del = *handler;
    313312        *handler = NULL;
    314        
     313
    315314        del->eyec = 0xdead; /* The handler is not valid anymore for any other operation */
    316        
     315
    317316        /* Now find all sessions with data registered for this handler, and move this data to the deleted_states list. */
    318317        for (i = 0; i < sizeof(sess_hash) / sizeof(sess_hash[0]); i++) {
    319318                struct fd_list * li_si;
    320319                CHECK_POSIX(  pthread_mutex_lock(&sess_hash[i].lock)  );
    321                
     320
    322321                for (li_si = sess_hash[i].sentinel.next; li_si != &sess_hash[i].sentinel; li_si = li_si->next) { /* for each session in the hash line */
    323322                        struct fd_list * li_st;
     
    341340                CHECK_POSIX(  pthread_mutex_unlock(&sess_hash[i].lock)  );
    342341        }
    343        
     342
    344343        /* Now, delete all states after calling their cleanup handler */
    345344        while (!FD_IS_LIST_EMPTY(&deleted_states)) {
     
    350349                free(st);
    351350        }
    352        
     351
    353352        if (opaque)
    354353                *opaque = del->opaque;
    355        
     354
    356355        /* Free the handler */
    357356        free(del);
    358        
     357
    359358        return 0;
    360359}
     
    372371        int found = 0;
    373372        int ret = 0;
    374        
     373
    375374        TRACE_ENTRY("%p %p %zd %p %zd", session, diamid, diamidlen, opt, optlen);
    376375        CHECK_PARAMS( session && (diamid || opt) );
    377376
    378         if (diamid) {   
     377        if (diamid) {
    379378                if (!diamidlen) {
    380379                        diamidlen = strlen(diamid);
    381                 } 
     380                }
    382381                /* We check if the string is a valid DiameterIdentity */
    383382                CHECK_PARAMS( fd_os_is_valid_DiameterIdentity((uint8_t *)diamid, diamidlen) );
     
    385384                diamidlen = 0;
    386385        }
    387         if (opt) {     
     386        if (opt) {
    388387                if (!optlen) {
    389388                        optlen = strlen((char *)opt);
     
    394393                optlen = 0;
    395394        }
    396                
     395
    397396        /* Ok, first create the identifier for the string */
    398397        if (diamid == NULL) {
     
    410409                sidlen++; /* space for the final \0 also */
    411410                CHECK_MALLOC( sid = malloc(sidlen) );
    412                
     411
    413412                CHECK_POSIX( pthread_mutex_lock(&sid_lock) );
    414413                if ( ++sid_l == 0 ) /* overflow */
     
    417416                sid_l_cpy = sid_l;
    418417                CHECK_POSIX( pthread_mutex_unlock(&sid_lock) );
    419                
     418
    420419                if (opt) {
    421420                        sidlen = snprintf((char*)sid, sidlen, "%.*s;%u;%u;%.*s", (int)diamidlen, diamid, sid_h_cpy, sid_l_cpy, (int)optlen, opt);
     
    424423                }
    425424        }
    426        
     425
    427426        hash = fd_os_hash(sid, sidlen);
    428        
     427
    429428        /* Now find the place to add this object in the hash table. */
    430429        CHECK_POSIX( pthread_mutex_lock( H_LOCK(hash) ) );
    431430        pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(hash) );
    432        
     431
    433432        for (li = H_LIST(hash)->next; li != H_LIST(hash); li = li->next) {
    434433                int cmp;
    435434                struct session * s = (struct session *)(li->o);
    436                
     435
    437436                /* The list is ordered by hash and sid (in case of collisions) */
    438437                if (s->hash < hash)
     
    440439                if (s->hash > hash)
    441440                        break;
    442                
     441
    443442                cmp = fd_os_cmp(s->sid, s->sidlen, sid, sidlen);
    444443                if (cmp < 0)
     
    446445                if (cmp > 0)
    447446                        break;
    448                
     447
    449448                /* A session with the same sid was already in the hash table */
    450449                found = 1;
     
    452451                break;
    453452        }
    454        
     453
    455454        /* If the session did not exist, we can create it & link it in global tables */
    456455        if (!found) {
     
    461460                                goto out;
    462461                        } );
    463        
     462
    464463                fd_list_insert_before(li, &sess->chain_h); /* hash table */
    465464                sess->msg_cnt++;
    466465        } else {
    467466                free(sid);
    468                
    469                 CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) ); 
     467
     468                CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) );
    470469                (*session)->msg_cnt++;
    471                 CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) ); 
    472                
     470                CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) );
     471
    473472                /* it was found: was it previously destroyed? */
    474473                if ((*session)->is_destroyed == 0) {
     
    479478                        sess = *session;
    480479                        sess->is_destroyed = 0;
    481                        
     480
    482481                        /* update the expiry time */
    483482                        CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &sess->timeout), { ASSERT(0); } );
     
    485484                }
    486485        }
    487                
     486
    488487        /* We must insert in the expiry list */
    489488        CHECK_POSIX( pthread_mutex_lock( &exp_lock ) );
     
    512511        pthread_cleanup_pop(0);
    513512        CHECK_POSIX( pthread_mutex_unlock( H_LOCK(hash) ) );
    514        
     513
    515514        if (ret) /* in case of error */
    516515                return ret;
    517        
     516
    518517        *session = sess;
    519518        return 0;
     
    524523{
    525524        int ret;
    526        
     525
    527526        TRACE_ENTRY("%p %zd %p %p", sid, len, session, new);
    528527        CHECK_PARAMS( sid && session );
    529        
     528
    530529        if (!fd_os_is_valid_os0(sid,len)) {
    531530                TRACE_DEBUG(INFO, "Warning: a Session-Id value contains \\0 chars... (len:%zd, begin:'%.*s') => Debug messages may be truncated.", len, (int)len, sid);
    532531        }
    533        
     532
    534533        /* All the work is done in sess_new */
    535534        ret = fd_sess_new ( session, NULL, 0, sid, len );
     
    538537                case EALREADY:
    539538                        break;
    540                
     539
    541540                default:
    542541                        CHECK_FCT(ret);
    543542        }
    544        
     543
    545544        if (new)
    546545                *new = ret ? 0 : 1;
    547        
     546
    548547        return 0;
    549548}
     
    553552{
    554553        TRACE_ENTRY("%p %p", session, sid);
    555        
     554
    556555        CHECK_PARAMS( VALIDATE_SI(session) && sid );
    557        
     556
    558557        *sid = session->sid;
    559558        if (sidlen)
    560559                *sidlen = session->sidlen;
    561        
     560
    562561        return 0;
    563562}
     
    567566{
    568567        struct fd_list * li;
    569        
     568
    570569        TRACE_ENTRY("%p %p", session, timeout);
    571570        CHECK_PARAMS( VALIDATE_SI(session) && timeout );
    572        
     571
    573572        /* Lock -- do we need to lock the hash table as well? I don't think so... */
    574573        CHECK_POSIX( pthread_mutex_lock( &exp_lock ) );
    575574        pthread_cleanup_push( fd_cleanup_mutex, &exp_lock );
    576        
     575
    577576        /* Update the timeout */
    578577        fd_list_unlink(&session->expire);
    579578        memcpy(&session->timeout, timeout, sizeof(struct timespec));
    580        
     579
    581580        /* Find the new position in expire list. We take it in normal order */
    582581        for (li = exp_sentinel.next; li != &exp_sentinel; li = li->next) {
     
    598597        pthread_cleanup_pop(0);
    599598        CHECK_POSIX( pthread_mutex_unlock( &exp_lock ) );
    600        
     599
    601600        return 0;
    602601}
     
    609608        os0_t sid;
    610609        int ret = 0;
    611        
     610
    612611        /* place to save the list of states to be cleaned up. We do it after finding them to avoid deadlocks. the "o" field becomes a copy of the sid. */
    613612        struct fd_list deleted_states = FD_LIST_INITIALIZER( deleted_states );
    614        
     613
    615614        TRACE_ENTRY("%p", session);
    616615        CHECK_PARAMS( session && VALIDATE_SI(*session) );
    617        
     616
    618617        sess = *session;
    619618        *session = NULL;
    620        
     619
    621620        /* Lock the hash line */
    622621        CHECK_POSIX( pthread_mutex_lock( H_LOCK(sess->hash) ) );
    623622        pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(sess->hash) );
    624        
     623
    625624        /* Unlink from the expiry list */
    626625        CHECK_POSIX_DO( pthread_mutex_lock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } );
     626        pthread_cleanup_push( fd_cleanup_mutex, &exp_lock );
    627627        if (!FD_IS_LIST_EMPTY(&sess->expire)) {
    628628                sess_cnt--;
    629629                fd_list_unlink( &sess->expire ); /* no need to signal the condition here */
    630630        }
     631        pthread_cleanup_pop(0);
    631632        CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } );
    632        
     633
    633634        /* Now move all states associated to this session into deleted_states */
    634635        CHECK_POSIX_DO( pthread_mutex_lock( &sess->stlock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } );
     
    639640        }
    640641        CHECK_POSIX_DO( pthread_mutex_unlock( &sess->stlock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } );
    641        
     642
    642643        /* Mark the session as destroyed */
    643644        destroy_now = (sess->msg_cnt == 0);
     
    651652        pthread_cleanup_pop(0);
    652653        CHECK_POSIX( pthread_mutex_unlock( H_LOCK(sess->hash) ) );
    653        
     654
    654655        if (ret)
    655656                return ret;
    656        
     657
    657658        /* Now, really delete the states */
    658659        while (!FD_IS_LIST_EMPTY(&deleted_states)) {
     
    663664                free(st);
    664665        }
    665        
     666
    666667        /* Finally, destroy the session itself, if it is not referrenced by any message anymore */
    667668        if (destroy_now) {
     
    670671                free(sid);
    671672        }
    672        
     673
    673674        return 0;
    674675}
     
    680681        uint32_t hash;
    681682        int destroy_now = 0;
    682        
     683
    683684        TRACE_ENTRY("%p", session);
    684685        CHECK_PARAMS( session && VALIDATE_SI(*session) );
    685        
     686
    686687        sess = *session;
    687688        hash = sess->hash;
    688689        *session = NULL;
    689        
     690
    690691        CHECK_POSIX( pthread_mutex_lock( H_LOCK(hash) ) );
    691692        pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(hash) );
     
    693694        pthread_cleanup_push( fd_cleanup_mutex, &sess->stlock );
    694695        CHECK_POSIX_DO( pthread_mutex_lock( &exp_lock ), { ASSERT(0); /* otherwise, cleanup not poped on FreeBSD */ } );
    695        
     696        pthread_cleanup_push( fd_cleanup_mutex, &exp_lock );
     697
    696698        /* We only do something if the states list is empty */
    697699        if (FD_IS_LIST_EMPTY(&sess->states)) {
     
    706708                }
    707709        }
    708        
     710
     711        pthread_cleanup_pop(0);
    709712        CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); /* otherwise, cleanup not poped on FreeBSD */ } );
    710713        pthread_cleanup_pop(0);
     
    712715        pthread_cleanup_pop(0);
    713716        CHECK_POSIX( pthread_mutex_unlock( H_LOCK(hash) ) );
    714        
     717
    715718        if (destroy_now)
    716719                del_session(sess);
    717        
     720
    718721        return 0;
    719722}
     
    726729        int already = 0;
    727730        int ret = 0;
    728        
     731
    729732        TRACE_ENTRY("%p %p %p", handler, session, state);
    730733        CHECK_PARAMS( handler && VALIDATE_SH(handler) && session && VALIDATE_SI(session) && (!session->is_destroyed) && state );
    731        
     734
    732735        /* Lock the session state list */
    733736        CHECK_POSIX( pthread_mutex_lock(&session->stlock) );
    734737        pthread_cleanup_push( fd_cleanup_mutex, &session->stlock );
    735                        
     738
    736739        /* Create the new state object */
    737740        CHECK_MALLOC_DO(new = malloc(sizeof(struct state)), { ret = ENOMEM; goto out; } );
    738741        memset(new, 0, sizeof(struct state));
    739        
     742
    740743        new->eyec = SD_EYEC;
    741744        new->state= *state;
    742745        fd_list_init(&new->chain, new);
    743746        new->hdl = handler;
    744        
     747
    745748        /* find place for this state in the list */
    746749        for (li = session->states.next; li != &session->states; li = li->next) {
     
    749752                if (st->hdl->id < handler->id)
    750753                        continue;
    751                
     754
    752755                if (st->hdl->id == handler->id) {
    753756                        TRACE_DEBUG(INFO, "A state was already stored for session '%s' and handler '%p', at location %p", session->sid, st->hdl, st->state);
    754757                        already = EALREADY;
    755758                }
    756                
     759
    757760                break;
    758761        }
    759        
     762
    760763        if (!already) {
    761764                fd_list_insert_before(li, &new->chain);
     
    765768        }
    766769out:
    767         ;       
     770        ;
    768771        pthread_cleanup_pop(0);
    769772        CHECK_POSIX( pthread_mutex_unlock(&session->stlock) );
    770        
     773
    771774        return ret ?: already;
    772775}
     
    777780        struct fd_list * li;
    778781        struct state * st = NULL;
    779        
     782
    780783        TRACE_ENTRY("%p %p %p", handler, session, state);
    781784        CHECK_PARAMS( handler && VALIDATE_SH(handler) && session && VALIDATE_SI(session) && state );
    782        
     785
    783786        *state = NULL;
    784        
     787
    785788        /* Lock the session state list */
    786789        CHECK_POSIX( pthread_mutex_lock(&session->stlock) );
    787790        pthread_cleanup_push( fd_cleanup_mutex, &session->stlock );
    788        
     791
    789792        /* find the state in the list */
    790793        for (li = session->states.next; li != &session->states; li = li->next) {
    791794                st = (struct state *)(li->o);
    792                
     795
    793796                /* The list is ordered by handler's id */
    794797                if (st->hdl->id > handler->id)
    795798                        break;
    796799        }
    797        
     800
    798801        /* If we found the state */
    799802        if (st && (st->hdl == handler)) {
     
    802805                free(st);
    803806        }
    804        
     807
    805808        pthread_cleanup_pop(0);
    806809        CHECK_POSIX( pthread_mutex_unlock(&session->stlock) );
    807        
     810
    808811        return 0;
    809812}
     
    814817        TRACE_ENTRY("%p %zd %p %p", sid, len, session, new);
    815818        CHECK_PARAMS( sid && len && session );
    816        
     819
    817820        /* Get the session object */
    818821        CHECK_FCT( fd_sess_fromsid_msg ( sid, len, session, new) );
    819        
     822
    820823        /* Decrease the refcount */
    821824        CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) );
    822825        (*session)->msg_cnt--; /* was increased in fd_sess_new */
    823826        CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) );
    824                
     827
    825828        /* Done */
    826829        return 0;
     
    836839        session->msg_cnt++;
    837840        CHECK_POSIX( pthread_mutex_unlock(&session->stlock) );
    838        
     841
    839842        return 0;
    840843}
     
    844847        int reclaim;
    845848        uint32_t hash;
    846        
     849
    847850        TRACE_ENTRY("%p", session);
    848851        CHECK_PARAMS( session && VALIDATE_SI(*session) );
    849        
     852
    850853        /* Lock the hash line to avoid possibility that session is freed while we are reclaiming */
    851854        hash = (*session)->hash;
    852855        CHECK_POSIX( pthread_mutex_lock( H_LOCK(hash)) );
    853         pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(hash) ); 
     856        pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(hash) );
    854857
    855858        /* Update the msg refcount */
     
    858861        (*session)->msg_cnt = reclaim - 1;
    859862        CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) );
    860        
     863
    861864        /* Ok, now unlock the hash line */
    862865        pthread_cleanup_pop( 0 );
    863866        CHECK_POSIX( pthread_mutex_unlock( H_LOCK(hash) ) );
    864        
     867
    865868        /* and reclaim if no message references the session anymore */
    866869        if (reclaim == 1) {
     
    878881{
    879882        FD_DUMP_HANDLE_OFFSET();
    880        
     883
    881884        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{session}(@%p): ", session), return NULL);
    882        
     885
    883886        if (!VALIDATE_SI(session)) {
    884887                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID/NULL"), return NULL);
     
    890893                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "'%s'(%zd) h:%x m:%d d:%d to:%s.%06ld",
    891894                                                        session->sid, session->sidlen, session->hash, session->msg_cnt, session->is_destroyed,
    892                                                         timebuf, session->timeout.tv_nsec/1000), 
     895                                                        timebuf, session->timeout.tv_nsec/1000),
    893896                                 return NULL);
    894                
     897
    895898                if (with_states) {
    896899                        struct fd_list * li;
    897900                        CHECK_POSIX_DO( pthread_mutex_lock(&session->stlock), /* ignore */ );
    898901                        pthread_cleanup_push( fd_cleanup_mutex, &session->stlock );
    899                        
     902
    900903                        for (li = session->states.next; li != &session->states; li = li->next) {
    901904                                struct state * st = (struct state *)(li->o);
    902905                                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n  {state i:%d}(@%p): ", st->hdl->id, st), return NULL);
    903906                                if (st->hdl->state_dump) {
    904                                         CHECK_MALLOC_DO( (*st->hdl->state_dump)( FD_DUMP_STD_PARAMS, st->state), 
     907                                        CHECK_MALLOC_DO( (*st->hdl->state_dump)( FD_DUMP_STD_PARAMS, st->state),
    905908                                                        fd_dump_extend( FD_DUMP_STD_PARAMS, "[dumper error]"));
    906909                                } else {
     
    908911                                }
    909912                        }
    910                        
     913
    911914                        pthread_cleanup_pop(0);
    912915                        CHECK_POSIX_DO( pthread_mutex_unlock(&session->stlock), /* ignore */ );
    913916                }
    914917        }
    915        
     918
    916919        return *buf;
    917920}
     
    920923{
    921924        FD_DUMP_HANDLE_OFFSET();
    922        
     925
    923926        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{sesshdl}(@%p): ", handler), return NULL);
    924        
     927
    925928        if (!VALIDATE_SH(handler)) {
    926929                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID/NULL"), return NULL);
     
    929932        }
    930933        return *buf;
    931 }       
     934}
    932935
    933936int fd_sess_getcount(uint32_t *cnt)
Note: See TracChangeset for help on using the changeset viewer.