Skip to content

Commit

Permalink
Create tempdir if it does not exist. Otherwise it will generate an er…
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru Negrila committed Apr 29, 2022
1 parent 819d8ea commit 4a2c753
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions bootloader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <fcntl.h>
#include <elf.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <libgen.h>
#include "xz.h"
#include "error.h"
#include "mmap.h"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion bootloader/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#define UTIL_H

int remove_tree(const char *pathname);

int mkpath (const char *dir, mode_t mode);
#endif /* UTIL_H */

0 comments on commit 4a2c753

Please sign in to comment.