processctl() PCTL_SPAWN cmd, scheduler embryo state, redirected pipes
This commit is contained in:
@ -5,13 +5,19 @@
|
||||
#include "errors.h"
|
||||
#include "util/util.h"
|
||||
#include "sysdefs/processctl.h"
|
||||
#include "vfs/vfs.h"
|
||||
#include "path/path.h"
|
||||
#include "kprintf.h"
|
||||
|
||||
int32_t SYSCALL3(sys_processctl, pid1, cmd1, optsptr1) {
|
||||
#define PCTL_MP_MAX 0xff
|
||||
#define PCTL_PATH_MAX VFS_PATH_MAX
|
||||
|
||||
int32_t SYSCALL3(sys_processctl, pid1, cmd1, arg1) {
|
||||
uint64_t pid = pid1;
|
||||
uint64_t cmd = cmd1;
|
||||
int32_t ret = E_OK;
|
||||
|
||||
if (pid == -1) {
|
||||
if (pid == (uint64_t)-1) {
|
||||
pid = PROCS.current->pid;
|
||||
}
|
||||
|
||||
@ -21,6 +27,10 @@ int32_t SYSCALL3(sys_processctl, pid1, cmd1, optsptr1) {
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
|
||||
if (proc == NULL) {
|
||||
if (cmd == PCTL_POLLSTATE) {
|
||||
ret = 2;
|
||||
goto done;
|
||||
}
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
@ -30,6 +40,36 @@ int32_t SYSCALL3(sys_processctl, pid1, cmd1, optsptr1) {
|
||||
proc_kill(proc);
|
||||
ret = E_DOSCHEDULING;
|
||||
} break;
|
||||
case PCTL_SPAWN: {
|
||||
const char *opath = (const char *)arg1;
|
||||
|
||||
if (opath == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
|
||||
char mp[PCTL_MP_MAX];
|
||||
char path[PCTL_PATH_MAX];
|
||||
|
||||
path_parse(opath, mp, path);
|
||||
|
||||
Proc *newproc = proc_spawnuser(mp, path);
|
||||
if (newproc == NULL) {
|
||||
ret = E_NOMEMORY;
|
||||
goto done;
|
||||
}
|
||||
proc_register(newproc);
|
||||
ret = newproc->pid;
|
||||
} break;
|
||||
case PCTL_POLLSTATE: {
|
||||
ret = proc->state;
|
||||
} break;
|
||||
case PCTL_RUN: {
|
||||
proc->state = PROC_READY;
|
||||
} break;
|
||||
case PCTL_GETPID: {
|
||||
ret = proc->pid;
|
||||
} break;
|
||||
default: {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
} break;
|
||||
|
Reference in New Issue
Block a user