mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 03:34:50 +00:00
Merge pull request #21 from DominicBreuker/fix-overlong-draining
Skip event processing while draining
This commit is contained in:
16
Makefile
16
Makefile
@@ -47,30 +47,30 @@ build:
|
|||||||
docker run -it \
|
docker run -it \
|
||||||
--rm \
|
--rm \
|
||||||
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
||||||
-w "/go/src/github.com/dominicbreuker" \
|
-w "/go/src/github.com/dominicbreuker/pspy" \
|
||||||
--env CGO_ENABLED=0 \
|
--env CGO_ENABLED=0 \
|
||||||
--env GOOS=linux \
|
--env GOOS=linux \
|
||||||
--env GOARCH=386 \
|
--env GOARCH=386 \
|
||||||
$(BUILD_IMAGE) /bin/sh -c "go build -a -ldflags '-s -w -X main.version=${VERSION} -X main.commit=${BUILD_SHA} -extldflags \"-static\"' -o pspy/bin/pspy32 pspy/main.go"
|
$(BUILD_IMAGE) /bin/sh -c "go build -a -ldflags '-s -w -X main.version=${VERSION} -X main.commit=${BUILD_SHA} -extldflags \"-static\"' -o bin/pspy32 main.go"
|
||||||
docker run -it \
|
docker run -it \
|
||||||
--rm \
|
--rm \
|
||||||
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
||||||
-w "/go/src/github.com/dominicbreuker" \
|
-w "/go/src/github.com/dominicbreuker/pspy" \
|
||||||
--env CGO_ENABLED=0 \
|
--env CGO_ENABLED=0 \
|
||||||
--env GOOS=linux \
|
--env GOOS=linux \
|
||||||
--env GOARCH=amd64 \
|
--env GOARCH=amd64 \
|
||||||
$(BUILD_IMAGE) /bin/sh -c "go build -a -ldflags '-s -w -X main.version=${VERSION} -X main.commit=${BUILD_SHA} -extldflags \"-static\"' -o pspy/bin/pspy64 pspy/main.go"
|
$(BUILD_IMAGE) /bin/sh -c "go build -a -ldflags '-s -w -X main.version=${VERSION} -X main.commit=${BUILD_SHA} -extldflags \"-static\"' -o bin/pspy64 main.go"
|
||||||
docker run -it \
|
docker run -it \
|
||||||
--rm \
|
--rm \
|
||||||
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
||||||
-w "/go/src/github.com/dominicbreuker" \
|
-w "/go/src/github.com/dominicbreuker/pspy" \
|
||||||
--env GOOS=linux \
|
--env GOOS=linux \
|
||||||
--env GOARCH=386 \
|
--env GOARCH=386 \
|
||||||
$(BUILD_IMAGE) /bin/sh -c "go build -ldflags '-w -s -X main.version=${VERSION} -X main.commit=${BUILD_SHA}' -o pspy/bin/pspy32s pspy/main.go && upx pspy/bin/pspy32s"
|
$(BUILD_IMAGE) /bin/sh -c "go build -ldflags '-w -s -X main.version=${VERSION} -X main.commit=${BUILD_SHA}' -o bin/pspy32s main.go && upx bin/pspy32s"
|
||||||
docker run -it \
|
docker run -it \
|
||||||
--rm \
|
--rm \
|
||||||
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
||||||
-w "/go/src/github.com/dominicbreuker" \
|
-w "/go/src/github.com/dominicbreuker/pspy" \
|
||||||
--env GOOS=linux \
|
--env GOOS=linux \
|
||||||
--env GOARCH=amd64 \
|
--env GOARCH=amd64 \
|
||||||
$(BUILD_IMAGE) /bin/sh -c "go build -ldflags '-w -s -X main.version=${VERSION} -X main.commit=${BUILD_SHA}' -o pspy/bin/pspy64s pspy/main.go && upx pspy/bin/pspy64s"
|
$(BUILD_IMAGE) /bin/sh -c "go build -ldflags '-w -s -X main.version=${VERSION} -X main.commit=${BUILD_SHA}' -o bin/pspy64s main.go && upx bin/pspy64s"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
FROM golang:1.18-bullseye
|
FROM golang:1.19-bullseye
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y upx && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y upx && rm -rf /var/lib/apt/lists/*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.18-bullseye
|
FROM golang:1.19-bullseye
|
||||||
|
|
||||||
RUN apt-get update && apt-get -y install cron python3 sudo procps
|
RUN apt-get update && apt-get -y install cron python3 sudo procps
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.18-bullseye
|
FROM golang:1.19-bullseye
|
||||||
|
|
||||||
RUN apt-get update && apt-get -y install cron python3 sudo procps
|
RUN apt-get update && apt-get -y install cron python3 sudo procps
|
||||||
|
|
||||||
@@ -8,7 +8,8 @@ RUN apt-get update && apt-get -y install cron python3 sudo procps
|
|||||||
COPY main.go /go/src/github.com/dominicbreuker/pspy/main.go
|
COPY main.go /go/src/github.com/dominicbreuker/pspy/main.go
|
||||||
COPY cmd /go/src/github.com/dominicbreuker/pspy/cmd
|
COPY cmd /go/src/github.com/dominicbreuker/pspy/cmd
|
||||||
COPY internal /go/src/github.com/dominicbreuker/pspy/internal
|
COPY internal /go/src/github.com/dominicbreuker/pspy/internal
|
||||||
COPY vendor /go/src/github.com/dominicbreuker/pspy/vendor
|
COPY go.mod /go/src/github.com/dominicbreuker/pspy/go.mod
|
||||||
|
COPY go.sum /go/src/github.com/dominicbreuker/pspy/go.sum
|
||||||
COPY .git /go/src/github.com/dominicbreuker/pspy/.git
|
COPY .git /go/src/github.com/dominicbreuker/pspy/.git
|
||||||
|
|
||||||
# run tests
|
# run tests
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type FSWatcher struct {
|
|||||||
w Walker
|
w Walker
|
||||||
maxWatchers int
|
maxWatchers int
|
||||||
eventSize int
|
eventSize int
|
||||||
|
drain bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFSWatcher() *FSWatcher {
|
func NewFSWatcher() *FSWatcher {
|
||||||
@@ -33,9 +34,14 @@ func NewFSWatcher() *FSWatcher {
|
|||||||
w: walker.NewWalker(),
|
w: walker.NewWalker(),
|
||||||
maxWatchers: inotify.MaxWatchers,
|
maxWatchers: inotify.MaxWatchers,
|
||||||
eventSize: inotify.EventSize,
|
eventSize: inotify.EventSize,
|
||||||
|
drain: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fs *FSWatcher) Enable() {
|
||||||
|
fs.drain = false
|
||||||
|
}
|
||||||
|
|
||||||
func (fs *FSWatcher) Close() {
|
func (fs *FSWatcher) Close() {
|
||||||
fs.i.Close()
|
fs.i.Close()
|
||||||
}
|
}
|
||||||
@@ -116,6 +122,10 @@ func (fs *FSWatcher) observe(triggerCh chan struct{}, dataCh chan []byte, errCh
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
n, err := fs.i.Read(buf)
|
n, err := fs.i.Read(buf)
|
||||||
|
if fs.drain {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
triggerCh <- struct{}{}
|
triggerCh <- struct{}{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errCh <- fmt.Errorf("reading inotify buffer: %v", err)
|
errCh <- fmt.Errorf("reading inotify buffer: %v", err)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ type Logger interface {
|
|||||||
type FSWatcher interface {
|
type FSWatcher interface {
|
||||||
Init(rdirs, dirs []string) (chan error, chan struct{})
|
Init(rdirs, dirs []string) (chan error, chan struct{})
|
||||||
Run() (chan struct{}, chan string, chan error)
|
Run() (chan struct{}, chan string, chan error)
|
||||||
|
Enable()
|
||||||
}
|
}
|
||||||
|
|
||||||
type PSScanner interface {
|
type PSScanner interface {
|
||||||
@@ -110,7 +111,7 @@ func startFSW(fsw FSWatcher, logger Logger, drainFor time.Duration, sigCh <-chan
|
|||||||
|
|
||||||
// ignore all file system events created on startup
|
// ignore all file system events created on startup
|
||||||
logger.Infof("Draining file system events due to startup...")
|
logger.Infof("Draining file system events due to startup...")
|
||||||
ok = drainEventsFor(triggerCh, fsEventCh, drainFor, sigCh)
|
ok = drainEventsFor(triggerCh, fsEventCh, drainFor, sigCh, fsw)
|
||||||
logger.Infof("done")
|
logger.Infof("done")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -137,14 +138,13 @@ func logErrors(errCh chan error, logger Logger) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func drainEventsFor(triggerCh chan struct{}, eventCh chan string, d time.Duration, sigCh <-chan os.Signal) bool {
|
func drainEventsFor(triggerCh chan struct{}, eventCh chan string, d time.Duration, sigCh <-chan os.Signal, fsw FSWatcher) bool {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-sigCh:
|
case <-sigCh:
|
||||||
return false
|
return false
|
||||||
case <-triggerCh:
|
|
||||||
case <-eventCh:
|
|
||||||
case <-time.After(d):
|
case <-time.After(d):
|
||||||
|
fsw.Enable()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,8 +68,6 @@ func TestStartFSW(t *testing.T) {
|
|||||||
sigCh := make(chan os.Signal)
|
sigCh := make(chan os.Signal)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
fsw.runTriggerCh <- struct{}{} // trigger sent while draining
|
|
||||||
fsw.runEventCh <- "event sent while draining"
|
|
||||||
fsw.runErrCh <- errors.New("error sent while draining")
|
fsw.runErrCh <- errors.New("error sent while draining")
|
||||||
<-time.After(drainFor) // ensure draining is over
|
<-time.After(drainFor) // ensure draining is over
|
||||||
fsw.runTriggerCh <- struct{}{}
|
fsw.runTriggerCh <- struct{}{}
|
||||||
@@ -294,6 +292,10 @@ func (fsw *mockFSWatcher) Run() (chan struct{}, chan string, chan error) {
|
|||||||
return fsw.runTriggerCh, fsw.runEventCh, fsw.runErrCh
|
return fsw.runTriggerCh, fsw.runEventCh, fsw.runErrCh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fsw *mockFSWatcher) Enable() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// PSScanner
|
// PSScanner
|
||||||
|
|
||||||
type mockPSScanner struct {
|
type mockPSScanner struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user