From b5f194d20f3f7b2f9c3c6ee9156997c2c796054e Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Wed, 17 Apr 2019 00:28:34 +0800 Subject: [PATCH] Fix get_ppid for init process --- kernel/src/syscall/proc.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/src/syscall/proc.rs b/kernel/src/syscall/proc.rs index c6cc4ec..6f33cf8 100644 --- a/kernel/src/syscall/proc.rs +++ b/kernel/src/syscall/proc.rs @@ -231,7 +231,11 @@ pub fn sys_gettid() -> SysResult { /// Get the parent process id pub fn sys_getppid() -> SysResult { - Ok(process().parent.as_ref().unwrap().lock().pid.get()) + if let Some(ref parent) = process().parent.as_ref() { + Ok(parent.lock().pid.get()) + } else { + Ok(0) + } } /// Exit the current thread