From 778d48994e80aeedc1c912c6cf25b38485830968 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Thu, 2 Mar 2023 00:03:15 +0300 Subject: [PATCH] Dup3() breaks darwin. Use conditional compilation of Dup2() --- api/common/logger.go | 3 +-- api/common/logger_default.go | 25 +++++++++++++++++++++++++ api/common/logger_linux_arm64.go | 23 +++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 api/common/logger_default.go create mode 100644 api/common/logger_linux_arm64.go diff --git a/api/common/logger.go b/api/common/logger.go index 9f90a16c..524333d5 100644 --- a/api/common/logger.go +++ b/api/common/logger.go @@ -22,7 +22,6 @@ import ( "os" "strings" "sync" - "syscall" "github.com/sirupsen/logrus" logrus_syslog "github.com/sirupsen/logrus/hooks/syslog" @@ -59,7 +58,7 @@ func InitLoggers(logFile string) { for _, l := range loggers { l.Out = file } - err = syscall.Dup3(int(file.Fd()), int(os.Stderr.Fd()), 0) + err = Dup2(int(file.Fd()), int(os.Stderr.Fd())) if err != nil { log.Errorf("Couldn't redirect STDERR to the log file %v", logFile) return diff --git a/api/common/logger_default.go b/api/common/logger_default.go new file mode 100644 index 00000000..c1f87684 --- /dev/null +++ b/api/common/logger_default.go @@ -0,0 +1,25 @@ +// +build !linux !arm64 + +// Copyright 2021 Yandex LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package common + +import ( + "syscall" +) + +func Dup2(oldfd, newfd int) error { + return syscall.Dup2(oldfd, newfd) +} diff --git a/api/common/logger_linux_arm64.go b/api/common/logger_linux_arm64.go new file mode 100644 index 00000000..f8c8a498 --- /dev/null +++ b/api/common/logger_linux_arm64.go @@ -0,0 +1,23 @@ +// Copyright 2021 Yandex LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package common + +import ( + "syscall" +) + +func Dup2(oldfd, newfd int) error { + return syscall.Dup3(oldfd, newfd, 0) +}