This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch roland/init-first created. glibc-2.16-ports-merge-407-gca4badd


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, roland/init-first has been created
        at  ca4badd13aa11b158f31c00e1fd190c3f5ae5536 (commit)

- Log -----------------------------------------------------------------
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=ca4badd13aa11b158f31c00e1fd190c3f5ae5536

commit ca4badd13aa11b158f31c00e1fd190c3f5ae5536
Author: Roland McGrath <roland@hack.frob.com>
Date:   Fri Sep 28 15:34:27 2012 -0700

    Clean up init-first.c files.

diff --git a/ChangeLog b/ChangeLog
index 8f61e77..acef710 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2012-09-28  Roland McGrath  <roland@hack.frob.com>
 
+	* sysdeps/unix/sysv/linux/init-first.c: Moved to ...
+	* csu/init-first.c: ... here.
+	* sysdeps/unix/sysv/linux/powerpc/init-first.c: Update #include.
+	* sysdeps/unix/sysv/linux/s390/init-first.c: Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/init-first.c: Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/x32/init-first.c: Likewise.
+	* sysdeps/i386/init-first.c: File removed.
+	* sysdeps/sh/init-first.c: File removed.
+
+2012-09-28  Roland McGrath  <roland@hack.frob.com>
+
 	* sysdeps/posix/sleep.c (__sleep): Rewritten using __nanosleep
 	instead of SIGALRM.
 
diff --git a/csu/init-first.c b/csu/init-first.c
index 050959d..0cfabbc 100644
--- a/csu/init-first.c
+++ b/csu/init-first.c
@@ -1,4 +1,4 @@
-/* Initialization code run first thing by the ELF startup code.  Stub version.
+/* Initialization code run first thing by the ELF startup code.  Common version
    Copyright (C) 1995-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -17,40 +17,76 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
 #include <unistd.h>
+#include <sysdep.h>
+#include <fpu_control.h>
+#include <sys/param.h>
 #include <sys/types.h>
+#include <libc-internal.h>
+
+#include <ldsodefs.h>
 
 /* Set nonzero if we have to be prepared for more then one libc being
    used in the process.  Safe assumption if initializer never runs.  */
 int __libc_multiple_libcs attribute_hidden = 1;
 
-extern void __libc_init (int, char **, char **);
-#ifdef USE_NONOPTION_FLAGS
-extern void __getopt_clean_environment (char **);
-#endif
+/* Remember the command line argument and enviroment contents for
+   later calls of initializers for dynamic libraries.  */
+int __libc_argc attribute_hidden;
+char **__libc_argv attribute_hidden;
+
 
-#ifdef SHARED
 void
-__libc_init_first (void)
+__libc_init_first (int argc, char **argv, char **envp)
 {
+#ifdef SHARED
+  /* For DSOs we do not need __libc_init_first but instead _init.  */
 }
