Skip to content

Commit f539556

Browse files
Asphalttbrb
authored andcommitted
Flush output file
Flush output file before closing it. Signed-off-by: Leon Hwang <[email protected]>
1 parent 53e8f30 commit f539556

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

internal/pwru/output.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package pwru
77
import (
88
"errors"
99
"fmt"
10-
"io"
1110
"log"
1211
"net"
1312
"os"
@@ -36,7 +35,7 @@ type output struct {
3635
printSkbMap *ebpf.Map
3736
printStackMap *ebpf.Map
3837
addr2name Addr2Name
39-
writer io.Writer
38+
writer *os.File
4039
kprobeMulti bool
4140
kfreeReasons map[uint64]string
4241
ifaceCache map[uint64]map[uint32]string
@@ -81,6 +80,13 @@ func NewOutput(flags *Flags, printSkbMap *ebpf.Map, printStackMap *ebpf.Map,
8180
}, nil
8281
}
8382

83+
func (o *output) Close() {
84+
if o.writer != os.Stdout {
85+
_ = o.writer.Sync()
86+
_ = o.writer.Close()
87+
}
88+
}
89+
8490
func (o *output) PrintHeader() {
8591
if o.flags.OutputTS == "absolute" {
8692
fmt.Fprintf(o.writer, "%12s ", "TIME")

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ func main() {
299299
if err != nil {
300300
log.Fatalf("Failed to create outputer: %s", err)
301301
}
302+
defer output.Close()
302303
output.PrintHeader()
303304

304305
defer func() {

0 commit comments

Comments
 (0)