diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cli/stasis/system_requirements.c | 4 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/stasis_indexer_main.c | 8 | ||||
| -rw-r--r-- | src/lib/delivery/delivery_init.c | 44 |
3 files changed, 39 insertions, 17 deletions
diff --git a/src/cli/stasis/system_requirements.c b/src/cli/stasis/system_requirements.c index 0f0aae8..ebfbffc 100644 --- a/src/cli/stasis/system_requirements.c +++ b/src/cli/stasis/system_requirements.c @@ -38,10 +38,6 @@ void check_system_requirements(struct Delivery *ctx) { msg(STASIS_MSG_RESTRICT, "found\n"); } - if (!globals.tmpdir && !ctx->storage.tmpdir) { - delivery_init_tmpdir(ctx); - } - msg(STASIS_MSG_L2, "Docker\n"); if (docker_capable(&ctx->deploy.docker.capabilities)) { struct DockerCapabilities *dcap = &ctx->deploy.docker.capabilities; diff --git a/src/cli/stasis_indexer/stasis_indexer_main.c b/src/cli/stasis_indexer/stasis_indexer_main.c index 5a92014..d71c341 100644 --- a/src/cli/stasis_indexer/stasis_indexer_main.c +++ b/src/cli/stasis_indexer/stasis_indexer_main.c @@ -274,8 +274,14 @@ int main(const int argc, char *argv[]) { if (system_tmp) { strncat(workdir_template, system_tmp, sizeof(workdir_template) - strlen(workdir_template) - 1); } else { - strncat(workdir_template, "/tmp", sizeof(workdir_template) - strlen(workdir_template) - 1); + strncat(workdir_template, "/tmp/stasis", sizeof(workdir_template) - strlen(workdir_template) - 1); } + + if (mkdirs(workdir_template, 0700)) { + SYSERROR("Unable to create directory '%s': %s", workdir_template, strerror(errno)); + exit(1); + } + strncat(workdir_template, "/stasis-combine.XXXXXX", sizeof(workdir_template) - strlen(workdir_template) - 1); char *workdir = mkdtemp(workdir_template); if (!workdir) { diff --git a/src/lib/delivery/delivery_init.c b/src/lib/delivery/delivery_init.c index 9a2f6c3..17f3899 100644 --- a/src/lib/delivery/delivery_init.c +++ b/src/lib/delivery/delivery_init.c @@ -11,24 +11,43 @@ int has_mount_flags(const char *mount_point, const unsigned long flags) { int delivery_init_tmpdir(struct Delivery *ctx) { char *tmpdir = NULL; - char *x = NULL; int unusable = 1; errno = 0; - x = getenv("TMPDIR"); + int need_setenv = 0; + const char *x = getenv("TMPDIR"); if (x) { guard_free(ctx->storage.tmpdir); tmpdir = strdup(x); + if (!tmpdir) { + // memory error + SYSERROR("%s", "unable to allocate tmpdir"); + goto l_delivery_init_tmpdir_fatal; + } } else { - tmpdir = ctx->storage.tmpdir; + tmpdir = strdup("/tmp/stasis"); + if (!tmpdir) { + SYSERROR("%s", "unable to allocate tmpdir"); + goto l_delivery_init_tmpdir_fatal; + } + need_setenv = 1; } - if (!tmpdir) { - // memory error - SYSERROR("%s", "unable to allocate tmpdir"); - goto l_delivery_init_tmpdir_fatal; + if (!ctx->storage.tmpdir) { + ctx->storage.tmpdir = strdup(tmpdir); + if (!ctx->storage.tmpdir) { + SYSERROR("%s", "unable to allocate ctx->storage.tmpdir"); + goto l_delivery_init_tmpdir_fatal; + } + } else { + // we already have a temp directory to use + guard_free(tmpdir); + tmpdir = strdup(ctx->storage.tmpdir); + if (!tmpdir) { + SYSERROR("%s", "unable to allocate tmpdir"); + goto l_delivery_init_tmpdir_fatal; + } } - // If the directory doesn't exist, create it if (access(tmpdir, F_OK) < 0) { if (mkdirs(tmpdir, 0755) < 0) { @@ -60,7 +79,7 @@ int delivery_init_tmpdir(struct Delivery *ctx) { goto l_delivery_init_tmpdir_fatal; } - if (!globals.tmpdir) { + if (!globals.tmpdir || strcmp(globals.tmpdir, ctx->storage.tmpdir) != 0) { globals.tmpdir = strdup(tmpdir); if (!globals.tmpdir) { SYSERROR("%s", "unable to allocate globals.tmpdir"); @@ -76,11 +95,12 @@ int delivery_init_tmpdir(struct Delivery *ctx) { } } unusable = 0; + if (need_setenv) { + setenv("TMPDIR", ctx->storage.tmpdir, 1); + } l_delivery_init_tmpdir_fatal: - if (unusable) { - guard_free(tmpdir); - } + guard_free(tmpdir); return unusable; } |
