[omniORB] orb->shutdown() in a signal handler

Favre Benoit ben.favre@wanadoo.fr
Mon Jul 15 11:41:01 2002


Is there a special issue for using orb->shutdown() in a signal handler ?

I implemented a SIGINT handler using sigaction() in a separate thread (a 
thread created before ORB creation) to be sure it won't interfere with the 
orb implementation. The handler calls orb->shutdown() and then exit().
I also redirect SIGINT of the main process to SIG_IGN before orb creation.
Sometimes, the handler will work and exit cleanly. sometimes, it will hang 
forever. If i attach the process with gdb, it says it hangs in pthread_join() 
(see the stack trace at the end of this mail).

here is the code :

void main()
{
    ...
    /* ignore SIGINT */
    signal(SIGINT,SIG_IGN);
    pthread_t handler_thread;

    /* create a thread to manage SIGINT */
    pthread_create(&handler_thread,NULL,fn_thread,NULL);

    /* do orb stuff */
    orb=CORBA::ORB_init(argc,argv,"omniORB3");
    ...
}

void *fn_thread(void *rien)
{
    struct sigaction signal_helper;
    signal_helper.sa_handler=handler;
    signal_helper.sa_flags=SA_ONESHOT;
    sigemptyset(&(signal_helper.sa_mask));

    /* set SIGINT handler */
    sigaction(SIGINT,&signal_helper,NULL);

    /* wait for ever */
    while(1)pause();
    return NULL;
}

void handler(int sig_num)
{
    /* shut down the orb and exit */
    orb->shutdown();
    exit();
}

I am using omniORB 3.03 with Linux RH 7.2, my signal handler is at #13

#0  0x401ccaa5 in __sigsuspend (set=0xbfffebe0) at 
../sysdeps/unix/sysv/linux/sigsuspend.c:45
#1  0x40128079 in __pthread_wait_for_restart_signal (self=0x40130d60) at 
pthread.c:967
#2  0x401254ba in pthread_join (thread_id=4101, thread_return=0x0) at 
restart.h:34
#3  0x40035dee in omni_thread::join () at eval.c:41
#4  0x400cc474 in tcpSocketIncomingRope::cancelThreads () at eval.c:41
#5  0x400cb58d in tcpSocketMTincomingFactory::stopIncoming () at eval.c:41
#6  0x40089b12 in omniObjAdapter::adapterInactive () at eval.c:41
#7  0x40092932 in omniOrbPOA::do_destroy () at eval.c:41
#8  0x4008ce42 in omniOrbPOA::destroy () at eval.c:41
#9  0x400937ec in omniOrbPOA::shutdown () at eval.c:41
#10 0x400ab5bf in omniOrbORB::actual_shutdown () at eval.c:41
#11 0x400ab81f in omniOrbORB::do_shutdown () at eval.c:41
#12 0x400ab0f6 in omniOrbORB::shutdown () at eval.c:41
#13 0x080597be in main_signal_handler (sig_type=2) at factory.cc:43
#14 0x401288d5 in pthread_sighandler (signo=2, ctx=
      {gs = 7, __gsh = 0, fs = 0, __fsh = 0, es = 43, __esh = 0, ds = 43, 
__dsh = 0, edi = 1074992552, esi = 3221222384, ebp = 3221222360, esp = 
3221222352, ebx = 3221222384, edx = 1076707668, ecx = 8, eax = 4294967292, 
trapno = 0, err = 0, eip = 1075628709, cs = 35, __csh = 0, eflags = 530, 
esp_at_signal = 3221222352, ss = 43, __ssh = 0, fpstate = 0x0, oldmask = 
2147483648, cr2 = 0}) at signals.c:97
#15 <signal handler called>
#16 0x401ccaa5 in __sigsuspend (set=0xbffff3f0) at 
../sysdeps/unix/sysv/linux/sigsuspend.c:45
#17 0x40128079 in __pthread_wait_for_restart_signal (self=0x40130d60) at 
pthread.c:967
#18 0x40124bdc in pthread_cond_wait (cond=0x401157ec, mutex=0x401157d0) at 
restart.h:34
#19 0x40035282 in omni_condition::wait () at eval.c:41
#20 0x400aaf75 in omniOrbORB::run () at eval.c:41
#21 0x08059e10 in main (argc=1, argv=0xbffff854) at factory.cc:115
#22 0x401ba507 in __libc_start_main (main=0x80598a8 <main>, argc=5, 
ubp_av=0xbffff854, init=0x8058c28 <_init>,
    fini=0x8064550 <_fini>, rtld_fini=0x4000dc14 <_dl_fini>, 
stack_end=0xbffff84c) at ../sysdeps/generic/libc-start.c:129