chiark / gitweb /
cgi-fcgi-interp: Add -D
[chiark-utils.git] / cprogs / cgi-fcgi-interp.c
index 1e368f08fe5c89a47264e8c4d708a09b39e57ccf..0fdb88ee4e449ccc53548929ea5c282ee964705c 100644 (file)
  *         speedy, the specified number of servers is started
  *         right away.)  The default is 4.
  *
+ *  -D
+ *         Debug mode.  Do not actually run program.  Instead, print
+ *         out what we would do.
+ *
  * <options> and <interpreter> can be put into a single argument
  * to cgi-fcgi-interp, separated by spaces or commas.  <interpreter>
  * must come last.
@@ -76,6 +80,7 @@
 #include <errno.h>
 #include <stdbool.h>
 #include <assert.h>
+#include <limits.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #define MINHEXHASH 33
 
 static const char *interp, *ident;
-static int numservers;
+static int numservers, debugmode;
 
 void diee(const char *m) {
   err(127, "error: %s failed", m);
@@ -114,12 +119,22 @@ 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, 'D',   0, .iassignto= &debugmode, .arg= 1 },
   { 0 }
 };
 
@@ -296,9 +311,11 @@ int main(int argc, const char *const *argv) {
 
   check_garbage();
 
-  printf("socket: %s\n",socket_path);
-  printf("interp: %s\n",interp);
-  printf("command: %s\n",command);
+  if (debugmode) {
+    printf("socket: %s\n",socket_path);
+    printf("interp: %s\n",interp);
+    printf("command: %s\n",command);
+  }
 
   exit(0);
 }