Navigation


Changeset 236:60f34df3e025 in freeDiameter


Ignore:
Timestamp:
Mar 8, 2010, 2:10:30 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Remove dependency on signalent.h

Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/main.c

    r235 r236  
    321321        TRACE_ENTRY("%d", signal);
    322322       
    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);
    324324
    325325        CHECK_FCT_DO( fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), exit(2) );
  • freeDiameter/tests/tests.h

    r235 r236  
    5757#include <time.h>
    5858#include <libgen.h>
     59#include <signal.h>
    5960
    6061/* Define the return code values */
     
    116117}
    117118
     119static 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
    118124static inline void parse_cmdline(int argc, char * argv[]) {
    119125        int c;
     
    138144        }
    139145        fd_g_debug_lvl = (test_verbo > 0) ? (test_verbo - 1) : 0;
    140         if (!no_timeout)
     146        if (!no_timeout) {
    141147                alarm(TEST_TIMEOUT);
     148                fd_sig_register(SIGALRM, "Test.harness", test_timeout);
     149        }
    142150}
    143151 
  • include/freeDiameter/CMakeLists.txt

    r168 r236  
    9090CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H)
    9191
    92 # signalent.h ? -- found in strace distrib; just for nice signal names...
    93 CHECK_INCLUDE_FILES (signalent.h HAVE_SIGNALENT_H)
    94 
    9592# The default configuration file name
    9693IF (NOT DEFAULT_CONF_FILE)
  • include/freeDiameter/libfreeDiameter.h

    r235 r236  
    590590
    591591/* 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 */
     592const char * fd_sig_abbrev(int signal);
    599593
    600594
  • libfreeDiameter/signal.c

    r235 r236  
    3838#include <signal.h>
    3939
    40 /* List of signal names */
    41 #ifdef HAVE_SIGNALENT_H
    42 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 
    4840/* A structure to hold the registered signal handlers */
    4941struct sig_hdl {
     
    6557static int sig_initialized = 0;
    6658
     59/* signals short names list */
     60static int abbrevs_init(void);
     61
    6762/* Initialize the support for signals */
    6863int fd_sig_init(void)
     
    7469        if (sig_initialized)
    7570                return 0;
     71       
     72        /* Initialize the list of abbreviations */
     73        CHECK_FCT(abbrevs_init());
    7674       
    7775        /* Block all signals from the current thread and all its future children, so that signals are delivered only to our sig_hdl->sig_thr */
     
    9795       
    9896        /* 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);
    10098        fd_log_threadname ( buf );
    10199       
     
    121119       
    122120        /* 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);
    124122        fd_log_threadname ( buf );
    125123       
     
    144142       
    145143        /* 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);
    147145       
    148146        /* Better way to handle this ? */
     
    180178                if (nh->signal == signal) {
    181179                        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);
    183181                }
    184182                break;
     
    216214                struct sig_hdl * h = (struct sig_hdl *)li;
    217215               
    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);
    219217        }
    220218        CHECK_POSIX_DO(pthread_mutex_unlock(&sig_hdl_lock), /* continue */);
     
    289287        return;
    290288}
     289
     290
     291/**************************************************************************************/
     292
     293static char **abbrevs;
     294static size_t abbrevs_nr = 0;
     295
     296/* Initialize the array of signals */
     297static 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 */
     450const 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.