int srun(int ac, char **av) { int debug_level; env_t *env = xmalloc(sizeof(env_t)); log_options_t logopt = LOG_OPTS_STDERR_ONLY; bool got_alloc = false; slurm_step_io_fds_t cio_fds = SLURM_STEP_IO_FDS_INITIALIZER; slurm_step_launch_callbacks_t step_callbacks; env->stepid = -1; env->procid = -1; env->localid = -1; env->nodeid = -1; env->cli = NULL; env->env = NULL; env->ckpt_dir = NULL; slurm_conf_init(NULL); debug_level = _slurm_debug_env_val(); logopt.stderr_level += debug_level; log_init(xbasename(av[0]), logopt, 0, NULL); _set_exit_code(); if (slurm_select_init(1) != SLURM_SUCCESS ) fatal( "failed to initialize node selection plugin" ); if (switch_init() != SLURM_SUCCESS ) fatal("failed to initialize switch plugin"); init_srun(ac, av, &logopt, debug_level, 1); create_srun_job(&job, &got_alloc, 0, 1); /* * Enhance environment for job */ if (opt.bcast_flag) _file_bcast(); if (opt.cpus_set) env->cpus_per_task = opt.cpus_per_task; if (opt.ntasks_per_node != NO_VAL) env->ntasks_per_node = opt.ntasks_per_node; if (opt.ntasks_per_socket != NO_VAL) env->ntasks_per_socket = opt.ntasks_per_socket; if (opt.ntasks_per_core != NO_VAL) env->ntasks_per_core = opt.ntasks_per_core; env->distribution = opt.distribution; if (opt.plane_size != NO_VAL) env->plane_size = opt.plane_size; env->cpu_bind_type = opt.cpu_bind_type; env->cpu_bind = opt.cpu_bind; env->cpu_freq_min = opt.cpu_freq_min; env->cpu_freq_max = opt.cpu_freq_max; env->cpu_freq_gov = opt.cpu_freq_gov; env->mem_bind_type = opt.mem_bind_type; env->mem_bind = opt.mem_bind; env->overcommit = opt.overcommit; env->slurmd_debug = opt.slurmd_debug; env->labelio = opt.labelio; env->comm_port = slurmctld_comm_addr.port; env->batch_flag = 0; if (opt.job_name) env->job_name = opt.job_name; if (job) { uint16_t *tasks = NULL; slurm_step_ctx_get(job->step_ctx, SLURM_STEP_CTX_TASKS, &tasks); env->select_jobinfo = job->select_jobinfo; env->nodelist = job->nodelist; env->partition = job->partition; /* If we didn't get the allocation don't overwrite the * previous info. */ if (got_alloc) env->nhosts = job->nhosts; env->ntasks = job->ntasks; env->task_count = _uint16_array_to_str(job->nhosts, tasks); env->jobid = job->jobid; env->stepid = job->stepid; env->account = job->account; env->qos = job->qos; env->resv_name = job->resv_name; } if (opt.pty && (set_winsize(job) < 0)) { error("Not using a pseudo-terminal, disregarding --pty option"); opt.pty = false; } if (opt.pty) { struct termios term; int fd = STDIN_FILENO; /* Save terminal settings for restore */ tcgetattr(fd, &termdefaults); tcgetattr(fd, &term); /* Set raw mode on local tty */ cfmakeraw(&term); /* Re-enable output processing such that debug() and * and error() work properly. */ term.c_oflag |= OPOST; tcsetattr(fd, TCSANOW, &term); atexit(&_pty_restore); block_sigwinch(); pty_thread_create(job); env->pty_port = job->pty_port; env->ws_col = job->ws_col; env->ws_row = job->ws_row; } setup_env(env, opt.preserve_env); xfree(env->task_count); xfree(env); _set_node_alias(); memset(&step_callbacks, 0, sizeof(step_callbacks)); step_callbacks.step_signal = launch_g_fwd_signal; /* re_launch: */ relaunch: pre_launch_srun_job(job, 0, 1); launch_common_set_stdio_fds(job, &cio_fds); if (!launch_g_step_launch(job, &cio_fds, &global_rc, &step_callbacks)) { if (launch_g_step_wait(job, got_alloc) == -1) goto relaunch; } fini_srun(job, got_alloc, &global_rc, 0); return (int)global_rc; }
static void _setup_one_job_env(opt_t *opt_local, srun_job_t *job, bool got_alloc) { env_t *env = xmalloc(sizeof(env_t)); uint16_t *tasks = NULL; xassert(job); env->localid = -1; env->nodeid = -1; env->procid = -1; env->stepid = -1; if (opt_local->bcast_flag) _file_bcast(opt_local, job); if (opt_local->cpus_set) env->cpus_per_task = opt_local->cpus_per_task; if (opt_local->ntasks_per_node != NO_VAL) env->ntasks_per_node = opt_local->ntasks_per_node; if (opt_local->ntasks_per_socket != NO_VAL) env->ntasks_per_socket = opt_local->ntasks_per_socket; if (opt_local->ntasks_per_core != NO_VAL) env->ntasks_per_core = opt_local->ntasks_per_core; env->distribution = opt_local->distribution; if (opt_local->plane_size != NO_VAL) env->plane_size = opt_local->plane_size; env->cpu_bind_type = opt_local->cpu_bind_type; env->cpu_bind = opt_local->cpu_bind; env->cpu_freq_min = opt_local->cpu_freq_min; env->cpu_freq_max = opt_local->cpu_freq_max; env->cpu_freq_gov = opt_local->cpu_freq_gov; env->mem_bind_type = opt_local->mem_bind_type; env->mem_bind = opt_local->mem_bind; env->overcommit = opt_local->overcommit; env->slurmd_debug = opt_local->slurmd_debug; env->labelio = opt_local->labelio; env->comm_port = slurmctld_comm_addr.port; if (opt_local->job_name) env->job_name = opt_local->job_name; slurm_step_ctx_get(job->step_ctx, SLURM_STEP_CTX_TASKS, &tasks); env->select_jobinfo = job->select_jobinfo; if (job->pack_node_list) env->nodelist = job->pack_node_list; else env->nodelist = job->nodelist; env->partition = job->partition; /* * If we didn't get the allocation don't overwrite the previous info. */ if (got_alloc) env->nhosts = job->nhosts; env->ntasks = job->ntasks; if (job->pack_ntasks != NO_VAL) env->ntasks = job->pack_ntasks; env->task_count = _uint16_array_to_str(job->nhosts, tasks); if (job->pack_jobid != NO_VAL) env->jobid = job->pack_jobid; else env->jobid = job->jobid; env->stepid = job->stepid; env->account = job->account; env->qos = job->qos; env->resv_name = job->resv_name; if (opt_local->pty && (set_winsize(job) < 0)) { error("Not using a pseudo-terminal, disregarding --pty option"); opt_local->pty = false; } if (opt_local->pty) { struct termios term; int fd = STDIN_FILENO; /* Save terminal settings for restore */ tcgetattr(fd, &termdefaults); tcgetattr(fd, &term); /* Set raw mode on local tty */ cfmakeraw(&term); /* Re-enable output processing such that debug() and * and error() work properly. */ term.c_oflag |= OPOST; tcsetattr(fd, TCSANOW, &term); atexit(&_pty_restore); block_sigwinch(); pty_thread_create(job); env->pty_port = job->pty_port; env->ws_col = job->ws_col; env->ws_row = job->ws_row; } env->env = env_array_copy((const char **) environ); setup_env(env, opt_local->preserve_env); job->env = env->env; xfree(env->task_count); xfree(env); }