setupPidfd opens a process file descriptor of init process, and sends the file descriptor back to the socket.
(socket *os.File, initType string)
| 722 | // setupPidfd opens a process file descriptor of init process, and sends the |
| 723 | // file descriptor back to the socket. |
| 724 | func setupPidfd(socket *os.File, initType string) error { |
| 725 | defer socket.Close() |
| 726 | |
| 727 | pidFd, err := unix.PidfdOpen(os.Getpid(), 0) |
| 728 | if err != nil { |
| 729 | return fmt.Errorf("failed to pidfd_open: %w", err) |
| 730 | } |
| 731 | |
| 732 | if err := cmsg.SendRawFd(socket, initType, uintptr(pidFd)); err != nil { |
| 733 | unix.Close(pidFd) |
| 734 | return fmt.Errorf("failed to send pidfd on socket: %w", err) |
| 735 | } |
| 736 | return unix.Close(pidFd) |
| 737 | } |