} else if (errno != EINTR && errno != EAGAIN)
return -1;
if (errno == EAGAIN) /* Try later, *sigh* */
- usleep(10000);
+ xusleep(250000);
}
return 0;
}
} else if (errno != EINTR && errno != EAGAIN)
return -1;
if (errno == EAGAIN) /* Try later, *sigh* */
- usleep(10000);
+ xusleep(250000);
}
return 0;
}
ret = read(fd, buf, count);
if (ret <= 0) {
if ((errno == EAGAIN || errno == EINTR || ret == 0) &&
- (tries++ < 5))
+ (tries++ < 5)) {
+ xusleep(250000);
continue;
+ }
return c ? c : -1;
}
if (ret > 0)
return 64;
}
-#ifndef HAVE_USLEEP
/*
- * This function is marked obsolete in POSIX.1-2001 and removed in
- * POSIX.1-2008. It is replaced with nanosleep().
+ * The usleep function is marked obsolete in POSIX.1-2001 and removed in
+ * POSIX.1-2008. This is replaced with nanosleep() that provides more
+ * advantages (like no interaction with signals and other timer functions.
*/
-static inline int usleep(useconds_t usec)
+#include <time.h>
+
+static inline int xusleep(useconds_t usec)
{
+#ifdef HAVE_NANOSLEEP
struct timespec waittime = {
.tv_sec = usec / 1000000L,
.tv_nsec = (usec % 1000000L) * 1000
};
return nanosleep(&waittime, NULL);
-}
+#elif defined(HAVE_USLEEP)
+ return usleep(usec);
+#else
+# error "System with usleep() or nanosleep() required!"
#endif
+}
/*
* Constant strings for usage() functions. For more info see
if (synctime && synctime - tv.tv_sec > 1) {
usecs = ((synctime - tv.tv_sec) * 1000000UL) -
(1000000UL - tv.tv_usec);
- usleep(usecs);
+ xusleep(usecs);
}
}
* concurrent processes happy.
*/
if (synctime)
- usleep(25000);
+ xusleep(25000);
}
return 0;
while (cp->eol == '\0') {
if (read(fd, &c, 1) < 1) {
if (errno == EINTR || errno == EAGAIN) {
- usleep(1000);
+ xusleep(250000);
continue;
}
ret = (char*)0;
if (*usemask & (1<<con->id))
continue;
kill(con->pid, SIGHUP);
- usleep(5000);
+ usleep(50000);
kill(con->pid, SIGKILL);
}
}
* A2000 RTCs and simply hangs after some time. Inserting a
* sleep helps."
*/
- usleep(1);
+ xusleep(1);
if (ioctl(con_fd, KDGHWCLK, &nowtime) == -1) {
warn(_("KDGHWCLK ioctl to read time failed in loop"));
program_invocation_short_name, suspend, devname,
ctime(&alarm));
fflush(stdout);
- usleep(10 * 1000);
+ xusleep(10 * 1000);
}
if (strcmp(suspend, "no") == 0) {
/* The terminal could be open with O_NONBLOCK when
* -L (force CLOCAL) is specified... */
if (errno == EINTR || errno == EAGAIN) {
- usleep(250000);
+ xusleep(250000);
continue;
}
switch (errno) {
{
do {
roll_file(filename, size);
- usleep(250000);
+ xusleep(250000);
} while(1);
}