Now the '-nf' doesn't leave a job in 'finished' state.
authorviric@llimona
Tue, 27 Mar 2007 23:14:58 +0200
changeset 55 678ca291d545
parent 54 74671342eb9e
child 56 fe3e02c74b63
child 58 3c492266923e
Now the '-nf' doesn't leave a job in 'finished' state.
client.c
jobs.c
main.c
main.h
msg.h
testbench.sh
--- a/client.c	Tue Mar 27 22:54:30 2007 +0200
+++ b/client.c	Tue Mar 27 23:14:58 2007 +0200
@@ -24,6 +24,7 @@
     /* global */
     m.u.newjob.command_size = strlen(command) + 1; /* add null */
     m.u.newjob.store_output = command_line.store_output;
+    m.u.newjob.should_keep_finished = command_line.should_keep_finished;
 
     /* Send the message */
     send_msg(server_socket, &m);
--- a/jobs.c	Tue Mar 27 22:54:30 2007 +0200
+++ b/jobs.c	Tue Mar 27 23:14:58 2007 +0200
@@ -28,6 +28,7 @@
     char *output_filename;
     int store_output;
     int pid;
+    int should_keep_finished;
 };
 
 struct Notify
@@ -243,6 +244,7 @@
     p->jobid = jobids++;
     p->state = QUEUED;
     p->store_output = m->u.newjob.store_output;
+    p->should_keep_finished = m->u.newjob.should_keep_finished;
 
     /* load the command */
     p->command = malloc(m->u.newjob.command_size);
@@ -338,7 +340,8 @@
 
     /* Add it to the finished queue */
     newfirst = firstjob->next;
-    new_finished_job(firstjob);
+    if (firstjob->should_keep_finished)
+        new_finished_job(firstjob);
 
     /* Remove it from the run queue */
     firstjob = newfirst;
--- a/main.c	Tue Mar 27 22:54:30 2007 +0200
+++ b/main.c	Tue Mar 27 23:14:58 2007 +0200
@@ -32,6 +32,7 @@
     command_line.need_server = 0;
     command_line.store_output = 1;
     command_line.should_go_background = 1;
+    command_line.should_keep_finished = 1;
 }
 
 void get_command(int index, int argc, char **argv)
@@ -182,6 +183,9 @@
     if (command_line.request != c_SHOW_HELP &&
             command_line.request != c_SHOW_VERSION)
         command_line.need_server = 1;
+
+    if ( ! command_line.store_output && ! command_line.should_go_background )
+        command_line.should_keep_finished = 0;
 }
 
 static void go_background()
--- a/main.h	Tue Mar 27 22:54:30 2007 +0200
+++ b/main.h	Tue Mar 27 23:14:58 2007 +0200
@@ -20,6 +20,7 @@
     int need_server;
     int store_output;
     int should_go_background;
+    int should_keep_finished;
     int jobid;
 };
 
--- a/msg.h	Tue Mar 27 22:54:30 2007 +0200
+++ b/msg.h	Tue Mar 27 23:14:58 2007 +0200
@@ -36,6 +36,7 @@
         struct {
             int command_size;
             int store_output;
+            int should_keep_finished;
         } newjob;
         struct {
             int ofilename_size;
--- a/testbench.sh	Tue Mar 27 22:54:30 2007 +0200
+++ b/testbench.sh	Tue Mar 27 23:14:58 2007 +0200
@@ -11,7 +11,7 @@
 ./ts -w
 
 LINES=`./ts -l | grep finished | wc -l`
-if [ $LINES -ne 6 ]; then
+if [ $LINES -ne 5 ]; then
   echo "Error in simple tasks."
   exit 1
 fi
@@ -101,3 +101,36 @@
 fi
 
 ./ts -K
+
+# Test not adding the job to finished.
+./ts ls
+./ts -w
+LINES=`./ts -l | grep finished | wc -l`
+if [ $LINES -ne 1 ]; then
+  echo "Error in not adding the job to finished."
+  exit 1
+fi
+
+./ts -nf ls > /dev/null
+LINES=`./ts -l | grep finished | wc -l`
+if [ $LINES -ne 1 ]; then
+  echo "Error in not adding the job to finished."
+  exit 1
+fi
+
+./ts -K
+
+# Test clearing the finished jobs
+./ts ls
+./ts ls
+./ts ls
+./ts -nf ls > /dev/null
+./ts -C
+
+LINES=`./ts -l | wc -l`
+if [ $LINES -ne 1 ]; then
+  echo "Error clearing the finished jobs."
+  exit 1
+fi
+
+./ts -K