]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
badblocks: If nanosleep() does not exist, try using usleep() instead
authorTheodore Ts'o <tytso@mit.edu>
Sun, 13 Jul 2008 20:17:57 +0000 (16:17 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 13 Jul 2008 20:38:56 +0000 (16:38 -0400)
For portability on systems that don't have nanosleep().

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
configure
configure.in
misc/badblocks.c

index 0b7a05eed2ae0f33c71df7ef797324cce950ee38..41f4f4bfdc4ff7ac26a9e040eaef5b23d486756f 100755 (executable)
--- a/configure
+++ b/configure
@@ -14883,7 +14883,9 @@ fi
 
 
 
-for ac_func in chflags getrusage llseek lseek64 open64 fstat64 ftruncate64 getmntinfo strtoull strcasecmp srandom jrand48 fchown mallinfo fdatasync strnlen strptime strdup sysconf pathconf posix_memalign memalign valloc __secure_getenv prctl mmap utime setresuid setresgid
+
+
+for ac_func in chflags getrusage llseek lseek64 open64 fstat64 ftruncate64 getmntinfo strtoull strcasecmp srandom jrand48 fchown mallinfo fdatasync strnlen strptime strdup sysconf pathconf posix_memalign memalign valloc __secure_getenv prctl mmap utime setresuid setresgid usleep nanosleep
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 { echo "$as_me:$LINENO: checking for $ac_func" >&5
index 4d84eeb9523b1c3a05faae20e75edd2eb6e71f8d..c29f4389998e24f2dd23bdf83400ad6400bb8c22 100644 (file)
@@ -741,7 +741,7 @@ AC_CHECK_MEMBER(struct sockaddr.sa_len,
        [#include <sys/types.h>
         #include <sys/socket.h>])
 dnl
-AC_CHECK_FUNCS(chflags getrusage llseek lseek64 open64 fstat64 ftruncate64 getmntinfo strtoull strcasecmp srandom jrand48 fchown mallinfo fdatasync strnlen strptime strdup sysconf pathconf posix_memalign memalign valloc __secure_getenv prctl mmap utime setresuid setresgid)
+AC_CHECK_FUNCS(chflags getrusage llseek lseek64 open64 fstat64 ftruncate64 getmntinfo strtoull strcasecmp srandom jrand48 fchown mallinfo fdatasync strnlen strptime strdup sysconf pathconf posix_memalign memalign valloc __secure_getenv prctl mmap utime setresuid setresgid usleep nanosleep)
 dnl
 dnl Check to see if -lsocket is required (solaris) to make something
 dnl that uses socket() to compile; this is needed for the UUID library
index 9a4c3629120a4df860134a6e50a9f2b317123eff..946c839f06e9065a0d397bb8b531a8301bfc2e24 100644 (file)
@@ -297,6 +297,7 @@ static int do_read (int dev, unsigned char * buffer, int try, int block_size,
                fprintf(stderr, _("Weird value (%ld) in do_read\n"), got);
        got /= block_size;
        if (d_flag && got == try) {
+#ifdef HAVE_NANOSLEEP
                struct timespec ts;
                ts.tv_sec = tv2.tv_sec - tv1.tv_sec;
                ts.tv_nsec = (tv2.tv_usec - tv1.tv_usec) * MILISEC;
@@ -313,6 +314,23 @@ static int do_read (int dev, unsigned char * buffer, int try, int block_size,
                }
                if (ts.tv_sec || ts.tv_nsec)
                        nanosleep(&ts, NULL);
+#else
+#ifdef HAVE_USLEEP
+               struct timeval tv;
+               tv.tv_sec = tv2.tv_sec - tv1.tv_sec;
+               tv.tv_usec = tv2.tv_usec - tv1.tv_usec;
+               tv.tv_sec = tv.tv_sec * d_flag / 100;
+               tv.tv_usec = tv.tv_usec * d_flag / 100;
+               if (tv.tv_usec > 1000000) {
+                       tv.tv_sec += tv.tv_usec / 1000000;
+                       tv.tv_usec %= 1000000;
+               }
+               if (tv.tv_sec)
+                       sleep(tv.tv_sec);
+               if (tv.tv_usec)
+                       usleep(tv.tv_usec);
+#endif
+#endif
        }
        return got;
 }