when creating a simple cgi server for the course. To do this, at some point I have to do fork / exec to start the cgi handler, the problem is that exec continues to return errno 14. I tried the following code in the standalone version, and it works with the absolute track.
Here is the code:
static void _process_cgi(int fd, http_context_t* ctx) { pid_t childProcess; int ret; char returnValue[1024]; log(LOG, "calling cgi", &ctx->uri[1], 0); if((childProcess = fork()) != 0) { /// /// Set the CGI standard output to the socket. /// dup2(fd, STANDARD_OUTPUT); //ctx->uri = "/simple.cgi" execl("/home/dvd/nwebdir/simple.cgi",&ctx->uri[1]); sprintf(returnValue,"%d",errno); log(LOG, "exec returned ", returnValue, 0); return -1; } ret = waitpid(childProcess,NULL,0); sprintf(returnValue,"%d",ret); log(LOG, "cgi returned", returnValue, 0); }
Here is a list of sys calls that the server passes before it reaches my code (in order): - chdir - plug - setpqrp - plug I don't know if this is relevant or not, but in my test program I don't have chdir or setpqrp.
Security Code:
pid_t pid; if ((pid = fork()) != 0) { execl("simple.cgi","simple"); //execl("/home/dvd/nwebdir/simple.cgi","simple"); return 0; } printf("waiting\n"); waitpid(pid, NULL, 0); printf("Parent exiting\n");
Note. I tried both execl and execlp in server code.
Here you can find the basic server implementation (without CGI), the only changes I made were in the web function: http://www.ibm.com/developerworks/systems/library/es-nweb/index.html
Hi