Skip to content
Snippets Groups Projects
Commit 42c6eae6 authored by Morris Jette's avatar Morris Jette
Browse files

sbatch environment setting mods

We replaced references to "pipe" with a more generic "file descriptor".
We also replaced a while loop in env.c with a for loop.
parent 08fce8ee
No related branches found
No related tags found
No related merge requests found
...@@ -376,12 +376,12 @@ option will implicitly be set to load other environment variables based upon ...@@ -376,12 +376,12 @@ option will implicitly be set to load other environment variables based upon
the user's configuration on the cluster which executes the job. the user's configuration on the cluster which executes the job.
.TP .TP
\fB\-\-export\-file\fR=<\fIfilename\fR | \fIpipe_fd\fR> \fB\-\-export\-file\fR=<\fIfilename\fR | \fIfd\fR>
If a number between 3 and OPEN_MAX is specified as the argument to If a number between 3 and OPEN_MAX is specified as the argument to
this option, a pipe's read file descriptor will be assumed (STDIN and this option, a readable file descriptor will be assumed (STDIN and
STDOUT are not supported as valid arguments). Otherwise a filename is STDOUT are not supported as valid arguments). Otherwise a filename is
assumed. Export environment variables defined in <\fIfilename\fR> or assumed. Export environment variables defined in <\fIfilename\fR> or
read from <\fIpipe_fd\fR> to the job's execution environment. The read from <\fIfd\fR> to the job's execution environment. The
content is one or more environment variable definitions of the form content is one or more environment variable definitions of the form
NAME=value, each separated by a null character. This allows the use NAME=value, each separated by a null character. This allows the use
of special characters in environment definitions. The of special characters in environment definitions. The
......
...@@ -1581,9 +1581,9 @@ static int _bracket_cnt(char *value) ...@@ -1581,9 +1581,9 @@ static int _bracket_cnt(char *value)
} }
/* /*
* Load user environment from a specified file or pipe. * Load user environment from a specified file or file descriptor.
* *
* This will read in a user specified file or pipe, that is invoked * This will read in a user specified file or fd, that is invoked
* via the --export-file option in sbatch. The NAME=value entries must * via the --export-file option in sbatch. The NAME=value entries must
* be NULL separated to support special characters in the environment * be NULL separated to support special characters in the environment
* definitions. * definitions.
...@@ -1596,7 +1596,7 @@ static int _bracket_cnt(char *value) ...@@ -1596,7 +1596,7 @@ static int _bracket_cnt(char *value)
char **env_array_from_file(const char *fname) char **env_array_from_file(const char *fname)
{ {
char *buf = NULL, *ptr = NULL, *eptr = NULL; char *buf = NULL, *ptr = NULL, *eptr = NULL;
char *line, *value, *p; char *value, *p;
char **env = NULL; char **env = NULL;
char name[256]; char name[256];
int buf_size = BUFSIZ, buf_left; int buf_size = BUFSIZ, buf_left;
...@@ -1605,7 +1605,8 @@ char **env_array_from_file(const char *fname) ...@@ -1605,7 +1605,8 @@ char **env_array_from_file(const char *fname)
int fd; int fd;
/* /*
* If file name is a numeric value, then it is assumed to be a pipe. * If file name is a numeric value, then it is assumed to be a
* file descriptor.
*/ */
fd = (int)strtol(fname, &p, 10); fd = (int)strtol(fname, &p, 10);
if ((*p != '\0') || (fd < 3) || (fd > sysconf(_SC_OPEN_MAX)) || if ((*p != '\0') || (fd < 3) || (fd > sysconf(_SC_OPEN_MAX)) ||
...@@ -1617,7 +1618,7 @@ char **env_array_from_file(const char *fname) ...@@ -1617,7 +1618,7 @@ char **env_array_from_file(const char *fname)
} }
verbose("Getting environment variables from %s", fname); verbose("Getting environment variables from %s", fname);
} else } else
verbose("Getting environment variables from pipe %d", fd); verbose("Getting environment variables from fd %d", fd);
/* /*
* Read in the user's environment data. * Read in the user's environment data.
...@@ -1647,25 +1648,18 @@ char **env_array_from_file(const char *fname) ...@@ -1647,25 +1648,18 @@ char **env_array_from_file(const char *fname)
* and build the environment. * and build the environment.
*/ */
env = env_array_create(); env = env_array_create();
line = xmalloc(ENV_BUFSIZE);
value = xmalloc(ENV_BUFSIZE); value = xmalloc(ENV_BUFSIZE);
ptr = buf; for (ptr = buf; ; ptr = eptr+1) {
while (ptr) {
memset(line, 0, ENV_BUFSIZE);
eptr = strchr(ptr, separator); eptr = strchr(ptr, separator);
if ((ptr == eptr) || (eptr == NULL)) if ((ptr == eptr) || (eptr == NULL))
break; break;
strncpy(line, ptr,(eptr - ptr)); if (_env_array_entry_splitter(ptr, name, sizeof(name),
ptr = eptr + 1;
if (_env_array_entry_splitter(line, name, sizeof(name),
value, ENV_BUFSIZE) && value, ENV_BUFSIZE) &&
(!_discard_env(name, value)) && (!_discard_env(name, value))) {
(name[0] != ' ')) {
env_array_overwrite(&env, name, value); env_array_overwrite(&env, name, value);
} }
} }
xfree(buf); xfree(buf);
xfree(line);
xfree(value); xfree(value);
return env; return env;
......
...@@ -2803,7 +2803,7 @@ static void _usage(void) ...@@ -2803,7 +2803,7 @@ static void _usage(void)
" [--network=type] [--mem-per-cpu=MB] [--qos=qos] [--gres=list]\n" " [--network=type] [--mem-per-cpu=MB] [--qos=qos] [--gres=list]\n"
" [--cpu_bind=...] [--mem_bind=...] [--reservation=name]\n" " [--cpu_bind=...] [--mem_bind=...] [--reservation=name]\n"
" [--switch=max-switches{@max-time-to-wait}]\n" " [--switch=max-switches{@max-time-to-wait}]\n"
" [--export[=names]] [--export-file=file|pipe] executable [args...]\n"); " [--export[=names]] [--export-file=file|fd] executable [args...]\n");
} }
static void _help(void) static void _help(void)
...@@ -2822,7 +2822,7 @@ static void _help(void) ...@@ -2822,7 +2822,7 @@ static void _help(void)
" -D, --workdir=directory set working directory for batch script\n" " -D, --workdir=directory set working directory for batch script\n"
" -e, --error=err file for batch script's standard error\n" " -e, --error=err file for batch script's standard error\n"
" --export[=names] specify environment variables to export\n" " --export[=names] specify environment variables to export\n"
" --export-file=file|pipe specify environment variables file or pipe to export\n" " --export-file=file|fd specify environment variables file or file descriptor to export\n"
" --get-user-env load environment from local cluster\n" " --get-user-env load environment from local cluster\n"
" --gid=group_id group ID to run job as (user root only)\n" " --gid=group_id group ID to run job as (user root only)\n"
" --gres=list required generic resources\n" " --gres=list required generic resources\n"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment