- forkchild(argv[1], file, argv[2], argv[3], argv[4], &in, &out);
- ins = fdopen(in, "w");
- passdata(stdin, ins);
- fclose(ins);
- outs = fdopen(out, "r");
- if((headers = parseheaders(outs)) == NULL) {
+
+ if(cd) {
+ /* This behavior is encouraged by the CGI specification (RFC 3875, 7.2),
+ * but not strictly required, and I get the feeling it might break some
+ * relative paths here or there, so it's not the default for now. */
+ if((sp = strrchr(file, '/')) != NULL) {
+ *sp = 0;
+ if(chdir(file)) {
+ *sp = '/';
+ } else {
+ file = sp + 1;
+ }
+ }
+ }
+
+ if(prog == NULL)
+ prog = file;
+ child = forkchild(inpath, prog, file, argv[optind], argv[optind + 1], argv[optind + 2], &infd, &outfd);
+ in = fdopen(infd, "w");
+ passdata(stdin, in); /* Ignore errors, perhaps? */
+ fclose(in);
+ out = fdopen(outfd, "r");
+ if((headers = parsecgiheaders(out)) == NULL) {