From 31d0897d55b3cf7ef5a396dbcbda7d2a8fc062ba Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Mon, 30 Jun 2003 16:09:33 +0000 Subject: [PATCH] Add support for squeue environment variables SLURM_FORMAT, SLURM_PARTITION, SLURM_SORT, SLURM_STATES, and SLURM_USERS. --- doc/man/man1/squeue.1 | 23 +++++++++++++++- src/squeue/opts.c | 61 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/doc/man/man1/squeue.1 b/doc/man/man1/squeue.1 index 791d511010b..c1372320882 100644 --- a/doc/man/man1/squeue.1 +++ b/doc/man/man1/squeue.1 @@ -78,7 +78,8 @@ The days and hours are printed only as needed. .br \fB%O\fR Are contiguous nodes requested by the job .br -\fB%p\fR Priority of the job (converted to a floating point number between 0.0 and 1.0 +\fB%p\fR Priority of the job (converted to a floating point number +between 0.0 and 1.0 .br \fB%P\fR Partition of the job or job step .br @@ -130,6 +131,26 @@ reported. \fB\-v\fR, \fB\-\-verbose\fR Report details of squeues actions. +.SH "ENVIRONMENT VARIABLES" +.PP +Some \fBsqueue\fR options may be set via environment variables. These +environment variables, along with their corresponding options, are listed +below. (Note: commandline options will always override these settings) +.TP 20 +SQUEUE_FORMAT +\fB\-o, \-\-format\fR +.TP +SQUEUE_PARTITION +\fB\-p, \-\-partition\fR +.TP +SQUEUE_SORT +\fB\-S, \-\-sort\fR +.TP +SQUEUE_STATES +\fB\-t, \-\-states\fR +.TP +SQUEUE_USERS +\fB\-u, \-\-users\fR .SH "EXAMPLES" .eo diff --git a/src/squeue/opts.c b/src/squeue/opts.c index 333d27ae3c1..5a2da97026a 100644 --- a/src/squeue/opts.c +++ b/src/squeue/opts.c @@ -26,6 +26,8 @@ #include <popt.h> #include <pwd.h> +#include <stdlib.h> +#include <string.h> #include <sys/types.h> #include "src/common/xstring.h" @@ -45,8 +47,8 @@ #define OPT_VERBOSE 0x09 #define OPT_ITERATE 0x0a #define OPT_USERS 0x0b -#define OPT_LONG 0x0c -#define OPT_SORT 0x0d +#define OPT_LONG 0x0c +#define OPT_SORT 0x0d #define OPT_NO_HEAD 0x0e /* FUNCTIONS */ @@ -71,7 +73,8 @@ parse_command_line( int argc, char* argv[] ) { poptContext context; char next_opt, curr_opt; - int rc = 0; + char *env_val = NULL; + int i = 0, rc = 0; /* Declare the Options */ static const struct poptOption options[] = @@ -138,20 +141,17 @@ parse_command_line( int argc, char* argv[] ) case OPT_STEPS_NONE: if ( (opt_arg = poptGetArg( context )) != NULL ) params.steps = (char*)opt_arg; - params.step_list = - _build_step_list( params.steps ); + params.step_list = _build_step_list( params.steps ); break; case OPT_STATES: - params.state_list = - _build_state_list( params.states ); + params.state_list = _build_state_list( params.states ); break; case OPT_PARTITIONS: params.part_list = _build_part_list( params.partitions ); break; case OPT_USERS: - params.user_list = - _build_user_list( params.users ); + params.user_list = _build_user_list( params.users ); break; case OPT_VERBOSE: params.verbose = true; @@ -184,6 +184,49 @@ parse_command_line( int argc, char* argv[] ) exit( 1 ); } + if ( ( params.format == NULL ) && + ( env_val = getenv("SQUEUE_FORMAT") ) ) { + i = strlen(env_val); + params.format = xmalloc(i); + strcpy(params.format, env_val); + env_val = NULL; + } + + if ( ( params.partitions == NULL ) && + ( env_val = getenv("SQUEUE_PARTITION") ) ) { + i = strlen(env_val); + params.partitions = xmalloc(i); + strcpy(params.partitions, env_val); + params.part_list = _build_part_list( params.partitions ); + env_val = NULL; + } + + if ( ( params.sort == NULL ) && + ( env_val = getenv("SQUEUE_SORT") ) ) { + i = strlen(env_val); + params.sort = xmalloc(i); + strcpy(params.sort, env_val); + env_val = NULL; + } + + if ( ( params.states == NULL ) && + ( env_val = getenv("SQUEUE_STATES") ) ) { + i = strlen(env_val); + params.states = xmalloc(i); + strcpy(params.states, env_val); + params.state_list = _build_state_list( params.states ); + env_val = NULL; + } + + if ( ( params.users == NULL ) && + ( env_val = getenv("SQUEUE_USERS") ) ) { + i = strlen(env_val); + params.users = xmalloc(i); + strcpy(params.users, env_val); + params.user_list = _build_user_list( params.users ); + env_val = NULL; + } + if ( params.format ) _parse_format( params.format ); -- GitLab