Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
authorviric <viriketo@gmail.com>
Thu, 28 Jul 2011 19:43:01 +0200
changeset 295 a63f43a17fd7
parent 294 32f895a59c41
child 296 dc46c806c6f4
Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a job due to a full queue. It will return the exit code 2 in that case.
client.c
error.c
execute.c
main.c
main.h
server.c
--- a/client.c	Tue Jul 26 22:36:23 2011 +0200
+++ b/client.c	Thu Jul 28 19:43:01 2011 +0200
@@ -80,6 +80,7 @@
     m.u.newjob.depend_on = command_line.depend_on;
     m.u.newjob.should_keep_finished = command_line.should_keep_finished;
     m.u.newjob.command_size = strlen(new_command) + 1; /* add null */
+    m.u.newjob.wait_enqueuing = command_line.wait_enqueuing;
 
     /* Send the message */
     send_msg(server_socket, &m);
@@ -105,6 +106,11 @@
     res = recv_msg(server_socket, &m);
     if(res == -1)
         error("Error in wait_newjob_ok");
+    if(m.type == NEWJOB_NOK)
+    {
+        fprintf(stderr, "Error, queue full\n");
+        exit(EXITCODE_QUEUE_FULL);
+    }
     if(m.type != NEWJOB_OK)
         error("Error getting the newjob_ok");
 
--- a/error.c	Tue Jul 26 22:36:23 2011 +0200
+++ b/error.c	Thu Jul 28 19:43:01 2011 +0200
@@ -90,6 +90,7 @@
 
 static void print_error(FILE *out, enum Etype type, const char *str, va_list ap)
 {
+    fprintf(out, "-------------------");
     if (type == ERROR)
         fprintf(out, "Error\n");
     else if (type == WARNING)
@@ -146,6 +147,12 @@
 
     real_errno = errno;
 
+    if (process_type == CLIENT)
+    {
+        vfprintf(stderr, str, ap);
+        fputc('\n', stderr);
+    }
+
     problem(ERROR, str, ap);
     exit(-1);
 }
--- a/execute.c	Tue Jul 26 22:36:23 2011 +0200
+++ b/execute.c	Thu Jul 28 19:43:01 2011 +0200
@@ -232,8 +232,12 @@
              * works. Thus, command exists, etc. */
             fprintf(stderr, "ts could not run the command\n");
             exit(-1);
+            /* To avoid a compiler warning */
+            errorlevel = 0;
             break;
         case -1:
+            /* To avoid a compiler warning */
+            errorlevel = 0;
             error("forking");
         default:
             close(p[1]);
--- a/main.c	Tue Jul 26 22:36:23 2011 +0200
+++ b/main.c	Thu Jul 28 19:43:01 2011 +0200
@@ -42,6 +42,7 @@
     command_line.do_depend = 0;
     command_line.depend_on = -1; /* -1 means depend on previous */
     command_line.max_slots = 1;
+    command_line.wait_enqueuing = 1;
 }
 
 void get_command(int index, int argc, char **argv)
@@ -81,7 +82,7 @@
 
     /* Parse options */
     while(1) {
-        c = getopt(argc, argv, ":VhKgClnfmr:t:c:o:p:w:u:s:U:i:L:dS:D:");
+        c = getopt(argc, argv, ":VhKgClnfmBr:t:c:o:p:w:u:s:U:i:L:dS:D:");
 
         if (c == -1)
             break;
@@ -188,6 +189,10 @@
                     exit(-1);
                 }
                 break;
+            case 'B':
+                /* I picked 'B' quite at random among the letters left */
+                command_line.wait_enqueuing = 0;
+                break;
             case ':':
                 switch(optopt)
                 {
--- a/main.h	Tue Jul 26 22:36:23 2011 +0200
+++ b/main.h	Thu Jul 28 19:43:01 2011 +0200
@@ -1,7 +1,7 @@
 enum
 {
     CMD_LEN=500,
-    PROTOCOL_VERSION=623
+    PROTOCOL_VERSION=700
 };
 
 enum msg_types
@@ -34,7 +34,8 @@
     GET_MAX_SLOTS,
     GET_MAX_SLOTS_OK,
     GET_VERSION,
-    VERSION
+    VERSION,
+    NEWJOB_NOK
 };
 
 enum Request
@@ -73,6 +74,7 @@
     int jobid; /* When queuing a job, main.c will fill it automatically from
                   the server answer to NEWJOB */
     int jobid2;
+    int wait_enqueuing;
     struct {
         char **array;
         int num;
@@ -115,6 +117,7 @@
             int env_size;
             int do_depend;
             int depend_on; /* -1 means depend on previous */
+            int wait_enqueuing;
         } newjob;
         struct {
             int ofilename_size;
@@ -173,6 +176,13 @@
     struct Procinfo info;
 };
 
+enum ExitCodes
+{
+    EXITCODE_OK            =  0,
+    EXITCODE_UNKNOWN_ERROR = -1,
+    EXITCODE_QUEUE_FULL    = 2
+};
+
 
 /* client.c */
 void c_new_job();
--- a/server.c	Tue Jul 26 22:36:23 2011 +0200
+++ b/server.c	Thu Jul 28 19:43:01 2011 +0200
@@ -43,6 +43,7 @@
     client_read(int index);
 static void end_server(int ls);
 static void s_newjob_ok(int index);
+static void s_newjob_nok(int index);
 static void s_runjob(int jobid, int index);
 static void clean_after_client_disappeared(int socket, int index);
 
@@ -386,6 +387,11 @@
             client_cs[index].hasjob = 1;
             if (!job_is_holding_client(client_cs[index].jobid))
                 s_newjob_ok(index);
+            else if (!m.u.newjob.wait_enqueuing)
+            {
+                s_newjob_nok(index);
+                clean_after_client_disappeared(s, index);
+            }
             break;
         case RUNJOB_OK:
             {
@@ -517,6 +523,21 @@
     send_msg(s, &m);
 }
 
+static void s_newjob_nok(int index)
+{
+    int s;
+    struct msg m;
+    
+    if (!client_cs[index].hasjob)
+        error("Run job of the client %i which doesn't have any job", index);
+
+    s = client_cs[index].socket;
+
+    m.type = NEWJOB_NOK;
+
+    send_msg(s, &m);
+}
+
 static void dump_conn_struct(FILE *out, const struct Client_conn *p)
 {
     fprintf(out, "  new_conn\n");