From 04db52612ef87c731b525f66c0d7379026c41954 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Mon, 12 Jun 2023 12:36:15 +0800 Subject: [PATCH] libc/fdcheck: child process that uses the parent process'fd will crash In many cases, it is legal for the child process to use the fd created by the parent process, so to improve compatibility, we allow the child process to use the fd of the Parent process. Signed-off-by: hujun5 --- libs/libc/misc/lib_fdcheck.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/libc/misc/lib_fdcheck.c b/libs/libc/misc/lib_fdcheck.c index b1587aae97..b7825609d9 100644 --- a/libs/libc/misc/lib_fdcheck.c +++ b/libs/libc/misc/lib_fdcheck.c @@ -75,6 +75,7 @@ int fdcheck_restore(int val) { int pid_expect; int pid_now; + int ppid_now; if (val <= 2) { @@ -83,9 +84,11 @@ int fdcheck_restore(int val) pid_expect = (val >> PID_SHIFT); pid_now = (getpid() & PID_MASK); - if (pid_expect != pid_now) + ppid_now = (getppid() & PID_MASK); + if (pid_expect != pid_now && pid_expect != ppid_now) { - ferr("pid_expect %d pid_now %d\n", pid_expect, pid_now); + ferr("pid_expect %d pid_now %d ppid_now %d\n", + pid_expect, pid_now, ppid_now); PANIC(); }