RE: Problem of signal loss

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Sakib.

 > I am facing the problem of intermittent signal loss in Red Hat 
 > (2.4.18-3). The program runs in a loop, and is able to respond
 > to individual signals (SIGUSR1 and SIGUSR2). In fact, it works
 > well with multiple occurrence of the same signal.

Tell us more.

 > However, if SIGUSR2 is sent after SIGUSR1, the program responds
 > to the SIGUSR1, but does not respond to SIGUSR2.
 >
 > It is to be noted that if a SIGUSR1 is raised before SIGUSR2,
 > the behaviour is normal.

Hope you don't mind my pointing it out, but the two test cases you
quote are identical

 > I shall appreciate any pointer to why this is happening.

 > The code snippet is given below.

Not a very good one though...

 > static void signal_handler(int num)
 > {
 >     if (signal(num, signal_handler) == SIG_ERR) {
 >         syserr_quit("Unable to install signal handler");
 >     }
 >
 >     switch(num) {
 >         case SIGUSR1:
 >             proc_USR1();
 >             break;
 >         case SIGUSR2:
 >             proc_USR2();
 >             break;
 >         default:
 >             log_err("Impossible signal received.");
 >             break;
 >     }
 > }

The only query I can see is whether the if statement reinstating
the signal handler should be done before or after the actions
associated with the signal being received. Personally, I would
split the if statement up along the lines of...

	static void signal_handler(int num)
	{
	    sighandler_t res = signal(num, signal_handler);

	    switch (num) {
			:
	    }
	    if (res == SIG_ERR) {
	        syserr_quit("Unable to install signal handler");
	    }
	}

However, any problems are most likely to be within the actual
signal-handling routines, otherwise the behaviour would tend
to be symmetric with either signal blocking the other. Since
you don't quote anything about them, there is little one can
offer to help.

 > int main(int argc, char *argv[])
 > {
 >		....
 >
 >     if (signal(SIGUSR1, signal_handler) == SIG_ERR) {
 >         syserr_quit("Unable to install SIGUSR1 handler");
 >     }
 >
 >     if (signal(SIGUSR2, signal_handler) == SIG_ERR) {
 >         syserr_quit("Unable to install SIGUSR2 handler");
 >     }
 >
 >     while (1) {
 >         fd_set fd_read;
 >
 >         FD_ZERO(&fd_read);
 >         FD_SET(a_socket, &fd_read);
 >         while (select(FD_SETSIZE, &fd_read, NULL, NULL, NULL) < 0) {
 >             if (errno != EINTR) {
 >                 syslog_err("Error in listening");
 >             }
 >         }
 >         some_other_function();
 >     }
 > }

Apart from feeling the some_other_function() call should be inside
the inner while loop, I can't see any problems with that at all.

Best wishes from Riley.
---
 * Nothing as pretty as a smile, nothing as ugly as a frown.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.495 / Virus Database: 294 - Release Date: 30-Jun-2003

-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux