-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proc: use pidfd_open(..., PIDFD_THREAD) if available
With luck this approach might possibly perhaps go upstream! We still fall back to waitfd if using PIDFD_THREAD doesn't work. Complicated somewhat by having to use SYS_syscall() if a glibc too old to support pidfd_open() isn't available (i.e. all released ones: it'll be in 2.36), and by the likelihood that PIDFD_THREAD isn't in the header even if the header is present, but otherwise fairly trivial. Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
- Loading branch information
1 parent
7c655ca
commit 2120a70
Showing
5 changed files
with
56 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed under the Universal Permissive License v 1.0 as shown at | ||
* http://oss.oracle.com/licenses/upl. | ||
*/ | ||
|
||
#include <sys/syscall.h> | ||
#include <sys/wait.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <port.h> /* for waitfd, etc */ | ||
#ifdef HAVE_SYS_PIDFD_H | ||
#include <sys/pidfd.h> | ||
#endif | ||
|
||
#ifndef __NR_pidfd_open | ||
#define __NR_pidfd_open 434 | ||
#endif | ||
|
||
#ifndef PIDFD_THREAD | ||
/* An arbitrary value unlikely ever to be useful for pidfds. */ | ||
#define PIDFD_THREAD O_NOCTTY | ||
#endif | ||
|
||
int | ||
pid_fd(pid_t pid) | ||
{ | ||
int fd; | ||
#ifdef HAVE_SYS_PIDFD_H | ||
if ((fd = pidfd_open(pid, PIDFD_THREAD)) >= 0) | ||
return fd; | ||
#else | ||
if ((fd = syscall(__NR_pidfd_open, pid, PIDFD_THREAD)) >= 0) | ||
return fd; | ||
#endif | ||
|
||
/* | ||
* WEXITED | WSTOPPED is what Pwait() waits for. | ||
*/ | ||
return waitfd(P_PID, pid, WEXITED | WSTOPPED, 0); | ||
} |