From 8cc54d4634014218697d8d2495998d437bc6e7b1 Mon Sep 17 00:00:00 2001 From: Son Luong Ngoc Date: Thu, 31 Aug 2023 15:21:40 +0200 Subject: [PATCH] ci_runner,executor: remove os-specific syscall (#4642) --- enterprise/server/cmd/ci_runner/main.go | 9 +++++++-- enterprise/server/cmd/executor/BUILD | 2 ++ enterprise/server/cmd/executor/executor.go | 10 +--------- enterprise/server/cmd/executor/executor_unix.go | 16 ++++++++++++++++ .../server/cmd/executor/executor_windows.go | 4 ++++ 5 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 enterprise/server/cmd/executor/executor_unix.go create mode 100644 enterprise/server/cmd/executor/executor_windows.go diff --git a/enterprise/server/cmd/ci_runner/main.go b/enterprise/server/cmd/ci_runner/main.go index 84f15cb80e2..411c8d62750 100644 --- a/enterprise/server/cmd/ci_runner/main.go +++ b/enterprise/server/cmd/ci_runner/main.go @@ -17,7 +17,6 @@ import ( "runtime" "strings" "sync" - "syscall" "time" "github.com/buildbuddy-io/buildbuddy/enterprise/server/build_event_publisher" @@ -854,7 +853,13 @@ func (ar *actionRunner) Run(ctx context.Context, ws *workspace) error { // completed so that the outer workflow invocation gets disconnected // rather than finishing with an error. if *workflowID != "" && exitCode == bazelLocalEnvironmentalErrorExitCode { - syscall.Kill(os.Getpid(), syscall.SIGKILL) + p, err := os.FindProcess(os.Getpid()) + if err != nil { + return err + } + if err := p.Kill(); err != nil { + return err + } } // If this is a successfully "bazel run" invocation from which we are extracting run information via diff --git a/enterprise/server/cmd/executor/BUILD b/enterprise/server/cmd/executor/BUILD index 633d1514b72..f325c2b1006 100644 --- a/enterprise/server/cmd/executor/BUILD +++ b/enterprise/server/cmd/executor/BUILD @@ -10,6 +10,8 @@ go_library( "executor.go", "executor_linux.go", "executor_notlinux.go", + "executor_unix.go", + "executor_windows.go", ], importpath = "github.com/buildbuddy-io/buildbuddy/enterprise/server/cmd/executor", visibility = ["//visibility:public"], diff --git a/enterprise/server/cmd/executor/executor.go b/enterprise/server/cmd/executor/executor.go index 8b733841e86..00efdd1c748 100644 --- a/enterprise/server/cmd/executor/executor.go +++ b/enterprise/server/cmd/executor/executor.go @@ -8,7 +8,6 @@ import ( "net/http" "net/url" "os" - "syscall" "time" "github.com/buildbuddy-io/buildbuddy/enterprise/server/auth" @@ -147,14 +146,7 @@ func GetConfiguredEnvironmentOrDie(healthChecker *healthcheck.HealthChecker) env } func main() { - // The default umask (0022) has the effect of clearing the group-write and - // others-write bits when setting up workspace directories, regardless of the - // permissions bits passed to mkdir. We want to create these directories with - // 0777 permissions in some cases, because we need those to be writable by the - // container user, and it is too costly to enable those permissions via - // explicit chown or chmod calls on those directories. So, we clear the umask - // here to allow group-write and others-write permissions. - syscall.Umask(0) + setUmask() rootContext := context.Background() diff --git a/enterprise/server/cmd/executor/executor_unix.go b/enterprise/server/cmd/executor/executor_unix.go new file mode 100644 index 00000000000..27c9ae10be9 --- /dev/null +++ b/enterprise/server/cmd/executor/executor_unix.go @@ -0,0 +1,16 @@ +//go:build unix + +package main + +import "syscall" + +func setUmask() { + // The default umask (0022) has the effect of clearing the group-write and + // others-write bits when setting up workspace directories, regardless of the + // permissions bits passed to mkdir. We want to create these directories with + // 0777 permissions in some cases, because we need those to be writable by the + // container user, and it is too costly to enable those permissions via + // explicit chown or chmod calls on those directories. So, we clear the umask + // here to allow group-write and others-write permissions. + syscall.Umask(0) +} diff --git a/enterprise/server/cmd/executor/executor_windows.go b/enterprise/server/cmd/executor/executor_windows.go new file mode 100644 index 00000000000..d8fecca725e --- /dev/null +++ b/enterprise/server/cmd/executor/executor_windows.go @@ -0,0 +1,4 @@ +package main + +func setUmask() { +}