Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
33 changes: 0 additions & 33 deletions Gopkg.lock

This file was deleted.

38 changes: 0 additions & 38 deletions Gopkg.toml

This file was deleted.

16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,30 @@ build:
docker run -it \
--rm \
-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 GOOS=linux \
--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 \
--rm \
-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 GOOS=linux \
--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 \
--rm \
-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 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 \
--rm \
-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 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"
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ Inotify watchers placed on selected parts of the file system trigger these scans

Get the tool onto the Linux machine you want to inspect.
First get the binaries. Download the released binaries here:
- 32 bit big, static version: `pspy32` [download](https://github.com/DominicBreuker/pspy/releases/download/v1.2.0/pspy32)
- 64 bit big, static version: `pspy64` [download](https://github.com/DominicBreuker/pspy/releases/download/v1.2.0/pspy64)
- 32 bit small version: `pspy32s` [download](https://github.com/DominicBreuker/pspy/releases/download/v1.2.0/pspy32s)
- 64 bit small version: `pspy64s` [download](https://github.com/DominicBreuker/pspy/releases/download/v1.2.0/pspy64s)
- 32 bit big, static version: `pspy32` [download](https://github.com/DominicBreuker/pspy/releases/download/v1.2.1/pspy32)
- 64 bit big, static version: `pspy64` [download](https://github.com/DominicBreuker/pspy/releases/download/v1.2.1/pspy64)
- 32 bit small version: `pspy32s` [download](https://github.com/DominicBreuker/pspy/releases/download/v1.2.1/pspy32s)
- 64 bit small version: `pspy64s` [download](https://github.com/DominicBreuker/pspy/releases/download/v1.2.1/pspy64s)

The statically compiled files should work on any Linux system but are quite huge (~4MB).
If size is an issue, try the smaller versions which depend on libc and are compressed with UPX (~1MB).
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM golang:1.12-stretch
FROM golang:1.26-trixie

RUN apt-get update && apt-get install -y upx && rm -rf /var/lib/apt/lists/*
2 changes: 1 addition & 1 deletion docker/Dockerfile.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.12-stretch
FROM golang:1.26-trixie

RUN apt-get update && apt-get -y install cron python3 sudo procps

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:stretch
FROM debian:bookworm

RUN apt-get update && apt-get -y install cron python3 sudo procps

Expand Down
5 changes: 3 additions & 2 deletions docker/Dockerfile.testing
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.12-stretch
FROM golang:1.26-trixie

RUN apt-get update && apt-get -y install cron python3 sudo procps

Expand All @@ -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 cmd /go/src/github.com/dominicbreuker/pspy/cmd
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

# run tests
Expand Down
2 changes: 1 addition & 1 deletion docker/entrypoint-development.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

sudo cron -f &
sleep 1
sudo ps | grep cron 1>/dev/null
ps -auxf | grep cron 1>/dev/null
echo "[+] cron started"

echo "[+] Running as user `id`"
Expand Down
2 changes: 1 addition & 1 deletion docker/entrypoint-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

sudo cron -f &
sleep 1
sudo ps | grep cron 1>/dev/null
ps -auxf | grep cron 1>/dev/null
echo "[+] cron started"

echo "[+] Running as user `id`"
Expand Down
2 changes: 1 addition & 1 deletion docker/entrypoint-testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fi

sudo cron -f &
sleep 1
sudo ps | grep cron 1>/dev/null
ps -auxf | grep cron 1>/dev/null
echo "[+] cron started"

echo "[+] Running as user `id`"
Expand Down
13 changes: 13 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/dominicbreuker/pspy

go 1.26

require (
github.com/spf13/cobra v1.4.0
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
)

require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
12 changes: 11 additions & 1 deletion internal/fswatcher/fswatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type FSWatcher struct {
w Walker
maxWatchers int
eventSize int
drain bool
}

func NewFSWatcher() *FSWatcher {
Expand All @@ -33,9 +34,14 @@ func NewFSWatcher() *FSWatcher {
w: walker.NewWalker(),
maxWatchers: inotify.MaxWatchers,
eventSize: inotify.EventSize,
drain: true,
}
}

func (fs *FSWatcher) Enable() {
fs.drain = false
}

func (fs *FSWatcher) Close() {
fs.i.Close()
}
Expand Down Expand Up @@ -96,7 +102,7 @@ func (fs *FSWatcher) handleNextWalkerResult(dirCh chan string, walkErrCh chan er
return true
}
if err := fs.i.Watch(dir); err != nil {
errCh <- fmt.Errorf("Can't create watcher: %v", err)
errCh <- fmt.Errorf("can't create watcher: %v", err)
}
}
return false
Expand All @@ -116,6 +122,10 @@ func (fs *FSWatcher) observe(triggerCh chan struct{}, dataCh chan []byte, errCh

for {
n, err := fs.i.Read(buf)
if fs.drain {
continue
}

triggerCh <- struct{}{}
if err != nil {
errCh <- fmt.Errorf("reading inotify buffer: %v", err)
Expand Down
8 changes: 4 additions & 4 deletions internal/pspy/pspy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Logger interface {
type FSWatcher interface {
Init(rdirs, dirs []string) (chan error, chan struct{})
Run() (chan struct{}, chan string, chan error)
Enable()
}

type PSScanner interface {
Expand Down Expand Up @@ -110,7 +111,7 @@ func startFSW(fsw FSWatcher, logger Logger, drainFor time.Duration, sigCh <-chan

// ignore all file system events created on 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")
return
}
Expand All @@ -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 {
select {
case <-sigCh:
return false
case <-triggerCh:
case <-eventCh:
case <-time.After(d):
fsw.Enable()
return true
}
}
Expand Down
6 changes: 4 additions & 2 deletions internal/pspy/pspy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ func TestStartFSW(t *testing.T) {
sigCh := make(chan os.Signal)

go func() {
fsw.runTriggerCh <- struct{}{} // trigger sent while draining
fsw.runEventCh <- "event sent while draining"
fsw.runErrCh <- errors.New("error sent while draining")
<-time.After(drainFor) // ensure draining is over
fsw.runTriggerCh <- struct{}{}
Expand Down Expand Up @@ -294,6 +292,10 @@ func (fsw *mockFSWatcher) Run() (chan struct{}, chan string, chan error) {
return fsw.runTriggerCh, fsw.runEventCh, fsw.runErrCh
}

func (fsw *mockFSWatcher) Enable() {
return
}

// PSScanner

type mockPSScanner struct {
Expand Down
13 changes: 0 additions & 13 deletions vendor/github.com/inconshreveable/mousetrap/LICENSE

This file was deleted.

23 changes: 0 additions & 23 deletions vendor/github.com/inconshreveable/mousetrap/README.md

This file was deleted.

15 changes: 0 additions & 15 deletions vendor/github.com/inconshreveable/mousetrap/trap_others.go

This file was deleted.

Loading