diff --git a/src/slurmd/slurmstepd/mgr.c b/src/slurmd/slurmstepd/mgr.c index 372107d69c15ed7077586a45aea52f3490f66172..3a84e6652383a5ec3a7b32ba7b7ceab821ab9a2d 100644 --- a/src/slurmd/slurmstepd/mgr.c +++ b/src/slurmd/slurmstepd/mgr.c @@ -957,9 +957,19 @@ _fork_all_tasks(slurmd_job_t *job) /* * Put this task in the step process group */ - if (setpgid (job->task[i]->pid, job->pgid) < 0) - error ("Unable to put task %d (pid %ld) into pgrp %ld", - i, job->task[i]->pid, job->pgid); + if (setpgid (job->task[i]->pid, job->pgid) < 0) { + if (job->pty) { + /* login_tty() must put task zero in its own + * session, causing setpgid() to fail */ + info("Unable to put task %d (pid %ld) into " + "pgrp %ld: %m", + i, job->task[i]->pid, job->pgid); + } else { + error("Unable to put task %d (pid %ld) into " + "pgrp %ld: %m", + i, job->task[i]->pid, job->pgid); + } + } if (slurm_container_add(job, job->task[i]->pid) == SLURM_ERROR) { error("slurm_container_create: %m"); diff --git a/src/slurmd/slurmstepd/task.c b/src/slurmd/slurmstepd/task.c index 803ae235b21cb2695fc95ea03130e3186b18e96d..a99d549bdf23a84af7e54049a9d8cfbd0ff30c97 100644 --- a/src/slurmd/slurmstepd/task.c +++ b/src/slurmd/slurmstepd/task.c @@ -62,6 +62,14 @@ # 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> @@ -291,6 +299,16 @@ 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 + info("login_tty good"); + } +#endif + if (set_user_limits(job) < 0) { debug("Unable to set user limits"); log_fini(); @@ -361,7 +379,12 @@ exec_task(slurmd_job_t *job, int i, int waitfd) pdebug_stop_current(job); } - io_dup_stdio(task); + 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 + io_dup_stdio(task); /* task-specific pre-launch activities */