* be an absolute path; will be fed to execvp.
*
* -g<ident>
- * Use <ident> rather than hex(sha256(<script>))
+ * Use <ident> rather than hex(sha256(<interp>\0<script>\0))
* as the basename of the leafname of the fcgi rendezvous
* socket. If <ident> contains only hex digit characters it
* ought to be no more than 32 characters. <ident> should
* s<ident>
* l<ident> used to lock around garbage collection
*
- * If -M<ident> is not specified then an initial substricg of the
- * lowercase hex of the sha256 of the <script> (ie, our argv[1]) is
+ * If -M<ident> is not specified then an initial substring of the
+ * lowercase hex of the sha256 of <interp>\0<script>\0 is
* used. The substring is chosen so that the whole path is 10 bytes
* shorter than sizeof(sun_path). But always at least 33 characters.
*
static int numservers=4, debugmode;
static int check_interval=300;
+static struct sha256_ctx identsc;
+
const char *stage2;
void diee(const char *m) {
*ci->iassignto = v;
}
+static void ident_addstring(const struct cmdinfo *ci, const char *string) {
+ /* ci may be 0 and is provided so this can be .call */
+ sha256_update(&identsc,strlen(string)+1,string);
+}
+
#define MAX_OPTS 5
static const struct cmdinfo cmdinfos[]= {
- { "help", 0, .call= of_help },
- { 0, 'g', 1, .sassignto= &ident },
- { 0, 'M', 1, .call=of_iassign, .iassignto= &numservers },
- { 0, 'D', 0, .iassignto= &debugmode, .arg= 1 },
- { 0, 'c', 1, .call=of_iassign, .iassignto= &check_interval },
+ { "help", 0, .call=of_help },
+ { 0, 'g', 1, .sassignto= &ident },
+ { 0, 'M', 1, .call=of_iassign, .iassignto= &numservers },
+ { 0, 'D', 0, .iassignto= &debugmode, .arg= 1 },
+ { 0, 'c', 1, .call=of_iassign, .iassignto= &check_interval },
{ 0 }
};
int identlen = maxidentlen > 64 ? 64 : maxidentlen;
char *hexident = xmalloc(identlen + 2);
- struct sha256_ctx sc;
unsigned char bbuf[32];
int i;
- sha256_init(&sc);
- sha256_update(&sc,strlen(interp)+1,interp);
- sha256_update(&sc,strlen(script)+1,script);
- sha256_digest(&sc,sizeof(bbuf),bbuf);
+ ident_addstring(0,interp);
+ ident_addstring(0,script);
+ sha256_digest(&identsc,sizeof(bbuf),bbuf);
for (i=0; i<identlen; i += 2)
sprintf(hexident+i, "%02x", bbuf[i/2]);
else if (r!=1) errx(127,"open /dev/null for stdout gave bad fd %d",r);
}
+ sha256_init(&identsc);
+
if (argc>=2 &&
(smashedopt = argv[1]) &&
smashedopt[0]=='-' &&