From 033ff4d8e25e4b0dc2f56f66ce05ce2ebeacdec2 Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Thu, 5 Jan 2006 21:56:55 +0000 Subject: [PATCH] Fix bug in processing of "#SLURM" batch script option parsing. --- NEWS | 1 + src/srun/opt.c | 21 ++++++---- src/srun/srun.c | 87 ++++++++++++++------------------------- testsuite/expect/test1.47 | 67 +++++++++++++++++++++++++++--- 4 files changed, 108 insertions(+), 68 deletions(-) diff --git a/NEWS b/NEWS index e793714dc14..b5cb4ef000d 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ documents those changes that are of interest to users and admins. ============================= -- Add support for job suspend/resume. -- Add slurmd cache for group IDs (Takao Hatazaki, HP). + -- Fix bug in processing of "#SLURM" batch script option parsing. * Changes in SLURM 0.7.0-pre7 ============================= diff --git a/src/srun/opt.c b/src/srun/opt.c index 35e17c737e6..d887eb4f93d 100644 --- a/src/srun/opt.c +++ b/src/srun/opt.c @@ -2,7 +2,7 @@ * opt.c - options processing for srun * $Id$ ***************************************************************************** - * Copyright (C) 2002 The Regents of the University of California. + * Copyright (C) 2002-2006 The Regents of the University of California. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). * Written by Mark Grondona <grondona1@llnl.gov>, et. al. * UCRL-CODE-217948. @@ -829,6 +829,7 @@ _get_int(const char *arg, const char *what) void set_options(const int argc, char **argv, int first) { int opt_char, option_index = 0; + static bool set_cwd=false, set_name=false; struct utsname name; static struct option long_options[] = { {"attach", required_argument, 0, 'a'}, @@ -986,9 +987,10 @@ void set_options(const int argc, char **argv, int first) _get_int(optarg, "slurmd-debug"); break; case (int)'D': - if(!first && opt.cwd) + if(!first && set_cwd) break; - + + set_cwd = true; xfree(opt.cwd); opt.cwd = xstrdup(optarg); break; @@ -1026,9 +1028,10 @@ void set_options(const int argc, char **argv, int first) opt.join = true; break; case (int)'J': - if(!first && opt.job_name) + if(!first && set_name) break; - + + set_name = true; xfree(opt.job_name); opt.job_name = xstrdup(optarg); break; @@ -1327,8 +1330,12 @@ void set_options(const int argc, char **argv, int first) } } - if (!first && !_opt_verify()) - exit(1); + if (!first) { + if (!_opt_verify()) + exit(1); + if (_verbose > 3) + _opt_list(); + } } /* diff --git a/src/srun/srun.c b/src/srun/srun.c index 4e408d05d15..993252718c4 100644 --- a/src/srun/srun.c +++ b/src/srun/srun.c @@ -3,7 +3,7 @@ * parallel jobs. * $Id$ ***************************************************************************** - * Copyright (C) 2002 The Regents of the University of California. + * Copyright (C) 2002-2006 The Regents of the University of California. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). * Written by Mark Grondona <grondona@llnl.gov>, et. al. * UCRL-CODE-217948. @@ -99,6 +99,7 @@ static char *_build_script (char *pathname, int file_type); static char *_get_shell (void); static void _send_options(const int argc, char **argv); static void _get_options (const char *buffer); +static char *_get_token(char *buf_ptr); static int _is_file_text (char *, char**); static int _run_batch_job (void); static int _run_job_script(srun_job_t *job, env_t *env); @@ -501,68 +502,42 @@ _get_shell (void) return pw_ent_ptr->pw_shell; } -/* _get_opts - gather options put in user script. Used for batch scripts. */ +static char *_get_token(char *buf_ptr) +{ + int i, token_size = 0; + char *token; + + for (i=1; (buf_ptr[i] != '\n') && (buf_ptr[i] != '\0'); + i++) { + if (isspace(buf_ptr[i])) + break; + } + token_size = i; + token = xmalloc(token_size + 1); + strncpy(token, buf_ptr, token_size); + return token; +} + +/* _get_opts - gather options put in user script. Used for batch scripts. */ static void _get_options (const char *buffer) { - int i=0, i2=0; int argc = 1; char *argv[MAX_ENTRIES]; - - while(buffer[i]) { - if(!strncmp(buffer+i, "#SLURM ",7)) { - i += 7; - i2 = i; - while(buffer[i2]!= '\n') { - if(buffer[i2] == '-') { - i = i2; - while(buffer[i] != '\n') { - if(i != i2 && i != (i2+1) - && buffer[i] == '-') { - argv[argc] = xmalloc( - sizeof(char) - *(i-i2)); - memset(argv[argc], 0, - (i-i2)); - strncpy(argv[argc], - buffer+i2, - (i-i2-1)); - argc++; - if(argc>=MAX_ENTRIES) { - _send_options( - argc, - argv); - argc = 1; - } - i2 = i; - } - i++; - - } - argv[argc] = xmalloc( - sizeof(char) - *(i-i2+1)); - memset(argv[argc], 0, - (i-i2+1)); - strncpy(argv[argc], - buffer+i2, - (i-i2)); - i2 = i; - argc++; - if(argc>=MAX_ENTRIES) { - _send_options(argc, argv); - argc = 1; - } - - break; - } else - i2++; - } - i = i2; + char *buf_loc = (char *) buffer; + + while ((buf_loc = strstr(buf_loc, "#SLURM"))) { + buf_loc += 6; + /* find the tokens and move them to argv */ + for ( ; ((buf_loc[0] != '\n') && (buf_loc[0] != '\0')); + buf_loc++) { + if (isspace(buf_loc[0])) + continue; + argv[argc] = _get_token(buf_loc); + buf_loc += (strlen(argv[argc]) - 1); + argc++; } - - i++; } if(argc > 1) _send_options(argc, argv); diff --git a/testsuite/expect/test1.47 b/testsuite/expect/test1.47 index a2f1c337149..df55a54d2ec 100755 --- a/testsuite/expect/test1.47 +++ b/testsuite/expect/test1.47 @@ -10,7 +10,7 @@ # Note: This script generates and then deletes files in the working directory # named test1.47.input and test1.47.output ############################################################################ -# Copyright (C) 2005 The Regents of the University of California. +# Copyright (C) 2005-2006 The Regents of the University of California. # Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). # Written by Danny Auble <da@llnl.gov> # UCRL-CODE-217948. @@ -38,11 +38,68 @@ set test_id "1.47" set exit_code 0 set file_in "test$test_id.input" set file_out "test$test_id.output" -set matches 0 +set job_acct "TEST_ACCT" +set job_name "TEST_NAME" set delay 1 print_header $test_id +# +# Delete left-over input script +exec $bin_rm -f $file_in +exec echo "#!$bin_bash" >$file_in +exec echo "#SLURM --job-name=$job_name" >>$file_in +exec echo "#SLURM --account=$job_acct" >>$file_in +exec echo "$bin_sleep $delay" >>$file_in +exec $bin_chmod 700 $file_in + +set timeout $max_job_delay +set job_id 0 +spawn $srun -o $file_out -b $file_in +expect { + -re "jobid ($number) submitted" { + set job_id $expect_out(1,string) + exp_continue + } + timeout { + send_user "\nFAILURE: srun not responding\n" + kill_srun + set exit_code 1 + exp_continue + } + eof { + wait + } +} +if {$job_id == 0} { + send_user "\nFAILURE: batch submit failure\n" + exit 1 +} +set matches 0 +spawn $scontrol show job $job_id +expect { + -re "Name=$job_name" { + incr matches + exp_continue + } + -re "Account=$job_acct" { + incr matches + exp_continue + } + timeout { + send_user "\nFAILURE: scontrol not responding\n" + set exit_code 1 + exp_continue + } + eof { + wait + } +} +if {$matches != 2} { + send_user "\nFAILURE: did not set job name and account from batch script\n" + set exit_code 1 +} + # # Delete left-over input script # Build input script file @@ -56,7 +113,7 @@ exec echo "#SLURM -N65000" >>$file_in exec echo "$bin_sleep $delay" >>$file_in exec $bin_chmod 700 $file_in -set timeout $max_job_delay +set matches 0 spawn $srun -o $file_out -b $file_in expect { -re "More .* requested than permitted" { @@ -85,11 +142,11 @@ exec echo "#SLURM -N650000" >>$file_in exec echo "$bin_sleep $delay" >>$file_in exec $bin_chmod 700 $file_in -set timeout $max_job_delay spawn $srun -N1 -o $file_out -b $file_in expect { -re "More nodes requested than permitted" { - send_user "\nFAILURE: srun read from the batch file options over writing the commandline options\n" + send_user "\nFAILURE: srun read from the batch file options" + send_user "over writing the commandline options\n" set exit_code 1 exp_continue } -- GitLab