Changeset 236:60f34df3e025 in freeDiameter
- Timestamp:
- Mar 8, 2010, 2:10:30 PM (14 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/main.c
r235 r236 321 321 TRACE_ENTRY("%d", signal); 322 322 323 TRACE_DEBUG(INFO, "Received signal %s (%d), exiting", SIGNALSTR(signal), signal);323 TRACE_DEBUG(INFO, "Received signal %s (%d), exiting", fd_sig_abbrev(signal), signal); 324 324 325 325 CHECK_FCT_DO( fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), exit(2) ); -
freeDiameter/tests/tests.h
r235 r236 57 57 #include <time.h> 58 58 #include <libgen.h> 59 #include <signal.h> 59 60 60 61 /* Define the return code values */ … … 116 117 } 117 118 119 static void test_timeout(int signal) 120 { 121 FAILTEST("The timeout (" _stringize(TEST_TIMEOUT) " sec) was reached. Use -n or change TEST_TIMEOUT if the test needs more time to execute."); 122 } 123 118 124 static inline void parse_cmdline(int argc, char * argv[]) { 119 125 int c; … … 138 144 } 139 145 fd_g_debug_lvl = (test_verbo > 0) ? (test_verbo - 1) : 0; 140 if (!no_timeout) 146 if (!no_timeout) { 141 147 alarm(TEST_TIMEOUT); 148 fd_sig_register(SIGALRM, "Test.harness", test_timeout); 149 } 142 150 } 143 151 -
include/freeDiameter/CMakeLists.txt
r168 r236 90 90 CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H) 91 91 92 # signalent.h ? -- found in strace distrib; just for nice signal names...93 CHECK_INCLUDE_FILES (signalent.h HAVE_SIGNALENT_H)94 95 92 # The default configuration file name 96 93 IF (NOT DEFAULT_CONF_FILE) -
include/freeDiameter/libfreeDiameter.h
r235 r236 590 590 591 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 */ 592 const char * fd_sig_abbrev(int signal); 599 593 600 594 -
libfreeDiameter/signal.c
r235 r236 38 38 #include <signal.h> 39 39 40 /* List of signal names */41 #ifdef HAVE_SIGNALENT_H42 const char *const fd_sig_str[] = {43 # include "signalent.h"44 };45 const int fd_sig_nstr = sizeof fd_sig_str / sizeof fd_sig_str[0];46 #endif /* HAVE_SIGNALENT_H */47 48 40 /* A structure to hold the registered signal handlers */ 49 41 struct sig_hdl { … … 65 57 static int sig_initialized = 0; 66 58 59 /* signals short names list */ 60 static int abbrevs_init(void); 61 67 62 /* Initialize the support for signals */ 68 63 int fd_sig_init(void) … … 74 69 if (sig_initialized) 75 70 return 0; 71 72 /* Initialize the list of abbreviations */ 73 CHECK_FCT(abbrevs_init()); 76 74 77 75 /* Block all signals from the current thread and all its future children, so that signals are delivered only to our sig_hdl->sig_thr */ … … 97 95 98 96 /* Name this thread */ 99 snprintf(buf, sizeof(buf), "cb %d:%s:%s", me->signal, SIGNALSTR(me->signal), me->modname);97 snprintf(buf, sizeof(buf), "cb %d:%s:%s", me->signal, fd_sig_abbrev(me->signal), me->modname); 100 98 fd_log_threadname ( buf ); 101 99 … … 121 119 122 120 /* Name this thread */ 123 snprintf(buf, sizeof(buf), "catch %d:%s:%s", me->signal, SIGNALSTR(me->signal), me->modname);121 snprintf(buf, sizeof(buf), "catch %d:%s:%s", me->signal, fd_sig_abbrev(me->signal), me->modname); 124 122 fd_log_threadname ( buf ); 125 123 … … 144 142 145 143 /* An error occurred... What should we do ? */ 146 TRACE_DEBUG(INFO, "!!! ERROR !!! The signal catcher for %d:%s:%s is terminating!", me->signal, SIGNALSTR(me->signal), me->modname);144 TRACE_DEBUG(INFO, "!!! ERROR !!! The signal catcher for %d:%s:%s is terminating!", me->signal, fd_sig_abbrev(me->signal), me->modname); 147 145 148 146 /* Better way to handle this ? */ … … 180 178 if (nh->signal == signal) { 181 179 matched = 1; 182 TRACE_DEBUG(INFO, "Signal %d (%s) is already registered by module '%s'", signal, SIGNALSTR(signal), nh->modname);180 TRACE_DEBUG(INFO, "Signal %d (%s) is already registered by module '%s'", signal, fd_sig_abbrev(signal), nh->modname); 183 181 } 184 182 break; … … 216 214 struct sig_hdl * h = (struct sig_hdl *)li; 217 215 218 fd_log_debug("%*s - sig %*d (%s) => %p in module %s\n", indent, "", 2, h->signal, SIGNALSTR(h->signal), h->sig_hdl, h->modname);216 fd_log_debug("%*s - sig %*d (%s) => %p in module %s\n", indent, "", 2, h->signal, fd_sig_abbrev(h->signal), h->sig_hdl, h->modname); 219 217 } 220 218 CHECK_POSIX_DO(pthread_mutex_unlock(&sig_hdl_lock), /* continue */); … … 289 287 return; 290 288 } 289 290 291 /**************************************************************************************/ 292 293 static char **abbrevs; 294 static size_t abbrevs_nr = 0; 295 296 /* Initialize the array of signals */ 297 static int abbrevs_init(void) 298 { 299 int i; 300 301 #define SIGNAL_MAX_LIMIT 100 /* Do not save signals with value > this */ 302 303 /* The raw list of signals in the system -- might be incomplete, add any signal you need */ 304 struct sig_abb_raw { 305 int sig; 306 char *name; 307 } abbrevs_raw[] = { 308 { 0, "[unknown signal]" } 309 #define RAW_SIGNAL( _sig ) ,{ _sig, #_sig } 310 #ifdef SIGBUS 311 RAW_SIGNAL( SIGBUS ) 312 #endif /* SIGBUS */ 313 #ifdef SIGTTIN 314 RAW_SIGNAL( SIGTTIN ) 315 #endif /* SIGTTIN */ 316 #ifdef SIGTTOU 317 RAW_SIGNAL( SIGTTOU ) 318 #endif /* SIGTTOU */ 319 #ifdef SIGPROF 320 RAW_SIGNAL( SIGPROF ) 321 #endif /* SIGPROF */ 322 #ifdef SIGALRM 323 RAW_SIGNAL( SIGALRM ) 324 #endif /* SIGALRM */ 325 #ifdef SIGFPE 326 RAW_SIGNAL( SIGFPE ) 327 #endif /* SIGFPE */ 328 #ifdef SIGSTKFLT 329 RAW_SIGNAL( SIGSTKFLT ) 330 #endif /* SIGSTKFLT */ 331 #ifdef SIGSTKSZ 332 RAW_SIGNAL( SIGSTKSZ ) 333 #endif /* SIGSTKSZ */ 334 #ifdef SIGUSR1 335 RAW_SIGNAL( SIGUSR1 ) 336 #endif /* SIGUSR1 */ 337 #ifdef SIGURG 338 RAW_SIGNAL( SIGURG ) 339 #endif /* SIGURG */ 340 #ifdef SIGIO 341 RAW_SIGNAL( SIGIO ) 342 #endif /* SIGIO */ 343 #ifdef SIGQUIT 344 RAW_SIGNAL( SIGQUIT ) 345 #endif /* SIGQUIT */ 346 #ifdef SIGABRT 347 RAW_SIGNAL( SIGABRT ) 348 #endif /* SIGABRT */ 349 #ifdef SIGTRAP 350 RAW_SIGNAL( SIGTRAP ) 351 #endif /* SIGTRAP */ 352 #ifdef SIGVTALRM 353 RAW_SIGNAL( SIGVTALRM ) 354 #endif /* SIGVTALRM */ 355 #ifdef SIGSEGV 356 RAW_SIGNAL( SIGSEGV ) 357 #endif /* SIGSEGV */ 358 #ifdef SIGCONT 359 RAW_SIGNAL( SIGCONT ) 360 #endif /* SIGCONT */ 361 #ifdef SIGPIPE 362 RAW_SIGNAL( SIGPIPE ) 363 #endif /* SIGPIPE */ 364 #ifdef SIGWINCH 365 RAW_SIGNAL( SIGWINCH ) 366 #endif /* SIGWINCH */ 367 #ifdef SIGXFSZ 368 RAW_SIGNAL( SIGXFSZ ) 369 #endif /* SIGXFSZ */ 370 #ifdef SIGHUP 371 RAW_SIGNAL( SIGHUP ) 372 #endif /* SIGHUP */ 373 #ifdef SIGCHLD 374 RAW_SIGNAL( SIGCHLD ) 375 #endif /* SIGCHLD */ 376 #ifdef SIGSYS 377 RAW_SIGNAL( SIGSYS ) 378 #endif /* SIGSYS */ 379 #ifdef SIGSTOP 380 RAW_SIGNAL( SIGSTOP ) 381 #endif /* SIGSTOP */ 382 #ifdef SIGUSR2 383 RAW_SIGNAL( SIGUSR2 ) 384 #endif /* SIGUSR2 */ 385 #ifdef SIGTSTP 386 RAW_SIGNAL( SIGTSTP ) 387 #endif /* SIGTSTP */ 388 #ifdef SIGKILL 389 RAW_SIGNAL( SIGKILL ) 390 #endif /* SIGKILL */ 391 #ifdef SIGXCPU 392 RAW_SIGNAL( SIGXCPU ) 393 #endif /* SIGXCPU */ 394 #ifdef SIGUNUSED 395 RAW_SIGNAL( SIGUNUSED ) 396 #endif /* SIGUNUSED */ 397 #ifdef SIGPWR 398 RAW_SIGNAL( SIGPWR ) 399 #endif /* SIGPWR */ 400 #ifdef SIGILL 401 RAW_SIGNAL( SIGILL ) 402 #endif /* SIGILL */ 403 #ifdef SIGINT 404 RAW_SIGNAL( SIGINT ) 405 #endif /* SIGINT */ 406 #ifdef SIGIOT 407 RAW_SIGNAL( SIGIOT ) 408 #endif /* SIGIOT */ 409 #ifdef SIGTERM 410 RAW_SIGNAL( SIGTERM ) 411 #endif /* SIGTERM */ 412 }; 413 414 TRACE_ENTRY(""); 415 416 /* First pass: find the highest signal number */ 417 for (i=0; i < sizeof(abbrevs_raw)/sizeof(abbrevs_raw[0]); i++) { 418 if (abbrevs_raw[i].sig > SIGNAL_MAX_LIMIT) { 419 TRACE_DEBUG(ANNOYING, "Ignoring signal %s (%d), increase SIGNAL_MAX_LIMIT if you want it included", abbrevs_raw[i].name, abbrevs_raw[i].sig); 420 continue; 421 } 422 if (abbrevs_raw[i].sig > abbrevs_nr) 423 abbrevs_nr = abbrevs_raw[i].sig; 424 } 425 426 /* Now, alloc the array */ 427 abbrevs_nr++; /* 0-based */ 428 CHECK_MALLOC( abbrevs = calloc( abbrevs_nr, sizeof(char *) ) ); 429 430 /* Second pass: add all the signals in the array */ 431 for (i=0; i < sizeof(abbrevs_raw)/sizeof(abbrevs_raw[0]); i++) { 432 if (abbrevs_raw[i].sig > SIGNAL_MAX_LIMIT) 433 continue; 434 435 if (abbrevs[abbrevs_raw[i].sig] == NULL) 436 abbrevs[abbrevs_raw[i].sig] = abbrevs_raw[i].name; 437 } 438 439 /* Third pass: Set all missing signals to the undef value */ 440 for (i=0; i < abbrevs_nr; i++) { 441 if (abbrevs[i] == NULL) 442 abbrevs[i] = abbrevs_raw[0].name; 443 } 444 445 /* Done! */ 446 return 0; 447 } 448 449 /* Names of signals */ 450 const char * fd_sig_abbrev(int signal) 451 { 452 if (signal < abbrevs_nr) 453 return abbrevs[signal]; 454 return abbrevs[0]; 455 } 456
Note: See TracChangeset
for help on using the changeset viewer.