Skip to content

Commit

Permalink
syscall: fix Clearenv on Plan 9
Browse files Browse the repository at this point in the history
Update #25234
Fixes #35083

Change-Id: Ida39516ab1c14a34a62c2232476a75e83f4e3f75
Reviewed-on: https://go-review.googlesource.com/c/go/+/202657
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
fhs authored and bradfitz committed Oct 23, 2019
1 parent 7833302 commit b284dac
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/syscall/env_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,21 @@ func Setenv(key, value string) error {
}

func Clearenv() {
RawSyscall(SYS_RFORK, RFCENVG, 0, 0)
// Creating a new environment group using rfork(RFCENVG) can race
// with access to files in /env (e.g. from Setenv or Getenv).
// Remove all environment variables in current environment group instead.
fd, err := open("/env", O_RDONLY)
if err != nil {
return
}
defer Close(fd)
files, err := readdirnames(fd)
if err != nil {
return
}
for _, key := range files {
Remove("/env/" + key)
}
}

func Unsetenv(key string) error {
Expand Down

0 comments on commit b284dac

Please sign in to comment.