chiark / gitweb /
watershed, common: Break out m_[v]asprintf into common.c (nfc0
[chiark-utils.git] / cprogs / cgi-fcgi-perl.c
index 62c5831f7a2e9d00f6e218252c997270f3131f91..037bd8644e271675b6817b019c7af4d23cc97dac 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);
+}