()
| 49 | } |
| 50 | |
| 51 | func checkPidFD() error { |
| 52 | // Linux kernel supports pidfd_open(2) since v5.3. |
| 53 | // |
| 54 | // https://man7.org/linux/man-pages/man2/pidfd_open.2.html |
| 55 | pidfd, err := unix.PidfdOpen(os.Getpid(), 0) |
| 56 | if err != nil { |
| 57 | return fmt.Errorf("failed to invoke pidfd_open: %w", err) |
| 58 | } |
| 59 | defer unix.Close(pidfd) |
| 60 | |
| 61 | // Linux kernel supports pidfd_send_signal(2) since v5.1. |
| 62 | // |
| 63 | // https://man7.org/linux/man-pages/man2/pidfd_send_signal.2.html |
| 64 | if err := unix.PidfdSendSignal(pidfd, 0, nil, 0); err != nil { |
| 65 | return fmt.Errorf("failed to invoke pidfd_send_signal: %w", err) |
| 66 | } |
| 67 | |
| 68 | // The waitid(2) supports P_PIDFD since Linux kernel v5.4. |
| 69 | // |
| 70 | // https://man7.org/linux/man-pages/man2/waitid.2.html |
| 71 | werr := IgnoringEINTR(func() error { |
| 72 | return unix.Waitid(unix.P_PIDFD, pidfd, nil, unix.WEXITED, nil) |
| 73 | }) |
| 74 | |
| 75 | // The waitid returns ECHILD since current process isn't the child of current process. |
| 76 | if !errors.Is(werr, unix.ECHILD) { |
| 77 | return fmt.Errorf("failed to invoke waitid with P_PIDFD: wanted error %v, but got %v", |
| 78 | unix.ECHILD, werr) |
| 79 | } |
| 80 | |
| 81 | // NOTE: The CLONE_PIDFD flag has been supported since Linux kernel v5.2. |
| 82 | // So assumption is that if waitid(2) supports P_PIDFD, current kernel |
| 83 | // should support CLONE_PIDFD as well. |
| 84 | return nil |
| 85 | } |
no test coverage detected
searching dependent graphs…