This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos 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]

Patch for review -- sleep() and nanosleep() return incorrect values when interrupted by a signal


Currently, if nanosleep() is interrupted by a POSIX signal it returns 0. According to POSIX:

If the /nanosleep/() function returns because it has been interrupted by a signal, it shall return a value of -1 and set /errno/ to indicate the interruption.

This in turns fixes the return value for sleep(). Per POSIX:

If /sleep/() returns due to delivery of a signal, the return value shall be the "unslept" amount (the requested time minus the time actually slept) in seconds.

sleep() relies on nanosleep() in order to return the proper value for remaining seconds. Presently, sleep() returns 0 when interrupted.


Index: ecos/packages/compat/posix/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/compat/posix/current/ChangeLog,v
retrieving revision 1.50
diff -u -5 -p -r1.50 ChangeLog
--- ecos/packages/compat/posix/current/ChangeLog 12 Jun 2006 15:43:16 -0000 1.50
+++ ecos/packages/compat/posix/current/ChangeLog 13 Jun 2006 03:34:42 -0000
@@ -1,5 +1,11 @@
+2006-06-13 Dan Jakubiec <dan.jakubiec@systech.com>
+
+ * src/time.cxx: Fixed nanosleep() to return EINTR when it is interrupted
+ by a signal. This in turn fixed sleep() to return the number of unelapsed
+ seconds when interrupted by a signal.
+
2006-06-12 Klaas Gadeyne <klaas.gadeyne@fmtc.be>


       * src/pthread.cxx (pthread_create): name is only defined if
       CYGVAR_KERNEL_THREADS_NAME is set to 1

Index: ecos/packages/compat/posix/current/src/time.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/compat/posix/current/src/time.cxx,v
retrieving revision 1.10
diff -u -5 -p -r1.10 time.cxx
--- ecos/packages/compat/posix/current/src/time.cxx 23 Oct 2005 20:44:36 -0000 1.10
+++ ecos/packages/compat/posix/current/src/time.cxx 13 Jun 2006 03:34:42 -0000
@@ -663,10 +663,14 @@ externC int nanosleep( const struct time


        // Calculate remaining number of ticks.
        ticks -= (now-then);

cyg_ticks_to_timespec( ticks, rmtp );
+
+ // Check for cancellation and then notify the caller that we were interrupted.
+ PTHREAD_TESTCANCEL();
+ TIME_RETURN(EINTR);
}


    // check if we were woken up because we were cancelled.
    PTHREAD_TESTCANCEL();


-- Dan Jakubiec Systech Corporation


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