Setting environment variable TMPDIR can lead to undesired side-effects

187 views
Skip to first unread message

Jasper Orschulko

unread,
Jul 26, 2023, 2:00:11 PM7/26/23
to kas-...@googlegroups.com
Hi all,

as far as I understand the "TMPDIR" environment variable documented at
https://kas.readthedocs.io/en/latest/command-line.html#environment-variables
is meant to correspond to the TMPDIR variable documented in the yocto
docs: https://docs.yoctoproject.org/singleindex.html#term-TMPDIR?

If this is the case, then setting it as environment variable can cause
some undesired side-effects, as this variable has a special meaning in
(at least some) shell environments, defining the system-wide temp
directory, as seen here:

➜ ~ docker run --rm debian:bookworm-slim /bin/bash -c "mktemp"
/tmp/tmp.HUIWX7dhxM

vs.

➜ ~ docker run --rm -e TMPDIR=/mnt debian:bookworm-slim /bin/bash -c
"mktemp"
/mnt/tmp.BBdYvSMn4U

This caused me quite some headache after I set this variable as part of
a bigger change within our gitlab ci pipeline in an attempt to avoid
hardcoding this in various scripts and suddently gitlab ci internal
steps started failing:

Downloading artifacts for develop-ci-build-setup (65293)...
FATAL: open /builds/build/tmp/artifacts856143953: no such file or
directory

This could also cause the yocto temp dir to be cluttered with non-yocto
related temp files.

I am therefore wondering if it would be possible to change the
environment variable name for configuring the build tmpdir to something
without a special meaning, such as YOCTO_TMPDIR (I am not quite sure
how this passthrough from env var to yocto var works internally)? What
do you think? Is this an issue you are aware of?

Cheers, Jasper

Jan Kiszka

unread,
Aug 8, 2023, 3:02:22 AM8/8/23
to Jasper Orschulko, kas-...@googlegroups.com
Not sure yet if you are barking at the right tree: kas is only allowing
to forward the TMPDIR value set in the caller env into the curated
bitbake env. And that is because bitbake officially evaluates this. To
no degree, kas does more than this forwarding and documenting that:

# git grep TMPDIR
docs/command-line.rst:| ``TMPDIR`` | |
kas/libkas.py: env_vars = ['SSTATE_DIR', 'DL_DIR', 'TMPDIR']

Jan

--
Siemens AG, Technology
Linux Expert Center

Jasper Orschulko

unread,
Aug 10, 2023, 9:02:53 AM8/10/23
to jan.k...@siemens.com, kas-...@googlegroups.com
Hi Jan,

thanks for your response, that clearifies a lot for me and I can
confirm that a

TMPDIR=foo kas

works as you describe.

I still think this is a valid concern however, as developers might be
tempted to export this variable in their script before calling kas (as
in my case), e.g.:

```
export TMPDIR=/foo # this will cause problems
kas ...
```

vs.

```
TMPDIR=/foo kas ... # this is fine
```

But I understand why you would want to stick with "TMPDIR" to stay
aligned with upstream terminology.

Maybe this is something that could be resolved by documentation? If
you'd be happy with that I'd send in a patch that adds a brief warning
about not exporting the TMPDIR variable before calling kas at
https://kas.readthedocs.io/en/latest/command-line.html#environment-variables
.

Cheers,
Jasper

Jan Kiszka

unread,
Aug 10, 2023, 10:26:58 AM8/10/23
to Jasper Orschulko, kas-...@googlegroups.com
On 10.08.23 15:02, 'Jasper Orschulko' via kas-devel wrote:
> Hi Jan,
>
> thanks for your response, that clearifies a lot for me and I can
> confirm that a
>
> TMPDIR=foo kas
>
> works as you describe.
>
> I still think this is a valid concern however, as developers might be
> tempted to export this variable in their script before calling kas (as
> in my case), e.g.:
>
> ```
> export TMPDIR=/foo # this will cause problems
> kas ...
> ```
>

I'm still not sure to get where exactly this is causing problems. To
commands following later after "kas" in that script? But that would be
common knowledge, nothing bitbake or kas related.

Jan
Reply all
Reply to author
Forward
0 new messages