From e66387b252f36c894d79769cbfb178bc950600d4 Mon Sep 17 00:00:00 2001 From: Minep Date: Wed, 15 Jun 2022 21:58:30 +0100 Subject: [PATCH] refactor: formattings fix: avoid setpgid on group leader --- lunaix-os/includes/lunaix/proc.h | 1 + lunaix-os/kernel/lxinit.c | 5 ++--- lunaix-os/kernel/proc0.c | 14 ++++++++++++++ lunaix-os/kernel/process.c | 4 ++-- lunaix-os/kernel/syscall.c | 9 ++++++--- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lunaix-os/includes/lunaix/proc.h b/lunaix-os/includes/lunaix/proc.h index a6f4470..eafae4f 100644 --- a/lunaix-os/includes/lunaix/proc.h +++ b/lunaix-os/includes/lunaix/proc.h @@ -7,6 +7,7 @@ __LXSYSCALL(void, yield); __LXSYSCALL1(pid_t, wait, int*, status); + __LXSYSCALL3(pid_t, waitpid, pid_t, pid, int*, status, int, options); #endif /* __LUNAIX_SYS_H */ diff --git a/lunaix-os/kernel/lxinit.c b/lunaix-os/kernel/lxinit.c index fa8458c..43f0f2d 100644 --- a/lunaix-os/kernel/lxinit.c +++ b/lunaix-os/kernel/lxinit.c @@ -49,14 +49,13 @@ _lxinit_main() pid_t p = 0; if (!fork()) { - kprintf("Test no hang!"); - sleep(12); + kprintf("Test no hang!\n"); + sleep(6); _exit(0); } waitpid(-1, &status, WNOHANG); - // 这里是就是LunaixOS的第一个进程了! for (size_t i = 0; i < 5; i++) { pid_t pid = 0; if (!(pid = fork())) { diff --git a/lunaix-os/kernel/proc0.c b/lunaix-os/kernel/proc0.c index dac1b55..074bcd9 100644 --- a/lunaix-os/kernel/proc0.c +++ b/lunaix-os/kernel/proc0.c @@ -36,6 +36,20 @@ void __proc0() { init_platform(); + asm volatile("movw %0, %ax\n" + "movw %ax, %es\n" + "movw %ax, %ds\n" + "movw %ax, %fs\n" + "movw %ax, %gs\n" + "pushl %0\n" + "pushl %1\n" + "pushl %2\n" + "pushl %3\n" + "retf" ::"i"(UDATA_SEG), + "i"(USTACK_TOP & ~0xf), + "i"(UCODE_SEG), + "r"(&&usr)); +usr: if (!fork()) { asm("jmp _lxinit_main"); } diff --git a/lunaix-os/kernel/process.c b/lunaix-os/kernel/process.c index 64f2654..020dfb4 100644 --- a/lunaix-os/kernel/process.c +++ b/lunaix-os/kernel/process.c @@ -107,14 +107,14 @@ __DEFINE_LXSYSCALL2(int, setpgid, pid_t, pid, pid_t, pgid) pgid = pgid ? pgid : proc->pid; - llist_delete(&proc->grp_member); struct proc_info* gruppenfuhrer = get_process(pgid); - if (!gruppenfuhrer) { + if (!gruppenfuhrer || proc->pgid == proc->pid) { __current->k_status = LXINVL; return -1; } + llist_delete(&proc->grp_member); llist_append(&gruppenfuhrer->grp_member, &proc->grp_member); proc->pgid = pgid; diff --git a/lunaix-os/kernel/syscall.c b/lunaix-os/kernel/syscall.c index 0d41470..ce0f2a7 100644 --- a/lunaix-os/kernel/syscall.c +++ b/lunaix-os/kernel/syscall.c @@ -1,13 +1,16 @@ -#include #include #include #include +#include #include LOG_MODULE("SYSCALL") -extern void syscall_hndlr(isr_param* param); +extern void +syscall_hndlr(isr_param* param); -void syscall_install() { +void +syscall_install() +{ intr_subscribe(LUNAIX_SYS_CALL, syscall_hndlr); } \ No newline at end of file -- 2.27.0