diff options
author | Ian Moffett <ian@osmora.org> | 2025-06-29 20:56:40 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-06-29 20:56:40 -0400 |
commit | 655c43f4b8a2d42b2f7b9c85b8ad6d8de6e6a284 (patch) | |
tree | 5d85a0bf258aa9a0dffb3f95e986b09c62cde7e6 /usr.bin/osh/osh.c | |
parent | 08dc44c415c63abd71524468afe26b42f2e23b69 (diff) |
usr.bin: osh: Allow execution of direct paths
This commit allows the end-user to supply a path (e.g., /usr/bin/mrow)
straight to the shell to be interpreted as a binary executable path.
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'usr.bin/osh/osh.c')
-rw-r--r-- | usr.bin/osh/osh.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c index 0cac664..dd92378 100644 --- a/usr.bin/osh/osh.c +++ b/usr.bin/osh/osh.c @@ -256,6 +256,25 @@ cmd_run(const char *input, int argc, char *argv[], bool wait) char *envp[1] = { NULL }; int error, spawn_flags = 0; + /* Should we wait or daemonize? */ + if (wait) { + spawn_flags |= SPAWN_WAIT; + } + + /* + * If we can access the raw input as a file, try to + * spawn it as a program. This case would run if for + * example, the user entered /usr/sbin/foo, or some + * path directly into the console. + */ + if (access(input, F_OK) == 0) { + error = spawn(input, argv, envp, spawn_flags); + if (error < 0) { + return error; + } + return 0; + } + snprintf(bin_path, sizeof(bin_path), "/usr/bin/%s", input); /* See if we can access it */ @@ -263,11 +282,6 @@ cmd_run(const char *input, int argc, char *argv[], bool wait) return -1; } - /* Should we wait or daemonize? */ - if (wait) { - spawn_flags |= SPAWN_WAIT; - } - if ((error = spawn(bin_path, argv, envp, spawn_flags)) < 0) { return error; } |