Skip to content

Commit fd98713

Browse files
committed
shell: fall back to /tmp if TMPDIR cannot be created
Problem: If a user inadvertently exports a TMPDIR that can't be created on the node on which the job eventually runs, then the tmpdir job shell plugin raises a fatal error. This can occur when the parent directory of TMPDIR doesn't exist on the system on which the job eventually runs. Instead of raising a fatal error, issue a warning in this case and fall back to /tmp for TMPDIR. Fixes #4328
1 parent 35080d5 commit fd98713

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/shell/tmpdir.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,24 @@ static int mkjobtmp_tmpdir (flux_shell_t *shell, char *buf, size_t size)
7171
return 0;
7272
}
7373

74-
static int mktmpdir (flux_shell_t *shell)
75-
{
76-
const char *tmpdir = flux_shell_getenv (shell, "TMPDIR");
77-
78-
if (tmpdir && mkdir_exist_ok (tmpdir, false) < 0)
79-
return -1;
80-
return 0;
81-
}
82-
8374
static int tmpdir_init (flux_plugin_t *p,
8475
const char *topic,
8576
flux_plugin_arg_t *args,
8677
void *data)
8778
{
8879
flux_shell_t *shell = flux_plugin_get_shell (p);
80+
const char *tmpdir = flux_shell_getenv (shell, "TMPDIR");
8981
char jobtmp[1024];
9082

91-
/* Ensure TMPDIR exists if it is set in job environment
83+
/* Attempt to create TMPDIR if set. If this fails, fallback to /tmp.
9284
*/
93-
if (mktmpdir (shell) < 0)
94-
shell_die_errno (1, "error creating TMPDIR");
85+
if (tmpdir && mkdir_exist_ok (tmpdir, true) < 0) {
86+
shell_warn ("Unable to create TMPDIR=%s, resetting TMPDIR=/tmp",
87+
tmpdir);
88+
tmpdir = "/tmp";
89+
if (flux_shell_setenvf (shell, 1, "TMPDIR", "%s", tmpdir) < 0)
90+
shell_die_errno (1, "Unable to set TMPDIR=/tmp");
91+
}
9592

9693
/* Try to create jobtmp in broker rundir.
9794
* Fall back to ${TMPDIR:-/tmp} if that fails (e.g. guest user).

0 commit comments

Comments
 (0)