sh: Try to execute programs in /bin if they are not found
This commit is contained in:
parent
a06e1c5a21
commit
bd4c587409
@ -1,3 +1,4 @@
|
||||
#include <errno.h>
|
||||
#include <luna.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -104,7 +105,18 @@ void command_execute(command* cmd)
|
||||
}
|
||||
if (child == 0)
|
||||
{
|
||||
execv(cmd->buffer, NULL);
|
||||
if (cmd->buffer[0] != '/' && access(cmd->buffer, F_OK) < 0) // FIXME: Race condition.
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
{ // Try in /bin
|
||||
char* buf = malloc(cmd->size + 6);
|
||||
strlcpy(buf, "/bin/", 6);
|
||||
strncat(buf, cmd->buffer, cmd->size);
|
||||
execv(buf, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
execv(cmd->buffer, NULL);
|
||||
perror(cmd->buffer);
|
||||
exit(127);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user