Skip to content

Commit

Permalink
Dup3() breaks darwin. Use conditional compilation of Dup2()
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Mar 1, 2023
1 parent 866399a commit 778d489
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
3 changes: 1 addition & 2 deletions api/common/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"
"strings"
"sync"
"syscall"

"github.com/sirupsen/logrus"
logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions api/common/logger_default.go
Original file line number Diff line number Diff line change
@@ -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)
}
23 changes: 23 additions & 0 deletions api/common/logger_linux_arm64.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 778d489

Please sign in to comment.