I'm working on a fastcgi program (actually, a binding to lua), and I'm running into trouble trying to receive data from stdin:
char *s, *l = getenv("CONTENT_LENGTH");
int k = atoi(l);
fprintf(stderr, "Integer conversion successful.");
s = malloc(k);
fgets(s, k, stdin);
I'm pretty damn sure that somewhere in here, fastcgi is crashing; all I do after this is print s to stdout with the appropriate headers (so far, at least).
error.log looks like this:
2009-09-05 23:54:57: (mod_fastcgi.c.2494) unexpected end-of-file (perhaps the fastcgi process died): pid: 523 socket: unix:/var/run/lighttpd/lua-fastcgi.socket-3
2009-09-05 23:54:57: (mod_fastcgi.c.3326) response not received, request sent: 899 on socket: unix:/var/run/lighttpd/lua-fastcgi.socket-3 for /new_test.lua , closing connection
Anyone have any idea what's going wrong?
EDIT: WOW, I'm a moron. malloc(k * sizeof(char)), durr.
Anyone see any other problems with that code?
EDIT2: seeing as it's still not working, I assume there *are* other problems with it. I haven't used C in far too long, obviously.