mirror of
https://github.com/Leonmmcoset/cleonos.git
synced 2026-04-24 11:14:01 +00:00
ABI
This commit is contained in:
@@ -1,9 +1,28 @@
|
||||
#include "cmd_runtime.h"
|
||||
static int ush_cmd_exec(const ush_state *sh, const char *arg) {
|
||||
char target[USH_PATH_MAX];
|
||||
char argv_line[USH_ARG_MAX];
|
||||
char env_line[USH_PATH_MAX + 32ULL];
|
||||
const char *rest = "";
|
||||
char path[USH_PATH_MAX];
|
||||
u64 status;
|
||||
|
||||
if (ush_resolve_exec_path(sh, arg, path, (u64)sizeof(path)) == 0) {
|
||||
if (sh == (const ush_state *)0 || arg == (const char *)0 || arg[0] == '\0') {
|
||||
ush_writeln("exec: usage exec <path|name> [args...]");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ush_split_first_and_rest(arg, target, (u64)sizeof(target), &rest) == 0) {
|
||||
ush_writeln("exec: usage exec <path|name> [args...]");
|
||||
return 0;
|
||||
}
|
||||
|
||||
argv_line[0] = '\0';
|
||||
if (rest != (const char *)0 && rest[0] != '\0') {
|
||||
ush_copy(argv_line, (u64)sizeof(argv_line), rest);
|
||||
}
|
||||
|
||||
if (ush_resolve_exec_path(sh, target, path, (u64)sizeof(path)) == 0) {
|
||||
ush_writeln("exec: invalid target");
|
||||
return 0;
|
||||
}
|
||||
@@ -13,7 +32,11 @@ static int ush_cmd_exec(const ush_state *sh, const char *arg) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
status = cleonos_sys_exec_path(path);
|
||||
env_line[0] = '\0';
|
||||
ush_copy(env_line, (u64)sizeof(env_line), "PWD=");
|
||||
ush_copy(env_line + 4, (u64)(sizeof(env_line) - 4ULL), sh->cwd);
|
||||
|
||||
status = cleonos_sys_exec_pathv(path, argv_line, env_line);
|
||||
|
||||
if (status == (u64)-1) {
|
||||
ush_writeln("exec: request failed");
|
||||
@@ -25,7 +48,16 @@ static int ush_cmd_exec(const ush_state *sh, const char *arg) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
ush_writeln("exec: returned non-zero status");
|
||||
if ((status & (1ULL << 63)) != 0ULL) {
|
||||
ush_writeln("exec: terminated by signal");
|
||||
ush_print_kv_hex(" SIGNAL", status & 0xFFULL);
|
||||
ush_print_kv_hex(" VECTOR", (status >> 8) & 0xFFULL);
|
||||
ush_print_kv_hex(" ERROR", (status >> 16) & 0xFFFFULL);
|
||||
} else {
|
||||
ush_writeln("exec: returned non-zero status");
|
||||
ush_print_kv_hex(" STATUS", status);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user