libc/fdcheck: if pid_expect is 0, fdcheck does not take effect

there are some user code like this:
  /* close all inherited fds */
  for (i = 3; i < maxfds; i++)
    func (i);

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2023-06-12 13:36:38 +08:00 committed by Xiang Xiao
parent 04db52612e
commit b2ff151282

View file

@ -85,7 +85,7 @@ int fdcheck_restore(int val)
pid_expect = (val >> PID_SHIFT);
pid_now = (getpid() & PID_MASK);
ppid_now = (getppid() & PID_MASK);
if (pid_expect != pid_now && pid_expect != ppid_now)
if (pid_expect != pid_now && pid_expect != ppid_now && pid_expect != 0)
{
ferr("pid_expect %d pid_now %d ppid_now %d\n",
pid_expect, pid_now, ppid_now);