+
+void
+attribute_hidden
+_init (int argc, char **argv, char **envp)
+{
+#endif
+#ifdef USE_NONOPTION_FLAGS
+  extern void __getopt_clean_environment (char **);
 #endif
 
+  __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
+
+  /* Make sure we don't initialize twice.  */
+  if (!__libc_multiple_libcs)
+    {
+      /* Set the FPU control word to the proper default value if the
+	 kernel would use a different value.  (In a static program we
+	 don't have this information.)  */
 #ifdef SHARED
-/* NOTE!  The linker notices the magical name `_init' and sets the DT_INIT
-   pointer in the dynamic section based solely on that.  It is convention
-   for this function to be in the `.init' section, but the symbol name is
-   the only thing that really matters!!  */
-void _init
-#else
-void __libc_init_first
+      if (__fpu_control != GLRO(dl_fpu_control))
 #endif
-(int argc, char *arg0, ...)
-{
-  char **argv = &arg0, **envp = &argv[argc + 1];
+	__setfpucw (__fpu_control);
+    }
 
+  /* Save the command-line arguments.  */
+  __libc_argc = argc;
+  __libc_argv = argv;
   __environ = envp;
-  __libc_init (argc, argv, envp);
+
+#ifndef SHARED
+  __libc_init_secure ();
+
+  /* First the initialization which normally would be done by the
+     dynamic linker.  */
+  _dl_non_dynamic_init ();
+#endif
+
+#ifdef VDSO_SETUP
+  VDSO_SETUP ();
+#endif
+
+  __init_misc (argc, argv, envp);
 
 #ifdef USE_NONOPTION_FLAGS
   /* This is a hack to make the special getopt in GNU libc working.  */
@@ -59,4 +95,21 @@ void __libc_init_first
 
   /* Initialize ctype data.  */
   __ctype_init ();
+
+#if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
+  __libc_global_ctors ();
+#endif
+}
+
+/* This function is defined here so that if this file ever gets into
+   ld.so we will get a link error.  Having this file silently included
+   in ld.so causes disaster, because the _init definition above will
+   cause ld.so to gain an init function, which is not a cool thing. */
+
+extern void _dl_start (void) __attribute__ ((noreturn));
+
+void
+_dl_start (void)
+{
+  abort ();
 }
diff --git a/ports/ChangeLog.m68k b/ports/ChangeLog.m68k
index 5163cf3..040c490 100644
--- a/ports/ChangeLog.m68k
+++ b/ports/ChangeLog.m68k
@@ -1,3 +1,8 @@
+2012-09-28  Roland McGrath  <roland@hack.frob.com>
+
+	* sysdeps/unix/sysv/linux/m68k/init-first.c: Include main file from
+	csu/ rather than sysdeps/unix/sysv/linux/.
+
 2012-08-27  Joseph Myers  <joseph@codesourcery.com>
 
 	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
diff --git a/ports/ChangeLog.mips b/ports/ChangeLog.mips
index 9df62cc..9f2e236 100644
--- a/ports/ChangeLog.mips
+++ b/ports/ChangeLog.mips
@@ -1,3 +1,7 @@
+2012-09-28  Roland McGrath  <roland@hack.frob.com>
+
+	* sysdeps/mips/init-first.c: File removed.
+
 2012-09-28  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* sysdeps/mips/dl-trampoline.c (VERSYMIDX): Likewise.
diff --git a/ports/sysdeps/mips/init-first.c b/ports/sysdeps/mips/init-first.c
deleted file mode 100644
index 6a5e7ca..0000000
--- a/ports/sysdeps/mips/init-first.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* Initialization code run first thing by the ELF startup code.  For mips/Unix.
-   Copyright (C) 1996, 1997, 2010 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <unistd.h>
-
-extern void __libc_init (int, char **, char **);
-extern void __libc_global_ctors (void);
-
-
-static void
-init (int *data)
-{
-  int argc = *data;
-  char **argv = (void *) (data + 1);
-  char **envp = &argv[argc + 1];
-
-  __environ = envp;
-  __libc_init (argc, argv, envp);
-}
-
-#ifdef SHARED
-/* This function is called to initialize the shared C library.
-   It is called just before the user _start code from mips/elf/start.S,
-   with the stack set up as that code gets it.  */
-
-/* NOTE!  The linker notices the magical name `_init' and sets the DT_INIT
-   pointer in the dynamic section based solely on that.  It is convention
-   for this function to be in the `.init' section, but the symbol name is
-   the only thing that really matters!!  */
-/*void _init (int argc, ...) __attribute__ ((unused, section (".init")));*/
-
-void
-_init (int argc, ...)
-{
-  init (&argc);
-
-#ifndef NO_CTORS_DTORS_SECTIONS
-  __libc_global_ctors ();
-#endif
-}
-#endif
-
-
-void
-__libc_init_first (int argc __attribute__ ((unused)), ...)
-{
-#ifndef SHARED
-  init (&argc);
-#endif
-}
diff --git a/ports/sysdeps/unix/sysv/linux/m68k/init-first.c b/ports/sysdeps/unix/sysv/linux/m68k/init-first.c
index ec311ec..713ab86 100644
--- a/ports/sysdeps/unix/sysv/linux/m68k/init-first.c
+++ b/ports/sysdeps/unix/sysv/linux/m68k/init-first.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2010 Free Software Foundation, Inc.
+/* Initialization code run first thing by the ELF startup code.  Linux/m68k.
+   Copyright (C) 2010-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Maxim Kuvyrkov <maxim@codesourcery.com>, 2010.
 
@@ -70,4 +71,4 @@ _libc_vdso_platform_setup (void)
 
 #endif /* SHARED */
 
-#include <sysdeps/unix/sysv/linux/init-first.c>
+#include <csu/init-first.c>
diff --git a/sysdeps/i386/init-first.c b/sysdeps/i386/init-first.c
deleted file mode 100644
index edea7f2..0000000
--- a/sysdeps/i386/init-first.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* Initialization code run first thing by the ELF startup code.  For i386/Unix.
-   Copyright (C) 1995-2012 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <ctype.h>
-#include <unistd.h>
-
-extern void __libc_init (int, char **, char **);
-#ifdef USE_NONOPTION_FLAGS
-extern void __getopt_clean_environment (char **);
-#endif
-extern void __libc_global_ctors (void);
-
-int __libc_multiple_libcs attribute_hidden = 1;
-
-static void
-init (int *data)
-{
-  int argc = *data;
-  char **argv = (void *) (data + 1);
-  char **envp = &argv[argc + 1];
-
-  __environ = envp;
-  __libc_init (argc, argv, envp);
-
-#ifdef USE_NONOPTION_FLAGS
-  /* This is a hack to make the special getopt in GNU libc working.  */
-  __getopt_clean_environment (envp);
-#endif
-
-  /* Initialize ctype data.  */
-  __ctype_init ();
-}
-
-#ifdef SHARED
-/* This function is called to initialize the shared C library.
-   It is called just before the user _start code from i386/start.S,
-   with the stack set up as that code gets it.  */
-
-/* NOTE!  The linker notices the magical name `_init' and sets the DT_INIT
-   pointer in the dynamic section based solely on that.  It is convention
-   for this function to be in the `.init' section, but the symbol name is
-   the only thing that really matters!!  */
-/*void _init (int argc, ...) __attribute__ ((unused, section (".init")));*/
-
-void
-_init (int argc, ...)
-{
-  init (&argc);
-
-#ifndef NO_CTORS_DTORS_SECTIONS
-  __libc_global_ctors ();
-#endif
-}
-#endif
-
-
-void
-__libc_init_first (int argc __attribute__ ((unused)), ...)
-{
-#ifndef SHARED
-  init (&argc);
-#endif
-}
diff --git a/sysdeps/sh/init-first.c b/sysdeps/sh/init-first.c
deleted file mode 100644
index f298724..0000000
--- a/sysdeps/sh/init-first.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* Initialization code run first thing by the ELF startup code.  For SH.
-   Copyright (C) 1995-2012 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <ctype.h>
-#include <unistd.h>
-
-extern void __libc_init (int, char **, char **);
-#ifdef USE_NONOPTION_FLAGS
-extern void __getopt_clean_environment (char **);
-#endif
-extern void __libc_global_ctors (void);
-
-int __libc_multiple_libcs attribute_hidden = 1;
-
-static void
-init (int *data)
-{
-  int argc = *data;
-  char **argv = (void *) (data + 1);
-  char **envp = &argv[argc + 1];
-
-  __environ = envp;
-  __libc_init (argc, argv, envp);
-
-#ifdef USE_NONOPTION_FLAGS
-  /* This is a hack to make the special getopt in GNU libc working.  */
-  __getopt_clean_environment (envp);
-#endif
-
-  /* Initialize ctype data.  */
-  __ctype_init ();
-}
-
-#ifdef SHARED
-/* This function is called to initialize the shared C library.
-   It is called just before the user _start code from sh/sh[34]/start.S,
-   with the stack set up as that code gets it.  */
-
-/* NOTE!  The linker notices the magical name `_init' and sets the DT_INIT
-   pointer in the dynamic section based solely on that.  It is convention
-   for this function to be in the `.init' section, but the symbol name is
-   the only thing that really matters!!  */
-/*void _init (int argc, ...) __attribute__ ((unused, section (".init")));*/
-
-void
-_init (int argc, ...)
-{
-  init (&argc);
-
-#ifndef NO_CTORS_DTORS_SECTIONS
-  __libc_global_ctors ();
-#endif
-}
-#endif
-
-
-void
-__libc_init_first (int argc __attribute__ ((unused)), ...)
-{
-#ifndef SHARED
-  init (&argc);
-#endif
-}
diff --git a/sysdeps/unix/sysv/linux/init-first.c b/sysdeps/unix/sysv/linux/init-first.c
deleted file mode 100644
index 00234e6..0000000
--- a/sysdeps/unix/sysv/linux/init-first.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/* Initialization code run first thing by the ELF startup code.  Linux version.
-   Copyright (C) 1995-2004, 2005, 2007, 2011 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sysdep.h>
-#include <fpu_control.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <libc-internal.h>
-
-#include <ldsodefs.h>
-
-/* Set nonzero if we have to be prepared for more then one libc being
-   used in the process.  Safe assumption if initializer never runs.  */
-int __libc_multiple_libcs attribute_hidden = 1;
-
-/* Remember the command line argument and enviroment contents for
-   later calls of initializers for dynamic libraries.  */
-int __libc_argc attribute_hidden;
-char **__libc_argv attribute_hidden;
-
-
-void
-__libc_init_first (int argc, char **argv, char **envp)
-{
-#ifdef SHARED
-  /* For DSOs we do not need __libc_init_first but instead _init.  */
-}
-
-void
-attribute_hidden
-_init (int argc, char **argv, char **envp)
-{
-#endif
-#ifdef USE_NONOPTION_FLAGS
-  extern void __getopt_clean_environment (char **);
-#endif
-
-  __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
-
-  /* Make sure we don't initialize twice.  */
-  if (!__libc_multiple_libcs)
-    {
-      /* Set the FPU control word to the proper default value if the
-	 kernel would use a different value.  (In a static program we
-	 don't have this information.)  */
-#ifdef SHARED
-      if (__fpu_control != GLRO(dl_fpu_control))
-#endif
-	__setfpucw (__fpu_control);
-    }
-
-  /* Save the command-line arguments.  */
-  __libc_argc = argc;
-  __libc_argv = argv;
-  __environ = envp;
-
-#ifndef SHARED
-  __libc_init_secure ();
-
-  /* First the initialization which normally would be done by the
-     dynamic linker.  */
-  _dl_non_dynamic_init ();
-#endif
-
-#ifdef VDSO_SETUP
-  VDSO_SETUP ();
-#endif
-
-  __init_misc (argc, argv, envp);
-
-#ifdef USE_NONOPTION_FLAGS
-  /* This is a hack to make the special getopt in GNU libc working.  */
-  __getopt_clean_environment (envp);
-#endif
-
-  /* Initialize ctype data.  */
-  __ctype_init ();
-
-#if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
-  __libc_global_ctors ();
-#endif
-}
-
-/* This function is defined here so that if this file ever gets into
-   ld.so we will get a link error.  Having this file silently included
-   in ld.so causes disaster, because the _init definition above will
-   cause ld.so to gain an init function, which is not a cool thing. */
-
-extern void _dl_start (void) __attribute__ ((noreturn));
-
-void
-_dl_start (void)
-{
-  abort ();
-}
diff --git a/sysdeps/unix/sysv/linux/powerpc/init-first.c b/sysdeps/unix/sysv/linux/powerpc/init-first.c
index 57b36af..ba7ae29 100644
--- a/sysdeps/unix/sysv/linux/powerpc/init-first.c
+++ b/sysdeps/unix/sysv/linux/powerpc/init-first.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2007 Free Software Foundation, Inc.
+/* Initialization code run first thing by the ELF startup code.  Linux/PowerPC.
+   Copyright (C) 2007-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -45,4 +46,4 @@ _libc_vdso_platform_setup (void)
 # define VDSO_SETUP _libc_vdso_platform_setup
 #endif
 
-#include "../init-first.c"
+#include <csu/init-first.c>
diff --git a/sysdeps/unix/sysv/linux/s390/init-first.c b/sysdeps/unix/sysv/linux/s390/init-first.c
index c971382..a066dae 100644
--- a/sysdeps/unix/sysv/linux/s390/init-first.c
+++ b/sysdeps/unix/sysv/linux/s390/init-first.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2008 Free Software Foundation, Inc.
+/* Initialization code run first thing by the ELF startup code.  Linux/s390.
+   Copyright (C) 2008-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -46,4 +47,4 @@ _libc_vdso_platform_setup (void)
 # define VDSO_SETUP _libc_vdso_platform_setup
 #endif
 
-#include "../init-first.c"
+#include <csu/init-first.c>
diff --git a/sysdeps/unix/sysv/linux/x86_64/init-first.c b/sysdeps/unix/sysv/linux/x86_64/init-first.c
index e8b52ea..dd41f0f 100644
--- a/sysdeps/unix/sysv/linux/x86_64/init-first.c
+++ b/sysdeps/unix/sysv/linux/x86_64/init-first.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2007, 2011 Free Software Foundation, Inc.
+/* Initialization code run first thing by the ELF startup code.  Linux/x86-64.
+   Copyright (C) 2007-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -54,4 +55,4 @@ _libc_vdso_platform_setup (void)
 # define VDSO_SETUP _libc_vdso_platform_setup
 #endif
 
-#include "../init-first.c"
+#include <csu/init-first.c>
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/init-first.c b/sysdeps/unix/sysv/linux/x86_64/x32/init-first.c
index c2aea9d..5fe472e 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/init-first.c
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/init-first.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2012 Free Software Foundation, Inc.
+/* Initialization code run first thing by the ELF startup code.  Linux/x32.
+   Copyright (C) 2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -37,4 +38,4 @@ _libc_vdso_platform_setup (void)
 # define VDSO_SETUP _libc_vdso_platform_setup
 #endif
 
-#include "../../init-first.c"
+#include <csu/init-first.c>

http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=67f2ca31a07ea7487dc5266bdc196e1fac23baf6

commit 67f2ca31a07ea7487dc5266bdc196e1fac23baf6
Author: Roland McGrath <roland@hack.frob.com>
Date:   Fri Sep 28 16:22:51 2012 -0700

    Implement POSIX-generic sleep via nanosleep rather than SIGARLM.

diff --git a/ChangeLog b/ChangeLog
index 4a31c3f..8f61e77 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2012-09-28  Roland McGrath  <roland@hack.frob.com>
 
+	* sysdeps/posix/sleep.c (__sleep): Rewritten using __nanosleep
+	instead of SIGALRM.
+
 	* sysdeps/gnu/_G_config.h: Moved to ...
 	* sysdeps/unix/sysv/linux/_G_config.h: ... here.
 	* sysdeps/mach/hurd/_G_config.h: Moved to ...
diff --git a/sysdeps/posix/sleep.c b/sysdeps/posix/sleep.c
index dfd7420..b3c9e27 100644
--- a/sysdeps/posix/sleep.c
+++ b/sysdeps/posix/sleep.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991, 1992, 1993, 1996, 1997 Free Software Foundation, Inc.
+/* Sleep for a given number of seconds.  POSIX.1 version.
+   Copyright (C) 1991-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -15,20 +16,12 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <signal.h>
 #include <time.h>
 #include <unistd.h>
 #include <errno.h>
+#include <sys/param.h>
 
 
-/* SIGALRM signal handler for `sleep'.  This does nothing but return,
-   but SIG_IGN isn't supposed to break `pause'.  */
-static void
-sleep_handler (int sig)
-{
-  return;
-}
-
 /* Make the process sleep for SECONDS seconds, or until a signal arrives
    and is not ignored.  The function returns the number of seconds less
    than SECONDS which it actually slept (zero if it slept the full time).
@@ -39,67 +32,44 @@ sleep_handler (int sig)
 unsigned int
 __sleep (unsigned int seconds)
 {
-  unsigned int remaining, slept;
-  time_t before, after;
-  sigset_t set, oset;
-  struct sigaction act, oact;
-  int save = errno;
-
-  if (seconds == 0)
-    return 0;
-
-  /* Block SIGALRM signals while frobbing the handler.  */
-  if (sigemptyset (&set) < 0 ||
-      sigaddset (&set, SIGALRM) < 0 ||
-      sigprocmask (SIG_BLOCK, &set, &oset))
-    return seconds;
-
-  act.sa_handler = sleep_handler;
-  act.sa_flags = 0;
-  act.sa_mask = oset;	/* execute handler with original mask */
-  if (sigaction (SIGALRM, &act, &oact) < 0)
-    return seconds;
-
-  before = time ((time_t *) NULL);
-  remaining = alarm (seconds);
-
-  if (remaining > 0 && remaining < seconds)
+  /* This is not necessary but some buggy programs depend on it.  */
+  if (__builtin_expect (seconds == 0, 0))
     {
-      /* The user's alarm will expire before our own would.
-	 Restore the user's signal action state and let his alarm happen.  */
-      (void) sigaction (SIGALRM, &oact, (struct sigaction *) NULL);
-      alarm (remaining);	/* Restore sooner alarm.  */
-      sigsuspend (&oset);	/* Wait for it to go off.  */
-      after = time ((time_t *) NULL);
+#ifdef CANCELLATION_P
+      CANCELLATION_P (THREAD_SELF);
+#endif
+      return 0;
     }
-  else
-    {
-      /* Atomically restore the old signal mask
-	 (which had better not block SIGALRM),
-	 and wait for a signal to arrive.  */
-      sigsuspend (&oset);
 
-      after = time ((time_t *) NULL);
+  int save_errno = errno;
 
-      /* Restore the old signal action state.  */
-      (void) sigaction (SIGALRM, &oact, (struct sigaction *) NULL);
+  const unsigned int max
+    = (unsigned int) (((unsigned long int) (~((time_t) 0))) >> 1);
+  struct timespec ts = { 0, 0 };
+  do
+    {
+      if (sizeof (ts.tv_sec) <= sizeof (seconds))
+        {
+          /* Since SECONDS is unsigned assigning the value to .tv_sec can
+             overflow it.  In this case we have to wait in steps.  */
+          ts.tv_sec += MIN (seconds, max);
+          seconds -= (unsigned int) ts.tv_sec;
+        }
+      else
+        {
+          ts.tv_sec = (time_t) seconds;
+          seconds = 0;
+        }
+
+      if (__nanosleep (&ts, &ts) < 0)
+        /* We were interrupted.
+           Return the number of (whole) seconds we have not yet slept.  */
+        return seconds + ts.tv_sec;
     }
+  while (seconds > 0);
 
-  /* Notice how long we actually slept.  */
-  slept = after - before;
-
-  /* Restore the user's alarm if we have not already past it.
-     If we have, be sure to turn off the alarm in case a signal
-     other than SIGALRM was what woke us up.  */
-  (void) alarm (remaining > slept ? remaining - slept : 0);
-
-  /* Restore the original signal mask.  */
-  (void) sigprocmask (SIG_SETMASK, &oset, (sigset_t *) NULL);
-
-  /* Restore the `errno' value we started with.
-     Some of the calls we made might have failed, but we didn't care.  */
-  __set_errno (save);
+  __set_errno (save_errno);
 
-  return slept > seconds ? 0 : seconds - slept;
+  return 0;
 }
 weak_alias (__sleep, sleep)

-----------------------------------------------------------------------


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]