diff --git a/NEWS b/NEWS index 7a44e0371463ea24aadf79f4ab30cd3a535c6eab..2581d516bb0d20d9b2da74ae02614de7798a01e0 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,9 @@ documents those changes that are of interest to users and admins. * Changes in SLURM 1.3.0-pre9 ============================= + -- Add spank support to sbatch. Note that spank_local_user() will be called + with step_layout=NULL and gid=SLURM_BATCH_SCRIPT and spank_fini() will + be called immediately afterwards. * Changes in SLURM 1.3.0-pre8 ============================= diff --git a/src/sbatch/opt.c b/src/sbatch/opt.c index 35e4d02d62c76f21cea47886ab2527b745b13448..d3ea3b0378e991741ee3830c0fe5409e2370c12c 100644 --- a/src/sbatch/opt.c +++ b/src/sbatch/opt.c @@ -60,6 +60,7 @@ #include "src/common/list.h" #include "src/common/log.h" #include "src/common/parse_time.h" +#include "src/common/plugstack.h" #include "src/common/proc_args.h" #include "src/common/slurm_protocol_api.h" #include "src/common/uid.h" @@ -877,10 +878,16 @@ static void _set_options(int argc, char **argv) { int opt_char, option_index = 0; char *tmp; + struct option *optz = spank_option_table_create (long_options); + + if (!optz) { + error ("Unable to create option table"); + exit (1); + } optind = 0; while((opt_char = getopt_long(argc, argv, opt_string, - long_options, &option_index)) != -1) { + optz, &option_index)) != -1) { switch (opt_char) { case '?': fatal("Try \"sbatch --help\" for more information"); @@ -1267,6 +1274,8 @@ static void _set_options(int argc, char **argv) opt.propagate = xstrdup("ALL"); break; default: + if (spank_process_option (opt_char, optarg) < 0) + exit (1); fatal("Unrecognized command line parameter %c", opt_char); } @@ -1275,6 +1284,7 @@ static void _set_options(int argc, char **argv) if (optind < argc) { fatal("Invalid argument: %s", argv[optind]); } + spank_option_table_destroy (optz); } static void _proc_get_user_env(char *optarg) @@ -2161,6 +2171,9 @@ static void _help(void) } slurm_conf_unlock(); + printf("\n"); + spank_print_options (stdout, 6, 30); + printf("\n" #ifdef HAVE_BG /* Blue gene specific options */ "Blue Gene related options:\n" diff --git a/src/sbatch/sbatch.c b/src/sbatch/sbatch.c index 76fb1c1d117bb7e1a13a9f05e767ca4dbaa51661..f0f31f4c88f383ebe6160368cb344c3ed849b6a4 100644 --- a/src/sbatch/sbatch.c +++ b/src/sbatch/sbatch.c @@ -41,6 +41,7 @@ #include <slurm/slurm.h> #include "src/common/env.h" +#include "src/common/plugstack.h" #include "src/common/read_config.h" #include "src/common/slurm_rlimits_info.h" #include "src/common/xstring.h" @@ -50,6 +51,8 @@ #define MAX_RETRIES 3 +static void _call_spank_local_user(job_desc_msg_t desc, + submit_response_msg_t *resp); static int fill_job_desc_from_opts(job_desc_msg_t *desc); static void *get_script_buffer(const char *filename, int *size); static void set_prio_process_env(void); @@ -85,6 +88,8 @@ int main(int argc, char *argv[]) if (script_body == NULL) exit(1); + if (spank_init(NULL) < 0) + fatal("Plug-in initialization failed"); if (process_options_second_pass((argc - opt.script_argc), argv, script_body, script_size) < 0) { fatal("sbatch parameter parsing"); @@ -115,14 +120,31 @@ int main(int argc, char *argv[]) error(msg); sleep (++retries); } - + _call_spank_local_user(desc, resp); info("Submitted batch job %d", resp->job_id); xfree(desc.script); slurm_free_submit_response_response_msg(resp); - + spank_fini(NULL); return 0; } +static void _call_spank_local_user(job_desc_msg_t desc, + submit_response_msg_t *resp) +{ + struct spank_launcher_job_info info[1]; + + info->uid = desc.user_id; + info->gid = desc.group_id; + info->jobid = resp->job_id; + info->stepid = SLURM_BATCH_SCRIPT; + info->step_layout = NULL; + info->argc = desc.argc; + info->argv = desc.argv; + + if (spank_local_user(info) < 0) + error("spank_local_user: %m"); +} + /* Returns 0 on success, -1 on failure */ static int fill_job_desc_from_opts(job_desc_msg_t *desc) {