Calling exec returns errno 14 (bad address) with absolute path

前端 未结 3 1867
暖寄归人
暖寄归人 2021-01-12 16:08

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

相关标签:
3条回答
  • 2021-01-12 16:45

    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.)

    0 讨论(0)
  • 2021-01-12 16:46
        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.

    0 讨论(0)
  • 2021-01-12 16:58
    execl("simple.cgi","simple", NULL);
    

    The null is needed because execl() is a varargs - function.

    0 讨论(0)
提交回复
热议问题