diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-04-25 16:35:28 -0400 |
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-04-25 16:35:28 -0400 |
| commit | 8f209a9ab8dfca02ce5c53f50d87919b7202e3f1 (patch) | |
| tree | 3887a54bc7dd16a8bfca02aac3001c013ca34058 /src/lib | |
| parent | 0d4b95442be1dcb72855a2384744d0e13cc4ee7d (diff) | |
| download | stasis-8f209a9ab8dfca02ce5c53f50d87919b7202e3f1.tar.gz | |
Set starting TMPDIR to /tmp/stasis
* Easier to remove leftover files, if any
* Now uses setenv() to have better control over external programs
* Removes the hack to initialize TMPDIR early
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/delivery/delivery_init.c | 44 |
1 files changed, 32 insertions, 12 deletions
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; } |
