From 4a2c753f4cc6698a2d1073f57c07230b103e4d3d Mon Sep 17 00:00:00 2001 From: Alexandru Negrila Date: Fri, 29 Apr 2022 10:45:32 +0300 Subject: [PATCH] Create tempdir if it does not exist. Otherwise it will generate an error. (credits: https://github.com/troglobit/libite/blob/master/src/makepath.c#L40) --- bootloader/main.c | 21 +++++++++++++++++++++ bootloader/util.h | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/bootloader/main.c b/bootloader/main.c index 10d5fc9..9c1309a 100644 --- a/bootloader/main.c +++ b/bootloader/main.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include "xz.h" #include "error.h" #include "mmap.h" @@ -205,10 +207,29 @@ patch_app(const char *prog_path) free(interp_path); } +int +mkpath(const char *dir, mode_t mode) +{ + struct stat sb; + + if (!dir) { + errno = EINVAL; + return -1; + } + + if (!stat(dir, &sb)) + return 0; + + mkpath(dirname(strdupa(dir)), mode); + + return mkdir(dir, mode); +} + static char * create_tmpdir(void) { const char *tmproot = getenv(TMPDIR) ?: "/tmp"; + mkpath(tmproot, 0755); char *template = path_join(tmproot, "staticx-XXXXXX"); char *tmpdir = mkdtemp(template); if (!tmpdir) diff --git a/bootloader/util.h b/bootloader/util.h index 903ee65..423f367 100644 --- a/bootloader/util.h +++ b/bootloader/util.h @@ -2,5 +2,5 @@ #define UTIL_H int remove_tree(const char *pathname); - +int mkpath (const char *dir, mode_t mode); #endif /* UTIL_H */