Something filters out TMPDIR, even for classic snaps

As reported here

After snap install --classic go:

$ cat tmpdir.go
package main

import (

func main() {
 fmt.Printf("%q\n", os.Getenv("TMPDIR"))
$ TMPDIR=/tmp go run tmpdir.go
$ TMPDIR=/tmp /snap/bin/go run tmpdir.go

This is surprising.

I can see that there is code in snap-confine for setting TMPDIR, but that doesn’t run (afaict) for a classic snap, and anyway certainly doesn’t unset TMPDIR, rather the opposite…

So we found that the dynamic linked does unset TMPDIR (but not TEMPDIR) for setuid root executables… We also found a small bug in snap-confine where those two would only be set once (this is now

We could use a hack where snap-run would save those in, say, SNAPD_TMPDIR and snap-confine would restore TMPDIR to $SNAPD_TMPDIR but I’m not sure if this is worth the effort.