chiark / gitweb /
cgi-fcgi-interp: fix -M to actually work
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 22 Mar 2016 14:23:41 +0000 (14:23 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 22 Mar 2016 14:23:41 +0000 (14:23 +0000)
cprogs/cgi-fcgi-interp.c

index 1e368f08fe5c89a47264e8c4d708a09b39e57ccf..9ebad2bd83c5c376e350d27a2e461b4a44f0f707 100644 (file)
@@ -76,6 +76,7 @@
 #include <errno.h>
 #include <stdbool.h>
 #include <assert.h>
+#include <limits.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -114,12 +115,21 @@ static void of_help(const struct cmdinfo *ci, const char *val) {
   exit(0);
 }
 
+static void of_iassign(const struct cmdinfo *ci, const char *val) {
+  long v;
+  char *ep;
+  errno= 0; v= strtol(val,&ep,10);
+  if (!*val || *ep || errno || v<INT_MIN || v>INT_MAX)
+    badusage("bad integer argument `%s' for --%s",val,ci->olong);
+  *ci->iassignto = v;
+}
+
 #define MAX_OPTS 5
 
 static const struct cmdinfo cmdinfos[]= {
   { "help",   0, .call= of_help               },
   { 0, 'g',   1, .sassignto= &ident           },
-  { 0, 'M',   1, .iassignto= &numservers      },
+  { 0, 'M',   1, .call=of_iassign, .iassignto= &numservers      },
   { 0 }
 };