Changeset 235:8773740401a5 in freeDiameter
- Timestamp:
- Mar 5, 2010, 7:01:48 PM (14 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 2 added
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/test_app/CMakeLists.txt
r120 r235 14 14 ta_conf.tab.c 15 15 ta_conf.tab.h 16 ta_sig.c17 16 ta_dict.c 18 17 ta_cli.c -
extensions/test_app/ta_cli.c
r203 r235 136 136 137 137 /* Create a test message */ 138 static void ta_cli_test_message( void)138 static void ta_cli_test_message(int sig) 139 139 { 140 140 struct msg * req = NULL; … … 236 236 CHECK_FCT( fd_sess_handler_create(&ta_cli_reg, free) ); 237 237 238 CHECK_FCT( ta_sig_init(ta_cli_test_message) );238 CHECK_FCT( fd_sig_register(ta_conf->signal, "test_app.cli", ta_cli_test_message ) ); 239 239 240 240 return 0; … … 243 243 void ta_cli_fini(void) 244 244 { 245 ta_sig_fini();246 247 (void) fd_sess_handler_destroy(&ta_cli_reg);245 CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ ); 246 247 CHECK_FCT_DO( fd_sess_handler_destroy(&ta_cli_reg), /* continue */ ); 248 248 249 249 return; -
extensions/test_app/test_app.c
r120 r235 39 39 40 40 #include "test_app.h" 41 #include <signal.h>42 41 43 42 /* Initialize the configuration */ -
extensions/test_app/test_app.h
r127 r235 42 42 43 43 #include <freeDiameter/extension.h> 44 #include <signal.h> 44 45 45 46 #ifndef TEST_APP_DEFAULT_SIGNAL … … 69 70 int ta_conf_handle(char * conffile); 70 71 71 /* Start or stop the signal handler */72 int ta_sig_init(void (*cb)(void));73 void ta_sig_fini(void);74 75 72 /* Handle incoming messages (server) */ 76 73 int ta_serv_init(void); -
freeDiameter/main.c
r218 r235 42 42 43 43 /* forward declarations */ 44 static void * sig_hdl(void * arg);44 static void fd_shutdown(int signal); 45 45 static int main_cmdline(int argc, char *argv[]); 46 46 static void main_version(void); … … 58 58 { 59 59 int ret; 60 pthread_t sig_th;61 sigset_t sig_all;62 60 63 61 memset(fd_g_config, 0, sizeof(struct fd_config)); 64 62 65 /* Block all signals */66 sigfillset(&sig_all);67 CHECK_POSIX( pthread_sigmask(SIG_BLOCK, &sig_all, NULL) );68 69 63 /* Initialize the library -- must come first since it initializes the debug facility */ 70 CHECK_FCT( fd_lib_init( ) );64 CHECK_FCT( fd_lib_init(1) ); 71 65 TRACE_DEBUG(INFO, "libfreeDiameter initialized."); 72 66 … … 91 85 CHECK_FCT( main_cmdline(argc, argv) ); 92 86 93 /* Allow SIGINT and SIGTERM from this point */ 94 CHECK_POSIX( pthread_create(&sig_th, NULL, sig_hdl, NULL) ); 87 /* Allow SIGINT and SIGTERM from this point to terminate the application */ 88 CHECK_FCT( fd_sig_register(SIGINT, "freeDiameter.main", fd_shutdown) ); 89 CHECK_FCT( fd_sig_register(SIGTERM, "freeDiameter.main", fd_shutdown) ); 95 90 96 91 /* Add definitions of the base protocol */ … … 110 105 111 106 fd_conf_dump(); 107 fd_sig_dump(FULL, 1); 112 108 113 109 /* Start the servers */ … … 170 166 CHECK_FCT_DO( fd_rtdisp_cleanup(), /* destroy remaining handlers */ ); 171 167 172 CHECK_FCT_DO( fd_thr_term(&sig_th), /* reclaim resources of the signal thread */ );173 174 168 GNUTLS_TRACE( gnutls_global_deinit() ); 175 169 176 170 fd_log_debug(FD_PROJECT_BINARY " daemon is terminated.\n"); 171 172 fd_lib_fini(); 173 177 174 return ret; 178 175 } … … 319 316 } 320 317 321 #ifdef HAVE_SIGNALENT_H 322 const char *const signalstr[] = { 323 # include "signalent.h" 324 }; 325 const int nsignalstr = sizeof signalstr / sizeof signalstr[0]; 326 # define SIGNALSTR(sig) (((sig) < nsignalstr) ? signalstr[(sig)] : "unknown") 327 #else /* HAVE_SIGNALENT_H */ 328 # define SIGNALSTR(sig) ("") 329 #endif /* HAVE_SIGNALENT_H */ 330 331 /* signal handler */ 332 static void * sig_hdl(void * arg) 333 { 334 sigset_t sig_main; 335 int sig = 0; 336 337 TRACE_ENTRY(); 338 fd_log_threadname("Main signal handler"); 339 340 sigemptyset(&sig_main); 341 sigaddset(&sig_main, SIGINT); 342 sigaddset(&sig_main, SIGTERM); 343 344 CHECK_SYS_DO( sigwait(&sig_main, &sig), TRACE_DEBUG(INFO, "Error in sigwait function") ); 345 346 TRACE_DEBUG(INFO, "Received signal %s (%d), exiting", SIGNALSTR(sig), sig); 318 /* Terminate the application */ 319 static void fd_shutdown(int signal) 320 { 321 TRACE_ENTRY("%d", signal); 322 323 TRACE_DEBUG(INFO, "Received signal %s (%d), exiting", SIGNALSTR(signal), signal); 324 347 325 CHECK_FCT_DO( fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), exit(2) ); 348 return NULL;349 } 350 326 327 return; 328 } -
freeDiameter/tests/tests.h
r31 r235 106 106 #define INIT_FD() { \ 107 107 memset(fd_g_config, 0, sizeof(struct fd_config)); \ 108 CHECK( 0, fd_lib_init( ) ); \108 CHECK( 0, fd_lib_init(1) ); \ 109 109 fd_log_threadname(basename(__FILE__)); \ 110 110 (void) gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); \ -
include/freeDiameter/libfreeDiameter.h
r232 r235 75 75 #include <libgen.h> /* for basename if --dbg_file is specified */ 76 76 #endif /* DEBUG */ 77 78 79 /*============================================================*/ 80 /* INIT */ 81 /*============================================================*/ 82 83 /* This function must be called first, before any call to another library function */ 84 /* If the parameter is not 0, the support for signals (fd_sig_register) is enabled, otherwise it is disabled */ 85 /* The function must be called while the application is single-threaded to enable support for signals */ 86 int fd_lib_init(int support_signals); 87 88 /* Call this one when the application terminates, to destroy internal threads */ 89 void fd_lib_fini(void); 90 91 92 77 93 78 94 /*============================================================*/ … … 559 575 560 576 /*============================================================*/ 577 /* SIGNALS */ 578 /*============================================================*/ 579 580 /* Register a new callback to be called on reception of a given signal (it receives the signal as parameter) */ 581 /* EALREADY will be returned if there is already a callback registered on this signal */ 582 /* NOTE: the signal handler will be called from a new detached thread */ 583 int fd_sig_register(int signal, char * modname, void (*callback)(int signal)); 584 585 /* Remove the handler for a given signal */ 586 int fd_sig_unregister(int signal); 587 588 /* Dump list of handlers */ 589 void fd_sig_dump(int level, int indent); 590 591 /* Name of signals */ 592 #ifdef HAVE_SIGNALENT_H 593 extern const char *const fd_sig_str[]; 594 extern const int fd_sig_nstr; 595 # define SIGNALSTR(sig) (((sig) < fd_sig_nstr) ? fd_sig_str[(sig)] : "[unknown signal]") 596 #else /* HAVE_SIGNALENT_H */ 597 # define SIGNALSTR(sig) ("[no sig names]") 598 #endif /* HAVE_SIGNALENT_H */ 599 600 601 /*============================================================*/ 561 602 /* LISTS */ 562 603 /*============================================================*/ -
libfreeDiameter/CMakeLists.txt
r83 r235 14 14 rt_data.c 15 15 sessions.c 16 signal.c 16 17 ) 17 18 -
libfreeDiameter/init.c
r14 r235 36 36 #include "libfD.h" 37 37 38 int fd_lib_init(void) 38 /* Initialize library variables and threads */ 39 int fd_lib_init(int support_signals) 39 40 { 40 41 int ret = 0; … … 47 48 } 48 49 50 /* Initialize signals if requested */ 51 if (support_signals) { 52 CHECK_FCT( fd_sig_init() ); 53 } 54 49 55 /* Initialize the modules that need it */ 50 56 fd_msg_eteid_init(); … … 53 59 return 0; 54 60 } 61 62 /* Stop all threads created in the library */ 63 void fd_lib_fini(void) 64 { 65 fd_sess_fini(); 66 fd_sig_fini(); 67 } -
libfreeDiameter/libfD.h
r156 r235 46 46 void fd_msg_eteid_init(void); 47 47 int fd_sess_init(void); 48 void fd_sess_fini(void); 49 int fd_sig_init(void); 50 void fd_sig_fini(void); 48 51 49 52 /* Iterator on the rules of a parent object */ -
libfreeDiameter/sessions.c
r203 r235 238 238 } 239 239 240 /* Terminate */ 241 void fd_sess_fini(void) 242 { 243 TRACE_ENTRY(""); 244 CHECK_FCT_DO( fd_thr_term(&exp_thr), /* continue */ ); 245 return; 246 } 247 240 248 /* Create a new handler */ 241 249 int fd_sess_handler_create_internal ( struct session_handler ** handler, void (*cleanup)(char * sid, session_state * state) )
Note: See TracChangeset
for help on using the changeset viewer.