I followed what was said in a different thread.
I have used execve() with an environment variable PATH, set it to /bin, in order to be able to call commands without using the absolute path. But the function execve() still doesn't recognize the commands such as ls. Only /bin/ls works.
What could be the issue?
char *envList[3] = {"HOME=/root", "PATH=/bin", NULL };
execve(command[0], command, envList);
That's not how the
execvesyscall works. It will never look atPATHor any other environment variables to search for the executable to execute. You will have to provide a valid absolute or relative path.Furthermore, setting the environment only affects the new program that is executed, not the current one. So even using the
execvpe()library function that emulates the path resolution of a shell looking atPATH, it will look at the current value of the environment variablePATH, not the one being passed as environment to the new process.