Skip to content

Commit

Permalink
tetragon: improve systemd deployment detection
Browse files Browse the repository at this point in the history
When we are running as a systemd service, then tetragon
will run under a cgroup '$name.service' so match this.

Signed-off-by: Djalal Harouni <[email protected]>
  • Loading branch information
tixxdz committed Jun 20, 2024
1 parent 69b8cd4 commit 6941b73
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/cgroups/cgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ const (
type DeploymentCode int

type deploymentEnv struct {
id DeploymentCode
str string
id DeploymentCode
str string
endsWith string
}

const (
Expand Down Expand Up @@ -101,7 +102,9 @@ var (
{id: DEPLOY_CONTAINER, str: "docker"},
{id: DEPLOY_CONTAINER, str: "podman"},
{id: DEPLOY_CONTAINER, str: "libpod"},
{id: DEPLOY_SD_SERVICE, str: "system.slice"},
// If Tetragon is running as a systemd service, its
// cgroup path will end with .service
{id: DEPLOY_SD_SERVICE, endsWith: ".service"},
{id: DEPLOY_SD_USER, str: "user.slice"},
}

Expand Down Expand Up @@ -291,7 +294,10 @@ func setDeploymentMode(cgroupPath string) error {

// Last go through the deployments
for _, d := range deployments {
if strings.Contains(cgroupPath, d.str) {
if d.str != "" && strings.Contains(cgroupPath, d.str) {
deploymentMode = d.id
return nil
} else if d.endsWith != "" && strings.HasSuffix(cgroupPath, d.endsWith) == true {
deploymentMode = d.id
return nil
}
Expand Down

0 comments on commit 6941b73

Please sign in to comment.