Skip to content

Commit

Permalink
[release-branch.go1.23] syscall: on exec failure, close pidfd
Browse files Browse the repository at this point in the history
For golang#69284
Fixes golang#69402

Change-Id: I6350209302778ba5e44fa03d0b9e680d2b4ec192
Reviewed-on: https://go-review.googlesource.com/c/go/+/611495
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: roger peppe <rogpeppe@gmail.com>
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
(cherry picked from commit 8926ca9)
Reviewed-on: https://go-review.googlesource.com/c/go/+/613616
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
  • Loading branch information
ianlancetaylor authored and wangyifan committed Dec 16, 2024
1 parent 8ea3c8b commit 54e8ff9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/syscall/exec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,3 +839,11 @@ func doCheckClonePidfd(pidfd *int32) (pid uintptr, errno Errno) {
RawSyscall(SYS_EXIT_GROUP, 0, 0, 0)
}
}

// forkAndExecFailureCleanup cleans up after an exec failure.
func forkAndExecFailureCleanup(attr *ProcAttr, sys *SysProcAttr) {
if sys.PidFD != nil && *sys.PidFD != -1 {
Close(*sys.PidFD)
*sys.PidFD = -1
}
}

0 comments on commit 54e8ff9

Please sign in to comment.