common/utils: introduce tmpdir_mkstemp; use it

Various unit tests were creating temporary files unconditionally in /tmp
and were not cleaning up after themselves. Introduce a new variant of
mkstemp(3p) that respects the TMPDIR environment variable, and use it in
the offending unit tests. This allows each test run to use a dedicated
TMPDIR that can be cleaned up after the run.

Changelog-None

Signed-off-by: Matt Whitlock <c-lightning@mattwhitlock.name>
This commit is contained in:
Matt Whitlock
2021-12-05 02:47:38 -05:00
committed by Rusty Russell
parent 5284ee4dae
commit 1f79aad830
8 changed files with 38 additions and 12 deletions

View File

@@ -152,4 +152,8 @@ STRUCTEQ_DEF(ripemd160, 0, u);
/* Context which all wally allocations use (see common/setup.c) */
extern const tal_t *wally_tal_ctx;
/* Like mkstemp but resolves template relative to $TMPDIR (or /tmp if unset).
* Returns created temporary path name at *created if successful. */
int tmpdir_mkstemp(const tal_t *ctx, const char *template TAKES, char **created);
#endif /* LIGHTNING_COMMON_UTILS_H */