nanosleep() replacement
Tim Rice
tim at multitalents.net
Mon Mar 17 11:34:52 EST 2003
I put together a nanosleep() for systems without it.
Please review/test before I commit.
It sems to make UnixWare and Open Server 5 happy.
My SCO Open Server 3 box broke so I can't test it there.
-------------< cut here >----------------
--- openssh/configure.ac.old 2003-03-09 17:16:43.000000000 -0800
+++ openssh/configure.ac 2003-03-16 15:38:28.520560008 -0800
@@ -1483,6 +1483,8 @@
have_struct_timeval=1
fi
+AC_CHECK_TYPES(struct timespec)
+
# If we don't have int64_t then we can't compile sftp-server. So don't
# even attempt to do it.
if test "x$ac_cv_have_int64_t" = "xno" -a \
--- openssh/openbsd-compat/bsd-misc.c.old 2003-01-19 19:21:01.000000000 -0800
+++ openssh/openbsd-compat/bsd-misc.c 2003-03-16 14:49:58.740480006 -0800
@@ -135,3 +135,34 @@
}
#endif
+#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
+int nanosleep(const struct timespec *req, struct timespec *rem)
+{
+ int rc;
+ extern int errno;
+ struct timeval tsave, ttmp, time2wait;
+
+ TIMESPEC_TO_TIMEVAL(&time2wait, req)
+
+ gettimeofday(&tsave, NULL);
+ rc = select(0, NULL, NULL, NULL, &time2wait);
+ if (rc) {
+ gettimeofday (&ttmp, NULL);
+ ttmp.tv_sec -= tsave.tv_sec;
+ ttmp.tv_usec -= tsave.tv_usec;
+ tsave.tv_sec = (time2wait.tv_sec - ttmp.tv_sec);
+ tsave.tv_usec = (time2wait.tv_usec - ttmp.tv_usec);
+ if(tsave.tv_sec < 0){
+ tsave.tv_sec = 0;
+ tsave.tv_usec += 1000000L;
+ }
+ rc = -1;
+ }
+
+ TIMEVAL_TO_TIMESPEC(&tsave, rem)
+
+ return(rc);
+}
+
+#endif
+
--- openssh/openbsd-compat/bsd-misc.h.old 2002-06-20 20:35:30.000000000 -0700
+++ openssh/openbsd-compat/bsd-misc.h 2003-03-16 15:32:29.850560003 -0800
@@ -80,5 +80,14 @@
int setgroups(size_t size, const gid_t *list);
#endif
+#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
+#ifndef HAVE_STRUCT_TIMESPEC
+struct timespec {
+ time_t tv_sec;
+ long tv_nsec;
+};
+#endif
+int nanosleep(const struct timespec *req, struct timespec *rem);
+#endif
#endif /* _BSD_MISC_H */
-------------< end cut >----------------
--
Tim Rice Multitalents (707) 887-1469
tim at multitalents.net
More information about the openssh-unix-dev
mailing list