in making a simple cgi server for a course. To do that in some point I have to make a fork/exec to launch the cgi handler, the problem is that the exec keep returning errno
BTW, either you copied the code incorrectly or it has logic error. Fork() returns non-zero to parent process, not child one, so condition shall be reverted. (There is no comment button here so making answer.)
execl("/home/dvd/nwebdir/simple.cgi", &ctx->uri[1], (char *)0);
The last argument to execl()
must be a null char *
. You can usually get away with writing NULL
instead of (char *)0
, but it might not produce the correct result if you have #define NULL 0
and you are on a machine where sizeof(int) != sizeof(char *)
, such as a 64-bit system.
execl("simple.cgi","simple", NULL);
The null is needed because execl() is a varargs - function.