-
Notifications
You must be signed in to change notification settings - Fork 46
/
file_linux.go
68 lines (60 loc) · 1.14 KB
/
file_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//go:build linux
package log
import (
"os"
"path/filepath"
"syscall"
"unsafe"
)
func (w *FileWriter) WriteV(iovs []syscall.Iovec) (n uintptr, err error) {
w.mu.Lock()
defer w.mu.Unlock()
if w.file == nil {
if w.Filename == "" {
n, err = writev(syscall.Stderr, iovs)
if n == ^uintptr(0) { // -1 means aborted
n = 0
}
return
}
if w.EnsureFolder {
err = os.MkdirAll(filepath.Dir(w.Filename), 0755)
if err != nil {
return
}
}
err = w.create()
if err != nil {
return
}
}
n, err = writev(int(w.file.Fd()), iovs)
if n == ^uintptr(0) { // -1 means aborted
n = 0
}
if err != nil {
return
}
w.size += int64(n)
if w.MaxSize > 0 && w.size > w.MaxSize && w.Filename != "" {
err = w.rotate()
}
return
}
// from https://github.com/golang/go/blob/master/src/internal/poll/fd_writev_unix.go
func writev(fd int, iovecs []syscall.Iovec) (uintptr, error) {
var (
r uintptr
e syscall.Errno
)
for {
r, _, e = syscall.Syscall(syscall.SYS_WRITEV, uintptr(fd), uintptr(unsafe.Pointer(&iovecs[0])), uintptr(len(iovecs)))
if e != syscall.EINTR {
break
}
}
if e != 0 {
return r, e
}
return r, nil
}