diff --git a/cmd/dfget/cmd/daemon.go b/cmd/dfget/cmd/daemon.go index 0e8a23b99..c7c04abd8 100644 --- a/cmd/dfget/cmd/daemon.go +++ b/cmd/dfget/cmd/daemon.go @@ -20,7 +20,6 @@ import ( "context" "os" "path" - "syscall" "time" "github.com/gofrs/flock" @@ -92,13 +91,13 @@ func redirectStdoutAndStderr(console bool, logDir string) { stdoutPath := path.Join(logDir, "daemon", "stdout.log") if stdout, err := os.OpenFile(stdoutPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_SYNC, 0644); err != nil { logger.Warnf("open %s error: %s", stdoutPath, err) - } else if err := syscall.Dup2(int(stdout.Fd()), 1); err != nil { + } else if err := dup2(int(stdout.Fd()), 1); err != nil { logger.Warnf("redirect stdout error: %s", err) } stderrPath := path.Join(logDir, "daemon", "stderr.log") if stderr, err := os.OpenFile(stderrPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_SYNC, 0644); err != nil { logger.Warnf("open %s error: %s", stderrPath, err) - } else if err := syscall.Dup2(int(stderr.Fd()), 2); err != nil { + } else if err := dup2(int(stderr.Fd()), 2); err != nil { logger.Warnf("redirect stderr error: %s", err) } } diff --git a/cmd/dfget/cmd/daemon_dup2.go b/cmd/dfget/cmd/daemon_dup2.go new file mode 100644 index 000000000..22124703e --- /dev/null +++ b/cmd/dfget/cmd/daemon_dup2.go @@ -0,0 +1,26 @@ +//go:build !windows && !arm && !arm64 +// +build !windows,!arm,!arm64 + +/* + * Copyright 2022 The Dragonfly Authors + * + * 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 cmd + +import "syscall" + +func dup2(from int, to int) (err error) { + return syscall.Dup2(from, to) +} diff --git a/cmd/dfget/cmd/daemon_dup3.go b/cmd/dfget/cmd/daemon_dup3.go new file mode 100644 index 000000000..ed261643a --- /dev/null +++ b/cmd/dfget/cmd/daemon_dup3.go @@ -0,0 +1,29 @@ +//go:build !windows && (arm || arm64) +// +build !windows +// +build arm arm64 + +/* + * Copyright 2022 The Dragonfly Authors + * + * 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 cmd + +import "syscall" + +func dup2(from int, to int) (err error) { + // linux_arm64 platform doesn't have syscall.Dup2 + // so use the nearly identical syscall.Dup3 instead. + return syscall.Dup3(from, to, 0) +}