Fixing a process left, when "-r" is used without jobid.
authorviric
Mon, 11 Nov 2013 09:28:51 +0100
changeset 334 e9e212846a89
parent 333 4a2f6bdca101
child 335 b4a5d9544836
Fixing a process left, when "-r" is used without jobid.
jobs.c
main.h
server.c
--- a/jobs.c	Thu May 09 21:41:26 2013 +0200
+++ b/jobs.c	Mon Nov 11 09:28:51 2013 +0100
@@ -935,13 +935,15 @@
     }
 }
 
-int s_remove_job(int s, int jobid)
+/* jobid is input/output. If the input is -1, it's changed to the jobid
+ * removed */
+int s_remove_job(int s, int *jobid)
 {
     struct Job *p = 0;
     struct msg m;
     struct Job *before_p = 0;
 
-    if (jobid == -1)
+    if (*jobid == -1)
     {
         /* Find the last job added */
         p = firstjob;
@@ -971,7 +973,7 @@
         p = firstjob;
         if (p != 0)
         {
-            while (p->next != 0 && p->jobid != jobid)
+            while (p->next != 0 && p->jobid != *jobid)
             {
                 before_p = p;
                 p = p->next;
@@ -979,17 +981,17 @@
         }
 
         /* If not found, look in the 'finished' list */
-        if (p == 0 || p->jobid != jobid)
+        if (p == 0 || p->jobid != *jobid)
         {
             p = first_finished_job;
             if (p != 0)
             {
-                while (p->next != 0 && p->jobid != jobid)
+                while (p->next != 0 && p->jobid != *jobid)
                 {
                     before_p = p;
                     p = p->next;
                 }
-                if (p->jobid != jobid)
+                if (p->jobid != *jobid)
                     p = 0;
             }
         }
@@ -998,14 +1000,17 @@
     if (p == 0 || p->state == RUNNING || p == firstjob)
     {
         char tmp[50];
-        if (jobid == -1)
+        if (*jobid == -1)
             sprintf(tmp, "The last job cannot be removed.\n");
         else
-            sprintf(tmp, "The job %i cannot be removed.\n", jobid);
+            sprintf(tmp, "The job %i cannot be removed.\n", *jobid);
         send_list_line(s, tmp);
         return 0;
     }
 
+    /* Return the jobid found */
+    *jobid = p->jobid;
+
     /* Tricks for the check_notify_list */
     p->state = FINISHED;
     p->result.errorlevel = -1;
--- a/main.h	Thu May 09 21:41:26 2013 +0200
+++ b/main.h	Mon Nov 11 09:28:51 2013 +0100
@@ -224,7 +224,7 @@
 void s_clear_finished();
 void s_process_runjob_ok(int jobid, char *oname, int pid);
 void s_send_output(int socket, int jobid);
-int s_remove_job(int s, int jobid);
+int s_remove_job(int s, int *jobid);
 void s_remove_notification(int s);
 void check_notify_list(int jobid);
 void s_wait_job(int s, int jobid);
--- a/server.c	Thu May 09 21:41:26 2013 +0200
+++ b/server.c	Mon Nov 11 09:28:51 2013 +0100
@@ -438,7 +438,8 @@
         case REMOVEJOB:
             {
                 int went_ok;
-                went_ok = s_remove_job(s, m.u.jobid);
+                /* Will update the jobid. If it's -1, will set the jobid found */
+                went_ok = s_remove_job(s, &m.u.jobid);
                 if (went_ok)
                 {
                     int i;