chiark / gitweb /
cgi-fcgi-interp: Provide -E option.
[chiark-utils.git] / cprogs / cgi-fcgi-interp.c
index 65532e677da1d67368d58680a26ce70719a69da3..6b0585b54f4a9b46e0464d80458c28f4f88b28c7 100644 (file)
  *          The real interpreter to use.  Eg "perl".  Need not
  *          be an absolute path; will be fed to execvp.
  *
+ *  -G<ident-info>
+ *          Add <ident-info> to the unique identifying information for
+ *          this fcgi program.  May be repeated; order is significant.
+ *
+ *  -E<ident-info-env-var>
+ *          Look <ident-info-env-var> up in the environment and add
+ *          <ident-info-env-var>=<value> as if specified with -G.  If
+ *          the variable is unset in the environment, it is as if
+ *          -G<ident-info-env-var> was specified.
+ *
  *  -g<ident>
  *          Use <ident> rather than hex(sha256(<interp>\0<script>\0))
  *          as the basename of the leafname of the fcgi rendezvous
@@ -185,11 +195,24 @@ static void ident_addstring(const struct cmdinfo *ci, const char *string) {
   sha256_update(&identsc,strlen(string)+1,string);
 }
 
+static void off_ident_addenv(const struct cmdinfo *ci, const char *name) {
+  const char *val = getenv(name);
+  if (val) {
+    sha256_update(&identsc,strlen(name),name); /* no nul */
+    sha256_update(&identsc,1,"=");
+    ident_addstring(0,val);
+  } else {
+    ident_addstring(0,name);
+  }
+}
+
 #define MAX_OPTS 5
 
 static const struct cmdinfo cmdinfos[]= {
   { "help",   0, .call=of_help                                         },
   { 0, 'g',   1,                    .sassignto= &ident                 },
+  { 0, 'G',   1, .call= ident_addstring                                },
+  { 0, 'E',   1, .call= off_ident_addenv                               },
   { 0, 'M',   1, .call=of_iassign,  .iassignto= &numservers            },
   { 0, 'D',   0,                    .iassignto= &debugmode,    .arg= 1 },
   { 0, 'c',   1, .call=of_iassign,  .iassignto= &check_interval        },