42-archive/42sh/src/job-control/put_job_in_foreground.c
2017-03-15 15:51:52 +01:00

42 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* put_job_in_foreground.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
/* Updated: 2017/03/15 15:51:30 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int put_job_in_foreground(t_job *j, int cont)
{
t_jobc *jobc;
jobc = &data_singleton()->jobc;
DG("tcsetpgrp[%i]", j->pgid);
if (SH_IS_INTERACTIVE(data_singleton()->opts))
tcsetpgrp(STDIN, j->pgid);
if (cont)
{
// j->tmodes = pas initialisé !
//tcsetattr(STDIN, TCSADRAIN, &j->tmodes);
if (kill(-j->pgid, SIGCONT) < 0)
DG("kill(SIGCONT) failed");
}
DG("check");
job_wait(j->id);
DG("check");
if (SH_IS_INTERACTIVE(data_singleton()->opts))
{
tcsetpgrp(STDIN, jobc->shell_pgid);
tcgetattr(STDIN, &j->tmodes);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
}
job_remove(j->id);
DG("check");
return (0);
}