about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-10-14 19:21:07 +0000
committerUlrich Drepper <drepper@redhat.com>1999-10-14 19:21:07 +0000
commit907ea199d0c9fb94aa311259b42ec9ab447562dc (patch)
treeadc59edb515ca7e2647528ccaf98f1b5b34900e4
parent02ab9fe3d079f15ae1c0f030bd8bba68c3f0b29b (diff)
downloadglibc-907ea199d0c9fb94aa311259b42ec9ab447562dc.tar.gz
glibc-907ea199d0c9fb94aa311259b42ec9ab447562dc.tar.xz
glibc-907ea199d0c9fb94aa311259b42ec9ab447562dc.zip
Update.
1999-10-14  Andreas Jaeger  <aj@suse.de>

	* sysdeps/unix/sysv/linux/sleep.c (__sleep): Optimize for zero
	seconds.
-rw-r--r--ChangeLog5
-rw-r--r--sysdeps/unix/sysv/linux/sleep.c11
2 files changed, 14 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 57c38f0880..87cce19b96 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+1999-10-14  Andreas Jaeger  <aj@suse.de>
+
+	* sysdeps/unix/sysv/linux/sleep.c (__sleep): Optimize for zero
+	seconds.
+
 1999-10-12  Ulrich Drepper  <drepper@cygnus.com>
 
 	* sysdeps/unix/sysv/linux/i386/sys/ucontext.h: Don't define
diff --git a/sysdeps/unix/sysv/linux/sleep.c b/sysdeps/unix/sysv/linux/sleep.c
index 5fb11603cf..53968e86c2 100644
--- a/sysdeps/unix/sysv/linux/sleep.c
+++ b/sysdeps/unix/sysv/linux/sleep.c
@@ -1,5 +1,5 @@
 /* Implementation of the POSIX sleep function using nanosleep.
-   Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
@@ -31,9 +31,12 @@ __sleep (unsigned int seconds)
 {
   struct timespec ts = { tv_sec: (long int) seconds, tv_nsec: 0 };
   sigset_t set, oset;
-  struct sigaction oact;
   unsigned int result;
 
+  /* This is not necessary but some buggy programs depend on this.  */
+  if (seconds == 0)
+    return 0;
+
   /* Linux will wake up the system call, nanosleep, when SIGCHLD
      arrives even if SIGCHLD is ignored.  We have to deal with it
      in libc.  We block SIGCHLD first.  */
@@ -46,6 +49,10 @@ __sleep (unsigned int seconds)
   if (!__sigismember (&oset, SIGCHLD))
     {
       int saved_errno;
+      struct sigaction oact;
+
+      if (__sigemptyset (&set) < 0 || __sigaddset (&set, SIGCHLD) < 0)
+	return -1;
 
       /* We get the signal handler for SIGCHLD.  */
       if (__sigaction (SIGCHLD, (struct sigaction *) NULL, &oact) < 0)