From: Eli Zaretskii <eliz@gnu.org> Date: Tue, 30 Jun 2015 16:09:02 +0000 (+0300) Subject: Make sure sleep-for always delays for as long as it's told X-Git-Tag: emacs-25.0.90~1601 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3bea77f65504ee7c4364c300fd1f7d699e2866ac;p=emacs.git Make sure sleep-for always delays for as long as it's told * src/dispnew.c (Fsleep_for): Call wait_reading_process_output in a loop, to ensure we always wait exactly the required amount of time. (Bug#15990) --- diff --git a/src/dispnew.c b/src/dispnew.c index 1fc3cfeef44..7833fe3d01c 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -5679,8 +5679,16 @@ additional wait period, in milliseconds; this is for backwards compatibility. if (duration > 0) { struct timespec t = dtotimespec (duration); - wait_reading_process_output (min (t.tv_sec, WAIT_READING_MAX), - t.tv_nsec, 0, 0, Qnil, NULL, 0); + struct timespec tend = timespec_add (current_timespec (), t); + + /* wait_reading_process_output returns as soon as it detects + output from any subprocess, so we wait in a loop until the + time expires. */ + do { + wait_reading_process_output (min (t.tv_sec, WAIT_READING_MAX), + t.tv_nsec, 0, 0, Qnil, NULL, 0); + t = timespec_sub (tend, current_timespec ()); + } while (timespec_sign (t) > 0); } return Qnil;