[AGENT++] Signal Handling in agent++

Ramasubramanian Venkataraman venkiram_be at yahoo.co.in
Mon May 18 13:11:02 CEST 2009


Hi,

Below is the sample signal handling code given in the agent.cpp. I have added HUP signal case to read the config file. But what happend is for every 2nd time the agent process is restarts. Even with the simple cout in the HUPSignal cases restarts the process when we give the HUP signal 2nd time.

Im not sure whether you handle the Blocking unblocking of signal somehwere. Could you please throw some idea to resolve this issue.

Here is the complete trace output of agent process.

1st time the HUP signal is give to the process:
===================================
poll(0xFFBE8530, 1, 2000)       (sleeping...)
signotifywait()                 (sleeping...)
door_return(0x00000000, 0, 0x00000000, 0) (sleeping...)
lwp_sema_wait(0xFED61E60)       (sleeping...)
lwp_cond_wait(0xFEF234E8, 0xFEF234F8, 0xFEF1CD80) (sleeping...)
signotifywait()                                 = 1
lwp_sigredirect(1, SIGHUP, 0xFEC0FC6C)          = 0
    Received signal #1, SIGHUP, in poll() [caught]
      siginfo: SIGHUP pid=993 uid=271
poll(0xFFBE8530, 1, 2000)                       Err#4 EINTR
lwp_mutex_wakeup(0xFEF234F8)                    = 0
lwp_mutex_lock(0xFEF234F8)                      = 0
sigaction(SIGHUP, 0xFFBE7FC0, 0x00000000)       = 0
sigprocmask(SIG_SETMASK, 0xFEF1CFB8, 0x00000000) = 0
signotifywait()                                 = 25
lwp_sigredirect(0, SIGCONT, 0x00000000)         = 0
lseek(1, 0, SEEK_CUR)                           Err#29 ESPIPE
write(1, " I n s i d e   H U P   H".., 18)      = 18
lseek(1, 0, SEEK_CUR)                           Err#29 ESPIPE
sigprocmask(SIG_SETMASK, 0xFEF28CE0, 0x00000000) = 0
setcontext(0xFFBE7EA0)
poll(0xFFBE8530, 1, 2000)       (sleeping...)
signotifywait()                 (sleeping...)
door_return(0x00000000, 0, 0x00000000, 0) (sleeping...)
lwp_sema_wait(0xFED61E60)       (sleeping...)
lwp_cond_wait(0xFEF234E8, 0xFEF234F8, 0xFEF1CD80) (sleeping...)
poll(0xFFBE8530, 1, 2000)                       = 0

2nd Time when we give the same hup signal with an error ( Err#4 EINTR)
===============================


poll(0xFFBE8530, 1, 2000)       (sleeping...)
signotifywait()                 (sleeping...)
door_return(0x00000000, 0, 0x00000000, 0) (sleeping...)
lwp_sema_wait(0xFED61E60)       (sleeping...)
lwp_cond_wait(0xFEF234E8, 0xFEF234F8, 0xFEF1CD80) (sleeping...)
signotifywait()                                 = 1
    Received signal #1, SIGHUP, in poll() [default]
      siginfo: SIGHUP pid=993 uid=271
lwp_sigredirect(1, SIGHUP, 0xFEC0FC6C)          = 0
signotifywait()                                 = 25
poll(0xFFBE8530, 1, 2000)                       Err#4 EINTR
lwp_sigredirect(0, SIGCONT, 0x00000000)         = 0
        *** process killed ***

====================================================================


static void sig(int signo)
{
        if ((signo == SIGTERM) || (signo == SIGINT) ||
            (signo == SIGSEGV) || (signo ==SIGHUP)) {


                switch (signo) {
                case SIGSEGV: {
                        LOG_BEGIN(DEBUG_LOG | 1);
                        LOG("Segmentation fault, aborting.\n");
                        LOG_END;
                        exit(1);
                }
                case SIGHUP:
                        configRead();
                        break;
                case SIGTERM:
                case SIGINT: {
                        if (run) {
                                run = FALSE;
                                LOG_BEGIN(DEBUG_LOG | 1);
                                LOG("User abort\n");
                                LOG_END;
                        }
                }
                }
        }
}


void init_signals()
{
        signal (SIGTERM, sig);
        signal (SIGINT, sig);
        signal (SIGSEGV, sig);
        signal (SIGHUP, sig);
}


Thanks in Advance,
Venkataraman


      Cricket on your mind? Visit the ultimate cricket website. Enter http://beta.cricket.yahoo.com


More information about the AGENTPP mailing list