A correct programming practice is to save errno and restore its value

in all signal handlers that could modify it (i.e. by calling system
calls or worst standard C library functions).

Else the following code for instance is buggy if a signal arises between
the tests:

if (system_call() == -1) {
  if (errno == Exxx) {
   ...
  } else {
   ...
  }
}

And MANY (open source or not) programs are broken that way ...

svn path=/trunk/; revision=7664
This commit is contained in:
Laurent Deniel 2003-05-14 10:31:15 +00:00
parent d791827a65
commit ea052d7d23
1 changed files with 3 additions and 1 deletions

View File

@ -1,6 +1,6 @@
/* tethereal.c
*
* $Id: tethereal.c,v 1.182 2003/05/04 18:50:51 gerald Exp $
* $Id: tethereal.c,v 1.183 2003/05/14 10:31:15 deniel Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -1432,6 +1432,7 @@ report_counts(void)
static void
report_counts_siginfo(int signum _U_)
{
int sav_errno = errno;
/* If we've been told to delay printing, just set a flag asking
that we print counts (if we're supposed to), otherwise print
the count of packets captured (if we're supposed to). */
@ -1439,6 +1440,7 @@ report_counts_siginfo(int signum _U_)
infoprint = TRUE;
else
report_counts();
errno = sav_errno;
}
#endif /* SIGINFO */
#endif /* HAVE_LIBPCAP */