From b6653769f3ae1c31cc5d475c2075499216c7433e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 23 May 2016 19:21:37 -0700 Subject: Don't use sleep function in tail streams. Let's use our usleep_wrap function which uses nanosleep. The old sleep can interact with SIGALRM. * stream.c (tail_calc): Calculate microseconds instead of seconds. (sleep): Wrapper for Windows gone. (tail_strategy): Rename sec variable to usec. Use usleep_wrap instead of sleep. * sysif.c (usleep_wrap): Change to extern. * sysif.h (usleep_wrap): Declaration updated. --- stream.c | 26 +++++++------------------- sysif.c | 2 +- sysif.h | 1 + 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/stream.c b/stream.c index c25a9739..469416be 100644 --- a/stream.c +++ b/stream.c @@ -864,37 +864,25 @@ static struct strm_ops stdio_ops = static struct strm_ops stdio_sock_ops; #endif -static void tail_calc(unsigned long *state, int *sec, int *mod) +static void tail_calc(unsigned long *state, int *usec, int *mod) { unsigned long count = (*state)++; if (count > 32) count = 32; - *sec = 1 << (count / 8); + *usec = 1048576 << (count / 8); *mod = 8 >> (count / 8); if (*mod == 0) *mod = 1; } -#if !HAVE_POSIX_SLEEP && HAVE_WINDOWS_H - -int sleep(int sec); - -int sleep(int sec) -{ - Sleep(sec * 1000); - return 0; -} - -#endif - static void tail_strategy(val stream, unsigned long *state) { struct stdio_handle *h = coerce(struct stdio_handle *, stream->co.handle); - int sec = 0, mod = 0; + int usec = 0, mod = 0; val mode = nil; struct stdio_mode m, m_r = stdio_mode_init_r; - tail_calc(state, &sec, &mod); + tail_calc(state, &usec, &mod); if (h->is_rotated) { /* We already know that the file has rotated. The caller @@ -907,7 +895,7 @@ static void tail_strategy(val stream, unsigned long *state) } else if (h->f != 0) { /* We have a file and it hasn't rotated; so sleep on it. */ sig_save_enable; - sleep(sec); + usleep_wrap(num(usec)); sig_restore_enable; } @@ -940,9 +928,9 @@ static void tail_strategy(val stream, unsigned long *state) } /* Unable to open; keep trying. */ - tail_calc(state, &sec, &mod); + tail_calc(state, &usec, &mod); sig_save_enable; - sleep(sec); + usleep_wrap(num(usec)); sig_restore_enable; continue; } diff --git a/sysif.c b/sysif.c index 78327b0c..e22db64a 100644 --- a/sysif.c +++ b/sysif.c @@ -158,7 +158,7 @@ static val abort_wrap(void) abort(); } -static val usleep_wrap(val usec) +val usleep_wrap(val usec) { val retval; cnum u = c_num(usec); diff --git a/sysif.h b/sysif.h index 5b22ea5c..4d9f3f42 100644 --- a/sysif.h +++ b/sysif.h @@ -45,6 +45,7 @@ typedef long off_t; val getenv_wrap(val name); val at_exit_call(val func); val at_exit_do_not_call(val func); +val usleep_wrap(val usec); #if HAVE_FORK_STUFF val exec_wrap(val file, val args_opt); #endif -- cgit v1.2.3