sh: Try to execute programs in /bin if they are not found

This commit is contained in:
apio 2022-10-20 19:12:17 +02:00
parent a06e1c5a21
commit bd4c587409

View File

@ -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);
}