|
33 | 33 | #include <unistd.h> |
34 | 34 |
|
35 | 35 | #include "job-exec.h" |
| 36 | +#include "exec_config.h" |
36 | 37 | #include "bulk-exec.h" |
37 | 38 | #include "rset.h" |
38 | 39 |
|
39 | 40 | extern char **environ; |
40 | | -static const char *default_cwd = "/tmp"; |
41 | | -static const char *default_job_shell = NULL; |
42 | | -static const char *flux_imp_path = NULL; |
43 | 41 |
|
44 | 42 | struct exec_ctx { |
45 | 43 | const char * mock_exception; /* fake exception */ |
@@ -74,40 +72,6 @@ static const char * exec_mock_exception (struct bulk_exec *exec) |
74 | 72 | return ctx->mock_exception; |
75 | 73 | } |
76 | 74 |
|
77 | | -static const char *jobspec_get_job_shell (json_t *jobspec) |
78 | | -{ |
79 | | - const char *path = NULL; |
80 | | - (void) json_unpack (jobspec, "{s:{s:{s:{s:s}}}}", |
81 | | - "attributes", "system", "exec", |
82 | | - "job_shell", &path); |
83 | | - return path; |
84 | | -} |
85 | | - |
86 | | -static const char *job_shell_path (struct jobinfo *job) |
87 | | -{ |
88 | | - const char *path = jobspec_get_job_shell (job->jobspec); |
89 | | - return path ? path : default_job_shell; |
90 | | -} |
91 | | - |
92 | | -static const char *jobspec_get_cwd (json_t *jobspec) |
93 | | -{ |
94 | | - const char *cwd = NULL; |
95 | | - (void) json_unpack (jobspec, "{s:{s:{s:s}}}", |
96 | | - "attributes", "system", |
97 | | - "cwd", &cwd); |
98 | | - return cwd; |
99 | | -} |
100 | | - |
101 | | -static const char *job_get_cwd (struct jobinfo *job) |
102 | | -{ |
103 | | - const char *cwd; |
104 | | - if (job->multiuser) |
105 | | - cwd = "/"; |
106 | | - else if (!(cwd = jobspec_get_cwd (job->jobspec))) |
107 | | - cwd = default_cwd; |
108 | | - return (cwd); |
109 | | -} |
110 | | - |
111 | 75 | static void start_cb (struct bulk_exec *exec, void *arg) |
112 | 76 | { |
113 | 77 | struct jobinfo *job = arg; |
@@ -300,7 +264,7 @@ static int exec_init (struct jobinfo *job) |
300 | 264 | struct bulk_exec *exec = NULL; |
301 | 265 | const struct idset *ranks = NULL; |
302 | 266 |
|
303 | | - if (job->multiuser && !flux_imp_path) { |
| 267 | + if (job->multiuser && !config_get_imp_path ()) { |
304 | 268 | flux_log (job->h, |
305 | 269 | LOG_ERR, |
306 | 270 | "unable run multiuser job with no IMP configured!"); |
@@ -333,18 +297,18 @@ static int exec_init (struct jobinfo *job) |
333 | 297 | goto err; |
334 | 298 | } |
335 | 299 | if (job->multiuser) { |
336 | | - if (flux_cmd_argv_append (cmd, flux_imp_path) < 0 |
| 300 | + if (flux_cmd_argv_append (cmd, config_get_imp_path ()) < 0 |
337 | 301 | || flux_cmd_argv_append (cmd, "exec") < 0) { |
338 | 302 | flux_log_error (job->h, "exec_init: flux_cmd_argv_append"); |
339 | 303 | goto err; |
340 | 304 | } |
341 | 305 | } |
342 | | - if (flux_cmd_argv_append (cmd, job_shell_path (job)) < 0 |
| 306 | + if (flux_cmd_argv_append (cmd, config_get_job_shell (job)) < 0 |
343 | 307 | || flux_cmd_argv_appendf (cmd, "%ju", (uintmax_t) job->id) < 0) { |
344 | 308 | flux_log_error (job->h, "exec_init: flux_cmd_argv_append"); |
345 | 309 | goto err; |
346 | 310 | } |
347 | | - if (flux_cmd_setcwd (cmd, job_get_cwd (job)) < 0) { |
| 311 | + if (flux_cmd_setcwd (cmd, config_get_cwd (job)) < 0) { |
348 | 312 | flux_log_error (job->h, "exec_init: flux_cmd_setcwd"); |
349 | 313 | goto err; |
350 | 314 | } |
@@ -431,7 +395,7 @@ static int exec_kill (struct jobinfo *job, int signum) |
431 | 395 | flux_future_t *f; |
432 | 396 |
|
433 | 397 | if (job->multiuser) |
434 | | - f = bulk_exec_imp_kill (exec, flux_imp_path, signum); |
| 398 | + f = bulk_exec_imp_kill (exec, config_get_imp_path (), signum); |
435 | 399 | else |
436 | 400 | f = bulk_exec_kill (exec, signum); |
437 | 401 | if (!f) { |
@@ -467,54 +431,9 @@ static void exec_exit (struct jobinfo *job) |
467 | 431 | job->data = NULL; |
468 | 432 | } |
469 | 433 |
|
470 | | -/* Configure the exec module. |
471 | | - * Read the default job shell path from config. Allow override on cmdline |
472 | | - */ |
473 | 434 | static int exec_config (flux_t *h, int argc, char **argv) |
474 | 435 | { |
475 | | - flux_error_t err; |
476 | | - |
477 | | - /* Set default job shell path from builtin configuration, |
478 | | - * allow override via configuration, then cmdline. |
479 | | - */ |
480 | | - default_job_shell = flux_conf_builtin_get ("shell_path", FLUX_CONF_AUTO); |
481 | | - |
482 | | - |
483 | | - /* Check configuration for exec.job-shell */ |
484 | | - if (flux_conf_unpack (flux_get_conf (h), |
485 | | - &err, |
486 | | - "{s?:{s?s}}", |
487 | | - "exec", |
488 | | - "job-shell", &default_job_shell) < 0) { |
489 | | - flux_log (h, LOG_ERR, |
490 | | - "error reading config value exec.job-shell: %s", |
491 | | - err.text); |
492 | | - return -1; |
493 | | - } |
494 | | - |
495 | | - /* Check configuration for exec.imp */ |
496 | | - if (flux_conf_unpack (flux_get_conf (h), |
497 | | - &err, |
498 | | - "{s?:{s?s}}", |
499 | | - "exec", |
500 | | - "imp", &flux_imp_path) < 0) { |
501 | | - flux_log (h, LOG_ERR, |
502 | | - "error reading config value exec.imp: %s", |
503 | | - err.text); |
504 | | - return -1; |
505 | | - } |
506 | | - |
507 | | - /* Finally, override values on cmdline */ |
508 | | - for (int i = 0; i < argc; i++) { |
509 | | - if (strncmp (argv[i], "job-shell=", 10) == 0) |
510 | | - default_job_shell = argv[i]+10; |
511 | | - else if (strncmp (argv[i], "imp=", 4) == 0) |
512 | | - flux_imp_path = argv[i]+4; |
513 | | - } |
514 | | - flux_log (h, LOG_DEBUG, "using default shell path %s", default_job_shell); |
515 | | - if (flux_imp_path) |
516 | | - flux_log (h, LOG_DEBUG, "using imp path %s", flux_imp_path); |
517 | | - return 0; |
| 436 | + return config_init (h, argc, argv); |
518 | 437 | } |
519 | 438 |
|
520 | 439 | struct exec_implementation bulkexec = { |
|
0 commit comments