File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "context"
5+ "fmt"
6+ "os"
7+
8+ "golang.org/x/sys/unix"
9+ )
10+
11+ func createFIFOByPath (fPath string ) (* os.File , error ) {
12+ if err := os .Remove (fPath ); err != nil && ! os .IsNotExist (err ) {
13+ return nil , fmt .Errorf ("can't remove file: %w" , err )
14+ }
15+
16+ if err := unix .Mkfifo (fPath , 0666 ); err != nil {
17+ return nil , fmt .Errorf ("can't create linux pipe: %w" , err )
18+ }
19+
20+ fifoF , err := os .OpenFile (fPath , os .O_RDWR , os .ModeNamedPipe )
21+ if err != nil {
22+ return nil , fmt .Errorf ("can't open pipe: %w" , err )
23+ }
24+
25+ return fifoF , nil
26+ }
27+
28+ func createFIFOByPathCtx (ctx context.Context , fPath string ) (* os.File , error ) {
29+ f , err := createFIFOByPath (fPath )
30+ if err != nil {
31+ return nil , err
32+ }
33+
34+ go func () {
35+ <- ctx .Done ()
36+ _ = f .Close ()
37+ }()
38+
39+ return f , nil
40+ }
Original file line number Diff line number Diff line change @@ -2,35 +2,19 @@ package main
22
33import (
44 "context"
5- "fmt"
6- "os"
75
86 "go.uber.org/zap"
9- "golang.org/x/sys/unix"
107
118 "github.com/code-tool/docker-fpm-wrapper/internal/zapx"
129 "github.com/code-tool/docker-fpm-wrapper/pkg/phpfpm"
1310)
1411
1512func startSlowlogProxyForPool (ctx context.Context , pool phpfpm.Pool , out chan phpfpm.SlowlogEntry ) error {
16- if err := os .Remove (pool .SlowlogPath ); err != nil && ! os .IsNotExist (err ) {
17- return fmt .Errorf ("can't remove slowlog file: %w" , err )
18- }
19-
20- if err := unix .Mkfifo (pool .SlowlogPath , 0666 ); err != nil {
21- return fmt .Errorf ("can't create linux pipe for slowlog: %w" , err )
22- }
23-
24- fifoF , err := os .OpenFile (pool .SlowlogPath , os .O_RDWR , os .ModeNamedPipe )
13+ fifoF , err := createFIFOByPathCtx (ctx , pool .SlowlogPath )
2514 if err != nil {
26- return fmt . Errorf ( "can't open pipe with error: %w" , err )
15+ return err
2716 }
2817
29- go func () {
30- <- ctx .Done ()
31- _ = fifoF .Close ()
32- }()
33-
3418 slowLogParser := phpfpm .NewSlowlogParser (pool .RequestSlowlogTraceDepth )
3519 go func () {
3620 // TODO probably should be logged
You can’t perform that action at this time.
0 commit comments