Navigation


Changeset 10:c5c99c73c2bf in freeDiameter for freeDiameter/main.c


Ignore:
Timestamp:
Sep 25, 2009, 4:12:08 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added some extensions and functions in the daemon

File:
1 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/main.c

    r9 r10  
    3939#include <getopt.h>
    4040
     41/* forward declarations */
     42static void * sig_hdl(void * arg);
     43static int main_cmdline(int argc, char *argv[]);
     44
     45/* The static configuration structure */
     46static struct fd_config conf;
     47struct fd_config * fd_g_config = &conf;
     48
     49/* freeDiameter starting point */
     50int main(int argc, char * argv[])
     51{
     52        int ret;
     53        pthread_t sig_th;
     54        sigset_t sig_all;
     55       
     56        memset(fd_g_config, 0, sizeof(struct fd_config));
     57        sigfillset(&sig_all);
     58        CHECK_POSIX(  pthread_sigmask(SIG_BLOCK, &sig_all, NULL)  );
     59       
     60        /* Initialize the library */
     61        CHECK_FCT( fd_lib_init() );
     62       
     63        /* Name this thread */
     64        fd_log_threadname("Main");
     65       
     66        /* Initialize the config */
     67        CHECK_FCT( fd_conf_init() );
     68
     69        /* Parse the command-line */
     70        CHECK_FCT(  main_cmdline(argc, argv)  );
     71       
     72        /* Allow SIGINT and SIGTERM from this point */
     73        CHECK_POSIX(  pthread_create(&sig_th, NULL, sig_hdl, NULL)  );
     74       
     75        /* Add definitions of the base protocol */
     76        CHECK_FCT( fd_dict_base_protocol(fd_g_config->cnf_dict) );
     77       
     78        /* Initialize other modules */
     79        CHECK_FCT(  fd_ext_init()  );
     80        CHECK_FCT(  fd_queues_init()  );
     81        CHECK_FCT(  fd_msg_init()  );
     82       
     83        /* Parse the configuration file */
     84        CHECK_FCT( fd_conf_parse() );
     85       
     86        /* Load the dynamic extensions */
     87        CHECK_FCT(  fd_ext_load()  );
     88       
     89        /* Start the peer state machines */
     90       
     91       
     92        /* Now, just wait for events */
     93        TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized.");
     94        fd_conf_dump();
     95        while (1) {
     96                int code;
     97                CHECK_FCT_DO(  fd_event_get(fd_g_config->cnf_main_ev, &code, NULL),  break  );
     98                switch (code) {
     99                        case FDEV_DUMP_DICT:
     100                                fd_dict_dump(fd_g_config->cnf_dict);
     101                                break;
     102                       
     103                        case FDEV_DUMP_EXT:
     104                                fd_ext_dump();
     105                                break;
     106                       
     107                        case FDEV_DUMP_QUEUES:
     108                                fd_fifo_dump(0, "Incoming messages", fd_g_incoming, fd_msg_dump_walk);
     109                                fd_fifo_dump(0, "Outgoing messages", fd_g_outgoing, fd_msg_dump_walk);
     110                                fd_fifo_dump(0, "Local messages",    fd_g_local,    fd_msg_dump_walk);
     111                                break;
     112                       
     113                        case FDEV_DUMP_CONFIG:
     114                                fd_conf_dump();
     115                                break;
     116                       
     117                       
     118                        case FDEV_TERMINATE:
     119                                ret = 0;
     120                                goto end;
     121                       
     122                        default:
     123                                TRACE_DEBUG(INFO, "Unexpected event in the daemon (%d), ignored.\n", code);
     124                }
     125        }
     126       
     127end:
     128        TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon is stopping...");
     129       
     130        /* cleanups */
     131        CHECK_FCT_DO( fd_ext_fini(), /* continue */ );
     132        CHECK_FCT_DO( fd_thr_term(&sig_th), /* continue */ );
     133       
     134        return ret;
     135}
    41136
    42137/* Display package version */
     
    122217                        case 'c':       /* Read configuration from this file instead of the default location..  */
    123218                                CHECK_PARAMS( optarg );
    124                                 fd_g_config->conf_file = optarg;
     219                                fd_g_config->cnf_file = optarg;
    125220                                break;
    126221
     
    159254#endif /* HAVE_SIGNALENT_H */
    160255
    161 
    162256/* signal handler */
    163257static void * sig_hdl(void * arg)
     
    176270       
    177271        TRACE_DEBUG(INFO, "Received signal %s (%d), exiting", SIGNALSTR(sig), sig);
    178         CHECK_FCT_DO( fd_event_send(fd_g_config->g_fifo_main, FM_TERMINATE, NULL), exit(2) );
     272        CHECK_FCT_DO( fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, NULL), exit(2) );
    179273        return NULL;
    180274}
    181275       
    182 /* The static configuration structure */
    183 static struct fd_config conf;
    184 struct fd_config * fd_g_config = &conf;
    185 
    186 /* Entry point */
    187 int main(int argc, char * argv[])
    188 {
    189         int ret;
    190         pthread_t sig_th;
    191         sigset_t sig_all;
    192        
    193         memset(fd_g_config, 0, sizeof(struct fd_config));
    194         sigfillset(&sig_all);
    195         CHECK_POSIX(  pthread_sigmask(SIG_BLOCK, &sig_all, NULL)  );
    196        
    197         /* Initialize the library */
    198         CHECK_FCT( fd_lib_init() );
    199        
    200         /* Name this thread */
    201         fd_log_threadname("Main");
    202        
    203         /* Initialize the config */
    204         CHECK_FCT( fd_conf_init() );
    205 
    206         /* Parse the command-line */
    207         CHECK_FCT(  main_cmdline(argc, argv)  );
    208        
    209         /* Allow SIGINT and SIGTERM from this point */
    210         CHECK_POSIX(  pthread_create(&sig_th, NULL, sig_hdl, NULL)  );
    211        
    212         /* Add definitions of the base protocol */
    213         CHECK_FCT( fd_dict_base_protocol(fd_g_config->g_dict) );
    214        
    215         /* Initialize other modules */
    216         CHECK_FCT(  fd_ext_init()  );
    217        
    218         /* Parse the configuration file */
    219         CHECK_FCT( fd_conf_parse() );
    220        
    221         /* Load the dynamic extensions */
    222         CHECK_FCT(  fd_ext_load()  );
    223        
    224         /* Start the peer state machines */
    225        
    226        
    227         /* Now, just wait for events */
    228         TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized.");
    229         fd_conf_dump();
    230         while (1) {
    231                 int code;
    232                 CHECK_FCT_DO(  fd_event_get(fd_g_config->g_fifo_main, &code, NULL),  break  );
    233                 switch (code) {
    234                         case FM_TERMINATE:
    235                                 ret = 0;
    236                                 goto end;
    237                        
    238                         default:
    239                                 TRACE_DEBUG(INFO, "Unexpected event in the daemon (%d), terminating.\n", code);
    240                                 ret = -1;
    241                                 goto end;
    242                 }
    243         }
    244        
    245 end:
    246         TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon is stopping...");
    247        
    248         /* cleanups */
    249         CHECK_FCT_DO( fd_ext_fini(), /* continue */ );
    250         CHECK_FCT_DO( fd_thr_term(&sig_th), /* continue */ );
    251        
    252         return ret;
    253 }
Note: See TracChangeset for help on using the changeset viewer.