Skip to content
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,27 @@ endif
# for your distribution (look for libre2.a). See the Dockerfile for an example of how to build it.
BUILD_STATIC ?= 0

# Enable this to run the data race detector in staging builds or bats tests.
# Mutually exclusive with BUILD_STATIC, slows down the execution (tests take 4x as long)
RACE_DETECT ?= 1

# List of notification plugins to build
PLUGINS ?= $(patsubst ./cmd/notification-%,%,$(wildcard ./cmd/notification-*))

# Configure race detector.

GORACE_OPTS :=
GORACE :=

ifeq ($(RACE_DETECT),1)
GORACE_OPTS := -race
export GORACE := halt_on_error=0 exitcode=66 strip_path_prefix=$(shell pwd)/ log_path=/tmp/race
export CGO_ENABLED := 1
endif

export GORACE_OPTS
export GORACE

#--------------------------------------

GO = go
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ifeq ($(OS), Windows_NT)
endif

GO = go
GOBUILD = $(GO) build
GOBUILD = $(GO) build $(GORACE_OPTS)

BINARY_NAME = cscli$(EXT)

Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ifeq ($(OS), Windows_NT)
endif

GO = go
GOBUILD = $(GO) build
GOBUILD = $(GO) build $(GORACE_OPTS)
GOTEST = $(GO) test

CROWDSEC_BIN = crowdsec$(EXT)
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func serveAPIServer(ctx context.Context, apiServer *apiserver.APIServer) {
}()

pluginTomb.Go(func() error {
pluginBroker.Run(&pluginTomb)
pluginBroker.Run(pluginTomb)
return nil
})

Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec/crowdsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func runCrowdsec(

log.Info("Starting processing data")

if err := acquisition.StartAcquisition(ctx, datasources, logLines, &acquisTomb); err != nil {
if err := acquisition.StartAcquisition(ctx, datasources, logLines, acquisTomb); err != nil {
return fmt.Errorf("starting acquisition error: %w", err)
}

Expand Down
18 changes: 13 additions & 5 deletions cmd/crowdsec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import (

var (
// tombs for the parser, buckets and outputs.
acquisTomb tomb.Tomb
outputsTomb tomb.Tomb
apiTomb tomb.Tomb
crowdsecTomb tomb.Tomb
pluginTomb tomb.Tomb
acquisTomb *tomb.Tomb
outputsTomb *tomb.Tomb
apiTomb *tomb.Tomb
crowdsecTomb *tomb.Tomb
pluginTomb *tomb.Tomb

flags Flags

Expand All @@ -48,6 +48,14 @@ var (
pluginBroker csplugin.PluginBroker
)

func initTombs() {
acquisTomb = &tomb.Tomb{}
outputsTomb = &tomb.Tomb{}
apiTomb = &tomb.Tomb{}
crowdsecTomb = &tomb.Tomb{}
pluginTomb = &tomb.Tomb{}
}

func LoadBuckets(cConfig *csconfig.Config, hub *cwhub.Hub) error {
var err error

Expand Down
34 changes: 18 additions & 16 deletions cmd/crowdsec/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
"gopkg.in/tomb.v2"

"github.com/crowdsecurity/go-cs-lib/csdaemon"
"github.com/crowdsecurity/go-cs-lib/trace"
Expand All @@ -27,12 +26,7 @@ import (
)

func reloadHandler(ctx context.Context, _ os.Signal) (*csconfig.Config, error) {
// re-initialize tombs
acquisTomb = tomb.Tomb{}
outputsTomb = tomb.Tomb{}
apiTomb = tomb.Tomb{}
crowdsecTomb = tomb.Tomb{}
pluginTomb = tomb.Tomb{}
initTombs()

sd := NewStateDumper(flags.DumpDir)

Expand Down Expand Up @@ -161,27 +155,39 @@ func ShutdownCrowdsecRoutines(cancel context.CancelFunc, g *errgroup.Group, data
}

func shutdownAPI() error {
log.Debugf("shutting down api via Tomb")
if apiTomb == nil {
log.Debug("apiTomb is nil")
return nil
}

log.Debug("shutting down api via Tomb")

apiTomb.Kill(nil)

if err := apiTomb.Wait(); err != nil {
return err
}

log.Debugf("done")
log.Debug("done")

return nil
}

func shutdownCrowdsec() error {
log.Debugf("shutting down crowdsec via Tomb")
if crowdsecTomb == nil {
log.Debug("crowdsecTomb is nil")
return nil
}

log.Debug("shutting down crowdsec via Tomb")

crowdsecTomb.Kill(nil)

if err := crowdsecTomb.Wait(); err != nil {
return err
}

log.Debugf("done")
log.Debug("done")

return nil
}
Expand Down Expand Up @@ -310,11 +316,7 @@ func Serve(
agentReady chan bool,
sd *StateDumper,
) error {
acquisTomb = tomb.Tomb{}
outputsTomb = tomb.Tomb{}
apiTomb = tomb.Tomb{}
crowdsecTomb = tomb.Tomb{}
pluginTomb = tomb.Tomb{}
initTombs()

if cConfig.API.Server != nil && cConfig.API.Server.DbConfig != nil {
dbCfg := cConfig.API.Server.DbConfig
Expand Down
2 changes: 1 addition & 1 deletion cmd/notification-dummy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ifeq ($(OS), Windows_NT)
endif

GO = go
GOBUILD = $(GO) build
GOBUILD = $(GO) build $(GORACE_OPTS)

BINARY_NAME = notification-dummy$(EXT)

Expand Down
2 changes: 1 addition & 1 deletion cmd/notification-email/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ifeq ($(OS), Windows_NT)
endif

GO = go
GOBUILD = $(GO) build
GOBUILD = $(GO) build $(GORACE_OPTS)

BINARY_NAME = notification-email$(EXT)

Expand Down
2 changes: 1 addition & 1 deletion cmd/notification-file/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ifeq ($(OS), Windows_NT)
endif

GO = go
GOBUILD = $(GO) build
GOBUILD = $(GO) build $(GORACE_OPTS)

BINARY_NAME = notification-file$(EXT)

Expand Down
2 changes: 1 addition & 1 deletion cmd/notification-http/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ifeq ($(OS), Windows_NT)
endif

GO = go
GOBUILD = $(GO) build
GOBUILD = $(GO) build $(GORACE_OPTS)

BINARY_NAME = notification-http$(EXT)

Expand Down
2 changes: 1 addition & 1 deletion cmd/notification-sentinel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ifeq ($(OS), Windows_NT)
endif

GO = go
GOBUILD = $(GO) build
GOBUILD = $(GO) build $(GORACE_OPTS)

BINARY_NAME = notification-sentinel$(EXT)

Expand Down
2 changes: 1 addition & 1 deletion cmd/notification-slack/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ifeq ($(OS), Windows_NT)
endif

GO = go
GOBUILD = $(GO) build
GOBUILD = $(GO) build $(GORACE_OPTS)

BINARY_NAME = notification-slack$(EXT)

Expand Down
2 changes: 1 addition & 1 deletion cmd/notification-splunk/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ifeq ($(OS), Windows_NT)
endif

GO = go
GOBUILD = $(GO) build
GOBUILD = $(GO) build $(GORACE_OPTS)

BINARY_NAME = notification-splunk$(EXT)

Expand Down
Loading