Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create tempdir if it does not exist #222

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 */