Commit Graph

13 Commits

Author SHA1 Message Date
Leah Rowe
f06db344ad mkhtemp: fix err()
calling it indirectly was out of the question.

must call it directly.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-25 00:03:31 +00:00
Leah Rowe
3ddd7a0d36 util/mkhtemp: add -q option (silence errors)
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-24 23:31:51 +00:00
Leah Rowe
1ed2ca6b69 util/libreboot-utils: rename err() to b0rk()
it behaves a bit differently than err(), so it's
not good to confuse readers

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-24 22:44:27 +00:00
Leah Rowe
f8d9c51a36 util/mkhtemp: template support on util
just add a template like yo uwould on other mktemp.
it works perfectly now.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-24 22:19:40 +00:00
Leah Rowe
88ff5f7380 util/mkhtemp: O_TMPFILE fast path on linux
linux itself provides much of the hardening we need,
and avoids the need for some of our tests. use this
on linux (fall back to openat still, on e.g. bsd)

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-24 19:57:12 +00:00
Leah Rowe
3522a23587 util/nvmutil: use renameat for atomic write
not rename(). use renameat()

this re-uses the logic added for mkhtemp.

this will later enable more stringent
integrity checks, though we already verify
the integrity of a file after writing it
back, and renameat is always tied to the
descriptor, so it's fine.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-24 19:19:33 +00:00
Leah Rowe
c1befbcd3e util/nvmutil: never do cross-filesystem moves
make a local TMPDIR instead, where gbe.bin is.
this avoids the EXDEV errno, so we don't have
to handle it, and it's just better performant
for everyone.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-24 18:46:36 +00:00
Leah Rowe
e9c5da1a25 util/nvmutil: use new fs_open functions for gbe
this unifies nvmutil's file handling with the
handling used by mkhtemp. a special function
has been written for this. this allows greater
flexibility since we can more easily check the
integrity of a file at inode/dev level; this
complements nvmutil's existing content-based
verification.

(this also fixes nvmutil, so that gbe files can
be changed again. mkhtemp broke it while i was
writing it, but now everything works again)

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-24 17:18:47 +00:00
Leah Rowe
56ab5a18fe mkhtemp: show progname on error
i have my own getprogname implementation,
because not every libc is good enough to
include one.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-24 16:35:40 +00:00
Leah Rowe
cce396a1ac libreboot-utils: general code cleanup
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-24 09:48:34 +00:00
Leah Rowe
e7ede0c755 mkhtemp: unified non-error close handling
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-24 07:06:39 +00:00
Leah Rowe
2c21a04741 util/mkhtemp: show path on error accessing it
a bit naughty the way i do it, but it works. without
this, the message gets clobbered by EINVAL due to
a bad call to vprintf in the err function.

in this way, we ensure that there is a path, and
thus the errno does not get clobbered. i also
removed the EPERM setting in the env_tmpdir
function, which also clobbered errno.

with this fix, if TMPDIR is set but invalid,
it should now show the error reliably.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-24 02:41:53 +00:00
Leah Rowe
f2544d094b util/mkhtemp: new utility (hardened mktemp)
part of the same code library as nvmutil.

as part of this, i renamed util/nvmutil
to util/libreboot-utils/ because it is
now a multi-utility codebase.

this is more efficient, since i also wish
to use mkhtemp (function) in nvmutil.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-24 01:25:53 +00:00