Author: jilles
Date: Wed Jul  3 21:11:56 2013
New Revision: 252606
URL: http://svnweb.freebsd.org/changeset/base/252606

Log:
  MFC r251078,r251433: sleep: Improve nanosleep() error handling:
  
   * Work around kernel bugs that cause a spurious [EINTR] return if a
     debugger (such as truss(1)) is attached.
  
   * Write an error message if an error other than [EINTR] occurs.
  
  PR:           bin/178664

Modified:
  stable/9/bin/sleep/sleep.c
Directory Properties:
  stable/9/bin/sleep/   (props changed)

Modified: stable/9/bin/sleep/sleep.c
==============================================================================
--- stable/9/bin/sleep/sleep.c  Wed Jul  3 21:07:02 2013        (r252605)
+++ stable/9/bin/sleep/sleep.c  Wed Jul  3 21:11:56 2013        (r252606)
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
 
 #include <ctype.h>
 #include <err.h>
+#include <errno.h>
 #include <limits.h>
 #include <signal.h>
 #include <stdint.h>
@@ -81,14 +82,20 @@ main(int argc, char *argv[])
        time_to_sleep.tv_nsec = 1e9 * (d - time_to_sleep.tv_sec);
 
        signal(SIGINFO, report_request);
+
+       /*
+        * Note: [EINTR] is supposed to happen only when a signal was handled
+        * but the kernel also returns it when a ptrace-based debugger
+        * attaches. This is a bug but it is hard to fix.
+        */
        while (nanosleep(&time_to_sleep, &time_to_sleep) != 0) {
                if (report_requested) {
                        /* Reporting does not bother with nanoseconds. */
                        warnx("about %d second(s) left out of the original %d",
                            (int)time_to_sleep.tv_sec, (int)original);
                        report_requested = 0;
-               } else
-                       break;
+               } else if (errno != EINTR)
+                       err(1, "nanosleep");
        }
        return (0);
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to