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 <luna.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -104,6 +105,17 @@ void command_execute(command* cmd)
|
|||||||
}
|
}
|
||||||
if (child == 0)
|
if (child == 0)
|
||||||
{
|
{
|
||||||
|
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);
|
execv(cmd->buffer, NULL);
|
||||||
perror(cmd->buffer);
|
perror(cmd->buffer);
|
||||||
exit(127);
|
exit(127);
|
||||||
|
Loading…
Reference in New Issue
Block a user