I'm working on a multi-threaded proxy server and I keep getting a permission denied error when I call execl as follows:

execl(CHILD_PATH, CMD, (char*)rdy, (char*)NULL);

I define the path and program name at the beginning of my program as follows:

#define CHILD_PATH "./"
#define CMD "child"

rdy is an arguments and I terminate it with (char*)NULL. I've been trying to figure out what's wrong for close to 2 hours now and it's driving me crazy. Does anyone have any ides as to what is going wrong here?

11-03-2009

nadroj

Quote:

Originally Posted by http://linux.die.net/man/3/execl

The initial argument for these functions is the pathname of a file which is to be executed.

Your passing "./" which isnt a file, the first argument should be "./child", the file to execute.

Your remaining arguments should be fine. Note that you do keep the second argument as "CMD", even though you already specified the path and this file as the first argument. I.e.

Code:

execl("./child", "child", "my arguments", (char*)NULL);

If you still get permission denied errors, make sure the file your trying to execute can be executed, i.e. has execute permission.

11-03-2009

NLFortier

Thanks for the advice but I still seem to be getting an error. I changed my definitions as you recommended but now it's giving me a "bad address" error.

Can you verify that typing exactly "/mnt/hdb2/Dev-Cpp/proxy/main" (of course without quotes) at the command-line works fine with no error messages (such as the ones you are seeing when you exec)? If it works fine, can you post your (minimized) code? Basically, a small file with just the "main" function, which declares/assigns any variables needed for the call, as well as the one "execl" line of code. This will help to partition the problem (i.e. your code, vs. the file your trying to exec).