]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
sync: add SAFCM_HELPER environment variable to commands
authorSimon Ruderich <simon@ruderich.org>
Sun, 4 Apr 2021 19:27:31 +0000 (21:27 +0200)
committerSimon Ruderich <simon@ruderich.org>
Mon, 5 Apr 2021 07:41:12 +0000 (09:41 +0200)
Contains the absolute path to the remote helper binary. Will be useful
in the future when the remote helper gets additional subcommands.

cmd/safcm-remote/sync/commands.go
cmd/safcm-remote/sync/commands_test.go

index abc23bcc42a8af74264df5a8e095416a1433791f..e3c48dd10e4df6d78ff0242439b462d16364ba14 100644 (file)
@@ -79,10 +79,15 @@ func (s *Sync) syncCommand(command string, trigger string) error {
 }
 
 func safcmEnviroment(groups []string) []string {
+       exe, err := os.Executable()
+       if err != nil {
+               panic(err) // should not happen on supported systems
+       }
+
        env := os.Environ()
-       // Provide additional environment variables so commands can check
-       // group membership
+       // Provide additional environment variables
        env = append(env,
+               fmt.Sprintf("SAFCM_HELPER=%s", exe),
                fmt.Sprintf("SAFCM_GROUPS=%s", strings.Join(groups, " ")))
        for _, x := range groups {
                env = append(env, fmt.Sprintf("SAFCM_GROUP_%s=%s", x, x))
index aeeea32f0ce2233ad281f755312024e232beda8a..1b1adf71768dc0b8027c8bb0bd7edfd7c2e30156 100644 (file)
@@ -29,7 +29,12 @@ import (
 )
 
 func TestSyncCommands(t *testing.T) {
+       exe, err := os.Executable()
+       if err != nil {
+               t.Fatal(err)
+       }
        env := append(os.Environ(),
+               "SAFCM_HELPER="+exe,
                "SAFCM_GROUPS=all group1 group2 host.example.org",
                "SAFCM_GROUP_all=all",
                "SAFCM_GROUP_group1=group1",