diff options
author | midipix <writeonce@midipix.org> | 2018-05-23 03:40:20 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2018-05-22 23:49:18 -0400 |
commit | 5ec9b67e061e7bf839d6ae986354190d2e1e0037 (patch) | |
tree | 3f79cfd3ed355d2f5198e323d74d5ac270651dc6 /src/cmds | |
parent | 105c6c4b81ce64192e304827942a9aa65c8dd059 (diff) | |
download | ntux-5ec9b67e061e7bf839d6ae986354190d2e1e0037.tar.bz2 ntux-5ec9b67e061e7bf839d6ae986354190d2e1e0037.tar.xz |
ntux_cmd_spawn(): initial implementation and integration.
Diffstat (limited to 'src/cmds')
-rw-r--r-- | src/cmds/ntux_cmd_spawn.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/cmds/ntux_cmd_spawn.c b/src/cmds/ntux_cmd_spawn.c new file mode 100644 index 0000000..cb88696 --- /dev/null +++ b/src/cmds/ntux_cmd_spawn.c @@ -0,0 +1,54 @@ +/***********************************************************/ +/* ntux: native translation und extension */ +/* Copyright (C) 2016--2018 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTUX. */ +/***********************************************************/ + +#include <ntapi/ntapi.h> +#include <psxabi/sys_sysapi.h> +#include <psxabi/sys_errno.h> + +#include <ntux/ntux.h> +#include "ntux_driver_impl.h" +#include "ntux_nolibc_impl.h" +#include "ntux_errinfo_impl.h" + +int ntux_cmd_spawn(const struct ntux_driver_ctx * dctx) +{ + int32_t status; + pid_t pid; + const char ** argv; + const char ** envp; + unsigned char * program; + + /* init */ + ntux_driver_set_ectx( + dctx,0, + dctx->cctx->sargv[0]); + + argv = (const char **)dctx->cctx->sargv; + envp = (const char **)dctx->cctx->senvp; + program = (unsigned char *)dctx->cctx->sargv[0]; + + /* spawn */ + pid = __sys_vfork(); + + /* failed? */ + if (pid < 0) + if (ntux_errno_set(dctx,pid)) + return NTUX_SYSTEM_ERROR(dctx); + + /* child */ + if (pid == 0) + if ((status = __sys_execve(program,argv,envp))) + if (ntux_errno_set(dctx,status)) + if (NTUX_SYSTEM_ERROR(dctx)) + __sys_exit(0); + + /* parent */ + __sys_wait4( + pid,&status, + 0,0); + + return 0; +} |