Skip to content

Commit

Permalink
flux: FLUX_JOB_ID not always set in flux-core v0.46
Browse files Browse the repository at this point in the history
Starting with flux-core v0.46, environment variable FLUX_JOB_ID is
not set for processes running in an allocation, but not launched by
flux, for example

$ mini alloc -n1 -t3
$ set | grep FLUX

See
* 485743d19 broker: clear job environment vars in rc scripts

in flux-core for more details.

In this case, a job ID still exists, and can be obtained with
flux_attr_get().
  • Loading branch information
ofaaland authored and morrone committed Jan 11, 2023
1 parent bc90483 commit 8c17600
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/flux/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,38 @@ int internal_init(int verb)

_yogrt_verbosity = verb;
jobid_valid = 0;
flux_t *h = NULL;
flux_error_t error;

/*
* If the process was run by flux, it has FLUX_JOB_ID set. If not run
* by flux, but in allocation, we have to ask for the job ID. For example,
* $flux mini alloc -n1 -t3
* $./my_app
* would use the flux_attr_get() call.
*/
if ((jobid_str = getenv("FLUX_JOB_ID")) == NULL) {
error("ERROR: FLUX_JOB_ID is not set."
" Remaining time will be a bogus value.\n");
return jobid_valid;
if (!(h = flux_open_ex(NULL, 0, &error))) {
error("ERROR: flux_open() failed with error %s\n", error.text);
goto out;
}
if ((jobid_str = flux_attr_get(h, "jobid")) == NULL) {
error("ERROR: Unable to fetch Flux 'jobid' attribute.\n"
" Remaining time will be a bogus value.\n");
goto out;
}
}

if (flux_job_id_parse(jobid_str, &jobid) < 0) {
error("ERROR: Unable to parse FLUX_JOB_ID %s."
error("ERROR: Unable to parse FLUX_JOB_ID %s.\n"
" Remaining time will be a bogus value.\n", jobid_str);
return jobid_valid;
goto out;
}

jobid_valid = 1;

out:
flux_close(h);
return jobid_valid;
}

Expand All @@ -79,7 +96,7 @@ int internal_get_rem_time(time_t now, time_t last_update, int cached)
return BOGUS_TIME;
}

if (!(h = flux_open_ex(NULL, 0, &error))) {
if ((h = flux_open_ex(NULL, 0, &error)) == NULL) {
error("ERROR: flux_open() failed with error %s\n", error.text);
goto out;
}
Expand Down

0 comments on commit 8c17600

Please sign in to comment.