patch for tail: fractional-second --sleep-interval when doing "tail -f"

Erik Rossen <[email protected]>
Newsgroups gmane.comp.gnu.textutils.bugs
Message-ID <[email protected]>
This patch elimates a FIXME: adding fractional-second sleep intervals
for the "tail -f" command.

The following diff is against the tail.c in the textutils package of
Debian woody, but it is probably not too different from the GNU
original.

-- 
Erik Rossen                         ^    OpenPGP key: 2935D0B9
[email protected]                 /e\   "Use GnuPG, see the
http://www.multimania.com/rossen   ---    black helicopters."
tail.patch (text/plain, 1.3 KB)
--- tail.c	Thu Apr 11 21:05:28 2002
+++ tail.c.NEW	Thu Apr 11 21:06:39 2002
@@ -170,8 +170,8 @@
 /* The number of seconds to sleep between iterations.
    During one iteration, every file name or descriptor is checked to
    see if it has changed.  */
-/* FIXME: allow fractional seconds */
-static unsigned int sleep_interval = 1;
+/* sleep interval defaults to 1,000,000 microseconds */
+static unsigned long sleep_interval = 1000000;
 
 /* The process ID of the process (presumably on the current host)
    that is writing to all followed files.  */
@@ -921,7 +921,7 @@
 	{
 	  if (writer_is_dead)
 	    break;
-	  sleep (sleep_interval);
+	  usleep (sleep_interval);
 
 	  /* Once the writer is dead, read the files once more to
 	     avoid a race condition.  */
@@ -1408,14 +1408,14 @@
 	case 's':
 	  {
 	    strtol_error s_err;
-	    unsigned long int tmp_ulong;
-	    s_err = xstrtoul (optarg, NULL, 10, &tmp_ulong, "");
-	    if (s_err != LONGINT_OK || tmp_ulong > UINT_MAX)
+	    double tmp_d;
+	    s_err = xstrtod (optarg, NULL, &tmp_d);
+	    if (s_err != LONGINT_OK || (unsigned long) (tmp_d*1000000.0) > UINT_MAX)
 	      {
 		error (EXIT_FAILURE, 0,
 		       _("%s: invalid number of seconds"), optarg);
 	      }
-	    sleep_interval = tmp_ulong;
+	    sleep_interval = (unsigned long) (tmp_d*1000000.0);
 	  }
 	  break;
signature.asc (application/pgp-signature, 232 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8teOzY88aPik10LkRAkwOAKDnRp2E5p5Xi6BwSlceC2YiFtlHyACfdfP+
tonoxIxuaTznYzGmwVNrxc0=
=Rvo5
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.