From: Bruno Haible Date: Wed, 27 May 2020 17:41:38 +0000 (+0200) Subject: get_ppid_of: Make more robust in multithreaded applications. X-Git-Tag: v1.0~4044 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=c459f413148b87cc3a39adacc71a441be792c419;p=gnulib.git get_ppid_of: Make more robust in multithreaded applications. * lib/get_ppid_of.c (get_ppid_of): Pass an O_CLOEXEC flag to open(). * modules/get_ppid_of (Depends-on): Add 'open'. --- diff --git a/ChangeLog b/ChangeLog index beba581e90..ae1df5ec7e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-05-28 Bruno Haible + + get_ppid_of: Make more robust in multithreaded applications. + * lib/get_ppid_of.c (get_ppid_of): Pass an O_CLOEXEC flag to open(). + * modules/get_ppid_of (Depends-on): Add 'open'. + 2020-05-28 Bruno Haible get-rusage-as: Make more robust in multithreaded applications. diff --git a/lib/get_ppid_of.c b/lib/get_ppid_of.c index 1560e7d84b..5579cd9c5d 100644 --- a/lib/get_ppid_of.c +++ b/lib/get_ppid_of.c @@ -74,7 +74,7 @@ get_ppid_of (pid_t pid) int fd; sprintf (filename, "/proc/%u/status", (unsigned int) pid); - fd = open (filename, O_RDONLY); + fd = open (filename, O_RDONLY | O_CLOEXEC); if (fd >= 0) { char buf[4096 + 1]; @@ -115,7 +115,7 @@ get_ppid_of (pid_t pid) int fd; sprintf (filename, "/proc/%u/status", (unsigned int) pid); - fd = open (filename, O_RDONLY); + fd = open (filename, O_RDONLY | O_CLOEXEC); if (fd >= 0) { char buf[4096 + 1]; @@ -152,7 +152,7 @@ get_ppid_of (pid_t pid) int fd; sprintf (filename, "/proc/%u/psinfo", (unsigned int) pid); - fd = open (filename, O_RDONLY); + fd = open (filename, O_RDONLY | O_CLOEXEC); if (fd >= 0) { char buf[4096 + 1]; @@ -190,7 +190,7 @@ get_ppid_of (pid_t pid) int fd; sprintf (filename, "/proc/%u/psinfo", (unsigned int) pid); - fd = open (filename, O_RDONLY); + fd = open (filename, O_RDONLY | O_CLOEXEC); if (fd >= 0) { /* The contents is a 'struct psinfo'. But since 'struct psinfo' @@ -283,7 +283,7 @@ get_ppid_of (pid_t pid) int fd; sprintf (filename, "/proc/pinfo/%u", pid); - fd = open (filename, O_RDONLY); + fd = open (filename, O_RDONLY | O_CLOEXEC); if (0 <= fd) { prpsinfo_t buf; diff --git a/modules/get_ppid_of b/modules/get_ppid_of index 4f2cad1b2c..84e3d793b3 100644 --- a/modules/get_ppid_of +++ b/modules/get_ppid_of @@ -9,6 +9,7 @@ Depends-on: extensions sys_types unistd +open configure.ac: