Fixing a bug on -c and -t that remained open after killing 'less' on "ts -c | less"
authorviric@mandarina
Fri, 02 Oct 2009 20:01:16 +0200
changeset 277 1ee3c4ef9402
parent 276 dc78c982c8c5
child 278 1698b327528d
Fixing a bug on -c and -t that remained open after killing 'less' on "ts -c | less" I also moved up the version, and updated changelog.
Changelog
main.c
tail.c
--- a/Changelog	Fri Oct 02 19:38:30 2009 +0200
+++ b/Changelog	Fri Oct 02 20:01:16 2009 +0200
@@ -10,6 +10,9 @@
 Future:
  - Use a better system than mkstemp() for finding output files, so we can add
    .gz to the gzipped outputs.
+v0.6.5:
+ - Fixed a problem that -c and -t, if their pipe was broken, they remained.
+ - Fixed a problem (maybe some copypaste once?) on -l, that created always an error msg.
 v0.6.4:
  - Fixed a bug breaking -c and -t.
 v0.6.3:
--- a/main.c	Fri Oct 02 19:38:30 2009 +0200
+++ b/main.c	Fri Oct 02 20:01:16 2009 +0200
@@ -25,7 +25,7 @@
 static char getopt_env[] = "POSIXLY_CORRECT=YES";
 static char *old_getopt_env;
 
-static char version[] = "Task Spooler v0.6.3 - a task queue system for the unix user.\n"
+static char version[] = "Task Spooler v0.6.5 - a task queue system for the unix user.\n"
 "Copyright (C) 2007-2009  Lluis Batlle i Rossell";
 
 
--- a/tail.c	Fri Oct 02 19:38:30 2009 +0200
+++ b/tail.c	Fri Oct 02 20:01:16 2009 +0200
@@ -116,8 +116,9 @@
     int waiting_end = 1;
     int end_res = 0;
     int endfile_reached = 0;
+    int could_write = 1;
 
-    fd_set readset;
+    fd_set readset, errorset;
 
     fd = open(fname, O_RDONLY);
 
@@ -145,9 +146,13 @@
         if (waiting_end)
         {
             FD_SET(server_socket, &readset);
-            maxfd = max(fd, server_socket);
+            maxfd = max(maxfd, server_socket);
         }
 
+        FD_ZERO(&errorset);
+        FD_SET(1, &errorset);
+        maxfd = max(maxfd, server_socket);
+
         /* If we don't have fd's to wait for, let's sleep */
         if (maxfd == -1)
         {
@@ -156,7 +161,7 @@
         {
             /* Otherwise, do a normal select */
             struct timeval tv = {1 /*sec*/, 0 };
-            res = select(maxfd + 1, &readset, 0, 0, &tv);
+            res = select(maxfd + 1, &readset, 0, &errorset, &tv);
         }
 
         if (FD_ISSET(server_socket, &readset))
@@ -182,8 +187,27 @@
         else
             endfile_reached = 0;
 
-        write(1, buf, res);
-    } while(!endfile_reached || waiting_end);
+        if (!FD_ISSET(1, &errorset))
+        {
+            while(res > 0)
+            {
+                int wres;
+                wres = write(1, buf, res);
+                /* Maybe the listener doesn't want to receive more */
+                if (wres < 0)
+                {
+                    could_write = 0;
+                    break;
+                }
+                res -= wres;
+            }
+        }
+        else
+        {
+            could_write = 0;
+            break;
+        }
+    } while((!endfile_reached || waiting_end) && could_write);
 
     close(fd);