summaryrefslogtreecommitdiffhomepage
path: root/logtail
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@tailscale.com>2021-02-17 12:18:30 -0800
committerDavid Crawshaw <crawshaw@tailscale.com>2021-02-17 12:18:54 -0800
commitde94fe0f879ff055412fd1cda08dd9b89db85063 (patch)
treef1e15c519eca686737b49e802b5f5e22a4da5852 /logtail
parentdec01ef22bcce180bbdd70c6b7027900f0fd79d7 (diff)
downloadtailscale-crawshaw/filchsync.tar.xz
tailscale-crawshaw/filchsync.zip
filch: use F_NOCACHE on macOScrawshaw/filchsync
For #1320 Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
Diffstat (limited to 'logtail')
-rw-r--r--logtail/filch/filch.go4
-rw-r--r--logtail/filch/openfilesync_darwin.go27
-rw-r--r--logtail/filch/openfilesync_notdarwin.go16
3 files changed, 45 insertions, 2 deletions
diff --git a/logtail/filch/filch.go b/logtail/filch/filch.go
index 07d9b6203..22740588e 100644
--- a/logtail/filch/filch.go
+++ b/logtail/filch/filch.go
@@ -131,11 +131,11 @@ func New(filePrefix string, opts Options) (f *Filch, err error) {
path1 := filePrefix + ".log1.txt"
path2 := filePrefix + ".log2.txt"
- f1, err = os.OpenFile(path1, os.O_CREATE|os.O_RDWR, 0600)
+ f1, err = openFileSync(path1, os.O_CREATE|os.O_RDWR, 0600)
if err != nil {
return nil, err
}
- f2, err = os.OpenFile(path2, os.O_CREATE|os.O_RDWR, 0600)
+ f2, err = openFileSync(path2, os.O_CREATE|os.O_RDWR, 0600)
if err != nil {
return nil, err
}
diff --git a/logtail/filch/openfilesync_darwin.go b/logtail/filch/openfilesync_darwin.go
new file mode 100644
index 000000000..f6bb9183a
--- /dev/null
+++ b/logtail/filch/openfilesync_darwin.go
@@ -0,0 +1,27 @@
+// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//+build darwin
+
+package filch
+
+import (
+ "fmt"
+ "os"
+ "syscall"
+
+ "golang.org/x/sys/unix"
+)
+
+func openFileSync(path string, flag int, perm os.FileMode) (*os.File, error) {
+ f, err := os.OpenFile(path, flag, perm)
+ if err != nil {
+ return nil, err
+ }
+ _, err = unix.FcntlInt(uintptr(f.Fd()), syscall.F_NOCACHE, 1)
+ if err != nil {
+ return nil, fmt.Errorf("openFileSync: %w", err)
+ }
+ return f, nil
+}
diff --git a/logtail/filch/openfilesync_notdarwin.go b/logtail/filch/openfilesync_notdarwin.go
new file mode 100644
index 000000000..f6cdb264c
--- /dev/null
+++ b/logtail/filch/openfilesync_notdarwin.go
@@ -0,0 +1,16 @@
+// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//+build !darwin
+
+package filch
+
+import (
+ "os"
+)
+
+func openFileSync(path string, flag int, perm os.FileMode) (*os.File, error) {
+ // TODO(crawshaw): on Linux and FreeBSD, use O_SYNC
+ return os.OpenFile(path, flag, perm)
+}