The call to exec returns errno 14 (wrong address) with an absolute path

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

+4
source share
3 answers
 execl("simple.cgi","simple", NULL); 

Zero is necessary because execl () is a varargs function.

+13
source
  execl("/home/dvd/nwebdir/simple.cgi", &ctx->uri[1], (char *)0); 

The final argument to execl() must be null char * . You can usually get away with writing NULL instead of (char *)0 , but this can lead to an incorrect result if you have #define NULL 0 and you are on a machine where sizeof(int) != sizeof(char *) , for example, a 64-bit system.

+4
source

By the way, either you copied the code incorrectly, or you had a logical error. Fork () returns a non-zero parent process, not a child, so the condition must be canceled. (There is no comment button here, so give an answer.)

+2
source

Source: https://habr.com/ru/post/1403261/


All Articles