On Fri, Mar 07, 2014 at 11:20:53PM +0000, Stuart Henderson wrote:
> I've been umming and ahhing about this diff, the thing I don't like is
> that SCRIPT_FILENAME is an Apache extension rather than part of the
> standard CGI variables, which explains why it's not included by
> default in nginx (or other servers that people might conceivably
> want to use with slowcgi, such as lighttpd).
>
> Still, I don't see a better way to handle this, and replacing Apache
> is going to need to support cgis outside of /cgi-bin one way or another.
> But I do think it should fallback to using SCRIPT_NAME if the
> SCRIPT_FILENAME variable isn't present, so that standard fastcgi
> servers can use it to some extent too.
>
Maybe something like this? Using SCRIPT_FILENAME if present but falling
back on SCRIPT_NAME.
--
James Turner
Index: slowcgi.c
===================================================================
RCS file: /cvs/src/usr.sbin/slowcgi/slowcgi.c,v
retrieving revision 1.27
diff -u -p -u -p -r1.27 slowcgi.c
--- slowcgi.c 19 Jan 2014 00:01:05 -0000 1.27
+++ slowcgi.c 8 Mar 2014 03:33:30 -0000
@@ -119,6 +119,7 @@ struct request {
struct fcgi_stdin_head stdin_head;
uint16_t id;
char script_name[MAXPATHLEN];
+ char script_filename[MAXPATHLEN];
struct env_head env;
int env_count;
pid_t script_pid;
@@ -524,7 +525,7 @@ slowcgi_sig_handler(int sig, short event
create_end_record(c);
c->script_flags |= SCRIPT_DONE;
- ldebug("wait: %s", c->script_name);
+ ldebug("wait: %s", (strlen(c->script_filename) == 0) ?
c->script_name : c->script_filename);
}
if (pid == -1 && errno != ECHILD)
lwarn("waitpid");
@@ -745,6 +746,11 @@ parse_params(uint8_t *buf, uint16_t n, s
bcopy(buf, c->script_name, val_len);
c->script_name[val_len] = '\0';
}
+ if (val_len < MAXPATHLEN && strcmp(env_entry->val,
+ "SCRIPT_FILENAME") == 0) {
+ bcopy(buf, c->script_filename, val_len);
+ c->script_filename[val_len] = '\0';
+ }
env_entry->val[name_len] = '=';
bcopy(buf, (env_entry->val) + name_len + 1, val_len);
@@ -848,7 +854,7 @@ exec_cgi(struct request *c)
lerr(1, "socketpair");
cgi_inflight--;
c->inflight_fds_accounted = 1;
- ldebug("fork: %s", c->script_name);
+ ldebug("fork: %s", (strlen(c->script_filename) == 0) ? c->script_name :
c->script_filename);
switch (pid = fork()) {
case -1:
@@ -887,15 +893,15 @@ exec_cgi(struct request *c)
close(s_out[1]);
close(s_err[1]);
- argv[0] = c->script_name;
+ argv[0] = (strlen(c->script_filename) == 0) ? c->script_name :
c->script_filename;
argv[1] = NULL;
if ((env = calloc(c->env_count + 1, sizeof(char*))) == NULL)
_exit(1);
SLIST_FOREACH(env_entry, &c->env, entry)
env[i++] = env_entry->val;
env[i++] = NULL;
- execve(c->script_name, argv, env);
- lwarn("execve %s", c->script_name);
+ execve((strlen(c->script_filename) == 0) ? c->script_name :
c->script_filename, argv, env);
+ lwarn("execve %s", (strlen(c->script_filename) == 0) ?
c->script_name : c->script_filename);
_exit(1);
}