[distcc] Re: hostspec options syntax

Wayne Davison wayned at users.sourceforge.net
Sat Mar 8 19:59:45 GMT 2003


On Wed, Mar 05, 2003 at 08:07:37PM +1100, Martin Pool wrote:
> Another option would be just to allow random per-host named
> parameters, but I think the number of processes is important enough to
> deserve its own syntax.
> 
>   foohost,n=4
>   foohost,n=4,timeout=30,weight=3.2

I like this idea with the change that the number of slots can be
specified as either an unadorned number (",4") or as a normal option
(",slots=4").  This will allow slashes to be used in the hostspec
(for ssh or whatever else comes along) and makes future options easy.

I'm attaching a patch that parses the options as trailing items (after
any ":PORT" part of the HOST).  This code also parses the "timeout="
option, but the timeout value doesn't currently get stored anywhere.

..wayne..
-------------- next part --------------
Index: src/hosts.c
--- src/hosts.c	25 Feb 2003 00:27:25 -0000	1.28
+++ src/hosts.c	8 Mar 2003 19:59:19 -0000
@@ -157,21 +157,46 @@
     return 0;
 }
 
-static int dcc_parse_multiplier(const char **psrc, struct dcc_hostdef *hostdef)
+static int dcc_parse_options(const char **psrc, struct dcc_hostdef *hostdef)
 {
-    char *mul;
-    const char *token = *psrc;
+    char *opt, *arg;
+    const char *token;
     int ret;
 
-    if ((*psrc)[0] == '/') {
-        (*psrc)++;
-        if ((ret = dcc_dup_part(psrc, &mul, "/: \t\n\f")) != 0)
+    while ((*psrc)[0] == ',') {
+        token = (*psrc)++;
+        if ((ret = dcc_dup_part(psrc, &opt, ", \t\n\f")) != 0)
             return ret;
-        if (!mul || atoi(mul) == 0) {
-            rs_log_error("bad multiplier \"%s\" in host specification", token);
+        if (opt) {
+            if ((arg = strchr(opt, '=')) != NULL)
+                *arg++ = '\0';
+            else if (isdigit(*opt)) {
+                arg = opt;
+                opt = NULL;
+            }
+            else
+                arg = NULL;
+        }
+        else
+            arg = NULL;
+        if (!arg) {
+            rs_log_error("malformed option in host specification: \"%s\"", token);
+            return EXIT_BAD_HOSTSPEC;
+        }
+        if (!opt || strcmp(opt, "slots") == 0) {
+            hostdef->n_slots = atoi(arg);
+            if (hostdef->n_slots <= 0) {
+                rs_log_error("invalid number of slots in host specification: \"%s\"", token);
+                return EXIT_BAD_HOSTSPEC;
+            }
+        }
+        else if (strcmp(opt, "timeout") == 0) {
+            ; /* store timeout value at "arg" somewhere */
+        }
+        else {
+            rs_log_error("unknown option in host specification: \"%s\"", token);
             return EXIT_BAD_HOSTSPEC;
         }
-        hostdef->n_slots = atoi(mul);
     }
     return 0;
 }
@@ -189,7 +214,7 @@
     assert(token[0] == '@');
     token++;
 
-    if ((ret = dcc_dup_part(&token, &hostdef->hostname, "/: \t\n\f")) != 0)
+    if ((ret = dcc_dup_part(&token, &hostdef->hostname, ",: \t\n\f")) != 0)
         return ret;
 
     if (!hostdef->hostname) {
@@ -198,15 +223,15 @@
         return EXIT_BAD_HOSTSPEC;
     }
 
-    if ((ret = dcc_parse_multiplier(&token, hostdef)) != 0)
-        return ret;
-
     if (token[0] == ':') {
         token++;
-        if ((ret = dcc_dup_part(&token, &hostdef->ssh_command, " \t\n\f")) != 0)
+        if ((ret = dcc_dup_part(&token, &hostdef->ssh_command, ", \t\n\f")) != 0)
             return ret;
     }
-    
+
+    if ((ret = dcc_parse_options(&token, hostdef)) != 0)
+        return ret;
+
     hostdef->mode = DCC_MODE_SSH;
     return 0;
 }
@@ -219,7 +244,7 @@
     int ret;
     const char *token = token_start;
     
-    if ((ret = dcc_dup_part(&token, &hostdef->hostname, "/: \t\n\f")) != 0)
+    if ((ret = dcc_dup_part(&token, &hostdef->hostname, ",: \t\n\f")) != 0)
         return ret;
 
     if (!hostdef->hostname) {
@@ -228,14 +253,11 @@
         return EXIT_BAD_HOSTSPEC;
     }
 
-    if ((ret = dcc_parse_multiplier(&token, hostdef)) != 0)
-        return ret;
-
     hostdef->port = dcc_default_port;
     if (token[0] == ':') {
         token++;
 
-        if ((ret = dcc_dup_part(&token, &port_str, " \t\n\f")) != 0)
+        if ((ret = dcc_dup_part(&token, &port_str, ", \t\n\f")) != 0)
             return ret;
         
         if (port_str) {
@@ -248,7 +270,10 @@
             free(port_str);
         }
     }
-        
+
+    if ((ret = dcc_parse_options(&token, hostdef)) != 0)
+        return ret;
+
     hostdef->mode = DCC_MODE_TCP;
     return 0;
 }
@@ -263,7 +288,7 @@
     hostdef->hostname = strdup("localhost");
     hostdef->n_slots = 1;
     
-    return dcc_parse_multiplier(&token, hostdef);
+    return dcc_parse_options(&token, hostdef);
 }
 
 


More information about the distcc mailing list