geomyidae

A small C-based gopherd. (gopher://bitreich.org/1/scm/geomyidae)
git clone git://r-36.net/geomyidae
Log | Files | Refs | README | LICENSE

commit 8df91710dfdf1f9091be9ed40a259933c7b62951
parent bb858e05c4c1e15bd54b5bcb37ebac0f9356af47
Author: Christoph Lohmann <20h@r-36.net>
Date:   Wed, 16 Mar 2011 06:37:10 +0100

Now scripts are run in their directory.

Diffstat:
Mhandlr.c | 15++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/handlr.c b/handlr.c @@ -194,7 +194,7 @@ void handledcgi(int sock, char *file, char *port, char *base, char *args, char *sear) { - char *p, *ln, addr[512]; + char *p, *path, *ln, addr[512]; int outpipe[2]; Elems *el; @@ -203,6 +203,15 @@ handledcgi(int sock, char *file, char *port, char *base, char *args, if(pipe(outpipe) < 0) return; + path = gstrdup(file); + p = strrchr(path, '/'); + if (p != nil) + p[1] = '\0'; + else { + free(path); + path = nil; + } + p = strrchr(file, '/'); if(p == nil) p = file; @@ -224,6 +233,8 @@ handledcgi(int sock, char *file, char *port, char *base, char *args, case 0: dup2(outpipe[1], 1); close(outpipe[0]); + if (path != nil) + chdir(path); execl(file, p, sear, args, (char *)nil); case -1: break; @@ -242,6 +253,8 @@ handledcgi(int sock, char *file, char *port, char *base, char *args, tprintf(sock, "\r\n.\r\n\r\n"); wait(NULL); + if (path != nil) + free(path); shutdown(sock, SHUT_RDWR); close(sock); break;