Navigation


Changeset 1182:cc96a4dfb3d1 in freeDiameter


Ignore:
Timestamp:
Jun 6, 2013, 12:25:23 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Early shutdown situation: detect the race condition and delay the shutdown in freeDiameterd. Alternative would be to initialize in a separate thread that we can cancel before calling shutdown.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • freeDiameterd/main.c

    r1159 r1182  
    8787        }
    8888       
     89        /* Parse the configuration file */
     90        CHECK_FCT_DO( fd_core_parseconf(conffile), goto error );
     91       
     92        /* Start the servers */
     93        CHECK_FCT_DO( fd_core_start(), goto error );
     94       
    8995        /* Allow SIGINT and SIGTERM from this point to terminate the application */
    90         CHECK_POSIX( pthread_create(&signals_thr, NULL, catch_signals, NULL) );
    91        
    92         /* Parse the configuration file */
    93         CHECK_FCT( fd_core_parseconf(conffile) );
    94        
    95         /* Start the servers */
    96         CHECK_FCT( fd_core_start() );
     96        CHECK_POSIX_DO( pthread_create(&signals_thr, NULL, catch_signals, NULL), goto error );
    9797       
    9898        TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized.");
    99        
     99
    100100        /* Now, just wait for termination */
    101101        CHECK_FCT( fd_core_wait_shutdown_complete() );
     
    105105       
    106106        return 0;
     107error: 
     108        CHECK_FCT_DO( fd_core_shutdown(),  );
     109        CHECK_FCT( fd_core_wait_shutdown_complete() );
     110        fd_thr_term(&signals_thr);
     111        return -1;
    107112}
    108113
  • libfdcore/core.c

    r1167 r1182  
    228228}
    229229
     230static pthread_mutex_t core_lock = PTHREAD_MUTEX_INITIALIZER;
     231
    230232/* Parse the freeDiameter.conf configuration file, load the extensions */
    231 int fd_core_parseconf(const char * conffile)
     233static int fd_core_parseconf_int(const char * conffile)
    232234{
    233235        char * buf = NULL, *b;
     
    274276}
    275277
     278int fd_core_parseconf(const char * conffile)
     279{
     280        int ret;
     281        CHECK_POSIX( pthread_mutex_lock(&core_lock) );
     282        ret = fd_core_parseconf_int(conffile);
     283        CHECK_POSIX( pthread_mutex_unlock(&core_lock) );
     284        return ret;
     285}
     286
     287
    276288/* For threads that would need to wait complete start of the framework (ex: in extensions) */
    277289int fd_core_waitstartcomplete(void)
     
    283295
    284296/* Start the server & client threads */
    285 int fd_core_start(void)
     297static int fd_core_start_int(void)
    286298{
    287299        /* Start server threads */
     
    301313}
    302314
     315int fd_core_start(void)
     316{
     317        int ret;
     318        CHECK_POSIX( pthread_mutex_lock(&core_lock) );
     319        ret = fd_core_start_int();
     320        CHECK_POSIX( pthread_mutex_unlock(&core_lock) );
     321        return ret;
     322}
    303323
    304324/* Initialize shutdown of the framework. This is not blocking. */
     
    308328       
    309329        if (cur_state < CORE_RUNNING) {
     330                /* Calling application must make sure the initialization is not ongoing in a separate thread... */
     331                if (pthread_mutex_lock(&core_lock) != 0) {
     332                        /* This function must not be called asynchronously from fd_core_parseconf / fd_core_start ! Please review your main app design */
     333                        ASSERT(0);
     334                        return EINVAL;
     335                }
    310336                core_shutdown();
    311337                core_state_set(CORE_TERM);
     338                pthread_mutex_unlock(&core_lock);
    312339        } else if (cur_state == CORE_RUNNING) {
    313340                core_state_set(CORE_SHUTDOWN);
Note: See TracChangeset for help on using the changeset viewer.