diff --git a/src/slurmd/slurmstepd/mgr.c b/src/slurmd/slurmstepd/mgr.c index a7da99a185dde1ecc55d6e3d6e0cf7b249e19717..6dab4d8f2f070646548a345e0e11cd8a390af21b 100644 --- a/src/slurmd/slurmstepd/mgr.c +++ b/src/slurmd/slurmstepd/mgr.c @@ -75,6 +75,13 @@ # include <stdlib.h> #endif +#ifdef HAVE_PTY_H +# include <pty.h> +# ifdef HAVE_UTMP_H +# include <utmp.h> +# endif +#endif + #include "slurm/slurm_errno.h" #include "src/common/cbuf.h" @@ -1180,7 +1187,18 @@ static int exec_wait_signal (struct exec_wait_info *e, slurmd_job_t *job) return (0); } - +static void prepare_tty (slurmd_job_t *job, slurmd_task_info_t *task) +{ +#ifdef HAVE_PTY_H + if (job->pty && (task->gtid == 0)) { + if (login_tty(task->stdin_fd)) + error("login_tty: %m"); + else + debug3("login_tty good"); + } +#endif + return; +} /* fork and exec N tasks */ @@ -1296,6 +1314,11 @@ _fork_all_tasks(slurmd_job_t *job) xsignal_unblock(slurmstepd_blocked_signals); + /* + * Setup tty before any setpgid() calls + */ + prepare_tty (job, job->task[i]); + exec_task(job, i, ei->childfd); } diff --git a/src/slurmd/slurmstepd/task.c b/src/slurmd/slurmstepd/task.c index 4462596b35f0c3d46b613639d2b48d35ddd48c92..56fe04cd1200e0da4bd42d96a93b20a9b929465b 100644 --- a/src/slurmd/slurmstepd/task.c +++ b/src/slurmd/slurmstepd/task.c @@ -65,14 +65,6 @@ # include <sys/checkpnt.h> #endif -#ifdef HAVE_PTY_H -# include <pty.h> -#endif - -#ifdef HAVE_UTMP_H -# include <utmp.h> -#endif - #include <sys/resource.h> #include "slurm/slurm_errno.h" @@ -345,16 +337,6 @@ exec_task(slurmd_job_t *job, int i, int waitfd) int rc; slurmd_task_info_t *task = job->task[i]; -#ifdef HAVE_PTY_H - /* Execute login_tty() before setpgid() calls */ - if (job->pty && (task->gtid == 0)) { - if (login_tty(task->stdin_fd)) - error("login_tty: %m"); - else - debug3("login_tty good"); - } -#endif - if (i == 0) _make_tmpdir(job); @@ -422,14 +404,7 @@ exec_task(slurmd_job_t *job, int i, int waitfd) } } -#ifdef HAVE_PTY_H - if (job->pty && (task->gtid == 0)) { - /* Need to perform the login_tty() before all tasks - * register and the process groups are reset, otherwise - * login_tty() gets disabled */ - } else -#endif - io_dup_stdio(task); + io_dup_stdio(task); /* task-specific pre-launch activities */