Commit Graph

17 Commits

Author SHA1 Message Date
Leah Rowe
2c211d385e fix variable name
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 19:16:32 +00:00
Leah Rowe
e55f7ea081 util/nvmutil: re-add fallback timer rand
for 1989

enabled via ifdef. not enabled by default.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 19:11:08 +00:00
Leah Rowe
0229e84539 util/nvmutil: remove arandom fallback on rand
openbsd 2.1 has arc4random, which we detect here.

arandom was apparently added much later, so this
is dead code. remove it.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 18:36:59 +00:00
Leah Rowe
f8b07dba29 util/nvmutil: rand: use getrandom on newer linux
we still fall back to the old /dev/urandom read
on older linux, via runtime detection (ENOSYS).

getrandom is better, because it guarantees entropy
via blocking, and works even when /dev/urandom
is unavailable.

it has the same practical benefit as arc4random,
which i use on bsd. linux can have arc4random,
but not every linux libc has it, so it's better
to use getrandom on linux.

older linux will fall back to /dev/urandom

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 18:34:28 +00:00
Leah Rowe
7c66a788bd util/nvmutil: buffered urandom reads
also generally tidied the code and made
it more robust e.g. retries

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 18:04:33 +00:00
Leah Rowe
55f006318a tidy some comments
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 16:02:15 +00:00
Leah Rowe
7ad924a91f nvmutil: make tmpdir string much more random
more random characters

i added support for higher than the standard 6
characters so i can go nuts

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 08:50:09 +00:00
Leah Rowe
50300f846f util/nvmutil: hardened mkstemp
200 retries, not 100.

and open with O_NOFOLLOW and O_CLOEXEC

check X on mkstemp

support more than 6 X in mkstemp

make PATH_LEN 4096

1024 is a bit low

make default mkstemp length 4096

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 08:42:58 +00:00
Leah Rowe
4b35d9ac29 nvmutil: rename lseek_loop to lseek_on_eintr
that's what it does!

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 07:48:53 +00:00
Leah Rowe
1fbe972fa7 nvmutil: rename x_i_close to close_on_eintr
that's what it does. waits for eintr to stop firing

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 07:45:34 +00:00
Leah Rowe
dcf698b9a0 nvmutil: don't have finite eintr wait
this is technically incorrect. we don't control
faults in the hardware.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 07:43:43 +00:00
Leah Rowe
2eee2b5cac nvmutil: rename x_i_fsync to fsync_on_eintr
that's what it does. waits on eintr.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 07:41:04 +00:00
Leah Rowe
6d0bb47b82 util/rename: rename x_i_fsync
rename to fsync_on_eintr, because that's what it does

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 07:38:54 +00:00
Leah Rowe
846cb23585 nvmutil: remove memcmp/memcpy/strrchr/rename
i had this idea in my head of later porting this
to k&r c for fun. but screw it.

compiling on everything since 1989 is enough

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 07:37:53 +00:00
Leah Rowe
f1fda8b43e util/nvmutil: tidy up includes
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 07:22:03 +00:00
Leah Rowe
2ed8db3adc util/nvmutil: major cleanup
handle init in xstatus()

it's now a singleton design

also tidied up some other code

also removed todo.c. bloat.
will do all those anyway.

too much change. i just kept
touching the code until it
looked good

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-19 04:25:43 +00:00
Leah Rowe
594cc262f4 nvmutil: move lib files to lib/
only keep nvmutil.c in main

Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-03-18 14:20:06 +00:00