Hello Daniweb,
I'm trying to create a very simple shell for practicing purposes, but i'm a little bit puzzeled about the usage of execve, the function i use to execute a file.
The code fragment underneath shows my usage:
childPID = vfork();
if (childPID == 0)
{
execve(input.process, input.parameters, environ);
printf("[!] %s.\n", strerror(errno));
_exit(0);
}
else
{
waitpid(childPID, NULL, 0);
}
In this example I have the parameters used use the following (strings are NULL terminated):
input.process: "ls"
input.parameters: NULL pointer.
environ: A variable defined in unistd.h with the current environment settings.
When I execute the application like this i get the following:
[!] No such file or directory.
So i decided to investigate the environment variable. One of the data contained in it is:
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/MyUsername/bin
So one of the path paths in the path variable is "/bin" so I don't quite understand why "ls" doesn't work.
So then I tried the input "/bin/ls" instead of just "ls" and then the program does seem to work. So my question is: Why can't I provide a relative path when bin directories are specified in the PATH variable of the environment?