chiark / gitweb /
cgi-fcgi-perl: skeleton, compiles
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 21 Mar 2016 11:51:48 +0000 (11:51 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 21 Mar 2016 11:51:48 +0000 (11:51 +0000)
.gitignore
cprogs/Makefile
cprogs/cgi-fcgi-perl.c

index 6fdcfb8..b08c589 100644 (file)
@@ -16,6 +16,7 @@ cprogs/watershed
 cprogs/watershed.txt
 cprogs/rcopy-repeatedly
 cprogs/acctdump
+cprogs/cgi-fcgi-perl
 
 debian/tmp
 debian/sv-*
index cd82ab1..77e14e2 100644 (file)
@@ -28,7 +28,8 @@ include ../settings.make
 RWBUFFER_SIZE_MB=16
 
 PROGRAMS=              readbuffer writebuffer with-lock-ex xbatmon-simple \
-                       summer watershed rcopy-repeatedly xduplic-copier
+                       summer watershed rcopy-repeatedly xduplic-copier \
+                       cgi-fcgi-perl
 SUIDSBINPROGRAMS=      really
 DAEMONS=               trivsoundd
 MAN1PAGES=             readbuffer.1 writebuffer.1 with-lock-ex.1 \
@@ -57,6 +58,7 @@ writebuffer:                  writebuffer.o   wrbufcore.o     rwbuffer.o
 trivsoundd:                    trivsoundd.o    wrbufcore.o     rwbuffer.o 
 really:                                really.o myopt.o
 acctdump:                      acctdump.o      myopt.o
+cgi-fcgi-perl:                 cgi-fcgi-perl.o myopt.o
 
 acctdump.o really.o myopt.o rcopy-repeatedly.o: myopt.h
 readbuffer.o writebuffer.o rwbuffer.o wrbufcore.o trivsoundd.o:        rwbuffer.h
index 62c5831..037bd86 100644 (file)
@@ -8,7 +8,7 @@
  *
  * Options:
  *
- *  -M<ident>
+ *  -g<ident>
  *          Use <ident> rather than hex(sha256(<script>))
  *          as the basename of the leafname of the fcgi rendezvous
  *          socket.  If <ident> contains only hex digit characters it
  *  - run  cgi-fcgi -connect SOCKET SCRIPT
  */
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "myopt.h"
+
+static const char *ident;
+static int numservers;
+
+static void diee(const char *m) {
+  fprintf(stderr,"cgi-fcgi-: error: %s failed: %s\n", m, strerror(errno));
+  exit(127);
+}
+
+static void fusagemessage(FILE *f) {
+  fprintf(f, "usage: #!/usr/bin/cgi-fcgi-perl [<options>]\n");
+}
+
+void usagemessage(void) { fusagemessage(stderr); }
+
+static void of_help(const struct cmdinfo *ci, const char *val) {
+  fusagemessage(stdout);
+  if (ferror(stdout)) diee("write usage message to stdout");
+  exit(0);
+}
+
+static const struct cmdinfo cmdinfos[]= {
+  { "help",   0, .call= of_help               },
+  { 0, 'g',   1, .sassignto= &ident           },
+  { 0, 'M',   1, .iassignto= &numservers      },
+  { 0 }
+};
+
+int main(int argc, const char *const *argv) {
+  myopt(&argv, cmdinfos);
+  exit(0);
+}