not enough variables to fit a sentinel
According to exec reference, calls to exec (or stack checking vararg functions in general) requires a (char*)NULL
aka 0 at the end of the parameter list. GCC, however, is complaining about the following code
char cmdFullPath[4096]; //yes this 4096 thing is bad coding practice
...
execl(cmdFullPath, (char*)NULL);
//warni开发者_JAVA百科ng: not enough variable arguments to fit a sentinel
Anyone know what's wrong?
That reference says that the prototype is
execl(const char * path, const char * arg, ...)
I read that as 2 parameters + (char*)NULL
something like :
execl(cmdFullPath, (const char*)NULL, (char*)NULL);
from the page:
#include <unistd.h>
int main() {
execl("/bin/ls", "ls", "-l", (char *)NULL);
return 0;
}
Its usual to pass the executable name in as the first parameter
So if the executable you are executing is "/bin/ls" (as per the link you posted) then the first parameter is "ls" and you'd THEN pass (char*)NULL in as the last (ie in this case 3rd) parameter.
You have to pass at least three arguments. The second one is argv[0] so it cannot be null.
execl(cmdFullPath, "", NULL)
精彩评论