From 7b38366f956ff97dbe5c6132635764a6ec38542e Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Mon, 4 Nov 2019 17:35:24 +0900 Subject: [PATCH] Implement process_detach() method, to create a new session for a process, i.e. detach it from its parent --- include/corax/ipc.h | 3 +++ kernel/core/posixcall.c | 28 +++++++++++++++++++++++++++- kernel/core/process.c | 14 ++++++++++++++ kernel/include/process.h | 1 + 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/include/corax/ipc.h b/include/corax/ipc.h index 2e916f4..90b911f 100644 --- a/include/corax/ipc.h +++ b/include/corax/ipc.h @@ -15,4 +15,7 @@ struct cxmsg { #define cm_data CM_dat.CM_data +#define PID_INIT 1 +#define PID_UNIX 10 + #endif /* __CORAX_IPC_H */ diff --git a/kernel/core/posixcall.c b/kernel/core/posixcall.c index 781c889..34b2926 100644 --- a/kernel/core/posixcall.c +++ b/kernel/core/posixcall.c @@ -64,7 +64,33 @@ int sys_waitpid(pid_t pid, int *status, int options) int sys_setsid(void) { - return(-ENOSYS); + process_t *cproc; + int ret_val; + + /* + * This call should basically just detach the process from its + * parent, so it can continue after the parent process has ended. + */ + + ret_val = -EFAULT; + cproc = process_get_current(); + + if(cproc) { + /* + * At this point there is nothing that needs to be done here. Maybe + * in the future there will be more that needs to be done. + */ + +#if 0 + process_t *pproc; + + pproc = process_lookup(cproc->p_pid); +#endif /* 0 */ + + ret_val = process_detach(cproc); + } + + return(ret_val); } int sys_posixcall(stack_frame_t *stk) diff --git a/kernel/core/process.c b/kernel/core/process.c index cb4699a..a909903 100644 --- a/kernel/core/process.c +++ b/kernel/core/process.c @@ -558,3 +558,17 @@ int process_fork(int v) return(ret_val); } + +int process_detach(process_t *proc) +{ + int ret_val; + + ret_val = -EINVAL; + + if(proc) { + proc->p_pid = PID_INIT; + ret_val = 0; + } + + return(ret_val); +} diff --git a/kernel/include/process.h b/kernel/include/process.h index 480e2e0..4ac66d2 100644 --- a/kernel/include/process.h +++ b/kernel/include/process.h @@ -51,5 +51,6 @@ void* process_get_tasks(process_t*); pid_t process_get_id(process_t*); int process_exit(process_t*, int); int process_fork(int); +int process_detach(process_t*); #endif /* __PROCESS_H */ -- 2.47.3