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 */