fg works with vim but not cat, probablty something to do w/ SIGTTIN or SIGTTOU.

This commit is contained in:
Jack Halford 2017-01-08 16:14:31 +01:00
parent df1f449778
commit bbdaedef06
37 changed files with 230 additions and 86 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */
/* Updated: 2016/12/15 17:49:35 by jhalford ### ########.fr */
/* Updated: 2017/01/08 14:34:40 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,5 +24,6 @@ int builtin_exit(const char *path, char *const argv[], char *const envp[]);
int builtin_setenv(const char *path, char *const argv[], char *const envp[]);
int builtin_unsetenv(const char *path, char *const argv[], char *const envp[]);
int builtin_jobs(const char *path, char *const av[], char *const envp[]);
int builtin_fg(const char *path, char *const av[], char *const envp[]);
#endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/01/02 18:10:15 by jhalford ### ########.fr */
/* Updated: 2017/01/08 16:10:11 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2017/01/02 18:10:03 by jhalford ### ########.fr */
/* Updated: 2017/01/08 16:10:10 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -58,6 +58,8 @@ int job_is_stopped(int id);
int job_is_completed(int id);
void job_remove(int id);
void job_free(void *content, size_t content_size);
void job_kill_all(void);
void mark_job_as_running (t_job *j);
int process_mark_status(pid_t pid, int status);
int put_job_in_foreground(t_job *job, int cont);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2016/12/13 17:51:07 by jhalford ### ########.fr */
/* Updated: 2017/01/08 16:10:25 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,6 +29,7 @@
# include <sys/types.h>
# include <signal.h>
# include <fcntl.h>
# include <errno.h>
enum e_mode

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */
/* Updated: 2016/12/13 18:00:26 by jhalford ### ########.fr */
/* Updated: 2017/01/08 16:00:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,12 +15,27 @@
int builtin_exit(const char *path, char *const av[], char *const envp[])
{
int status;
static int notified = 0;
t_jobc *jobc;
t_list *jlist;
(void)envp;
(void)path;
jobc = &data_singleton()->jobc;
jlist = jobc->first_job;
if (jlist && !notified)
{
notified = 1;
ft_dprintf(2, "{red}%s: you have live jobs (running or suspended).{eoc}\n", SHELL_NAME);
return (0);
}
if (av[1])
status = ft_atoi(av[1]);
else
status = ft_atoi(ft_getenv((char**)envp, "?"));
{
/* status = ft_atoi(ft_getenv(data_singleton()->env, "?")); */
status = 0;
}
exit(status);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
/* Updated: 2016/12/15 17:48:23 by jhalford ### ########.fr */
/* Updated: 2017/01/08 14:30:52 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,6 +20,7 @@ t_stof g_builtin[] = {
{"env", &builtin_env},
{"exit", &builtin_exit},
{"jobs", &builtin_jobs},
{"fg", &builtin_fg},
{NULL, NULL},
};

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
/* Updated: 2017/01/02 19:10:01 by jhalford ### ########.fr */
/* Updated: 2017/01/08 15:24:20 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */
/* Updated: 2016/12/13 17:15:22 by jhalford ### ########.fr */
/* Updated: 2017/01/08 11:03:05 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
/* Updated: 2016/12/15 15:18:21 by jhalford ### ########.fr */
/* Updated: 2017/01/08 11:03:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
/* Updated: 2017/01/03 18:01:30 by jhalford ### ########.fr */
/* Updated: 2017/01/08 15:23:37 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,13 +32,19 @@ int launch_process(t_process *p)
if (p->attributes & (PROCESS_BINARY | PROCESS_SCRIPT)
&& access(p->path, X_OK) == -1)
{
ft_dprintf(2, "%s: permission denied: %s\n", SHELL_NAME, p->av[0]);
ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->av[0]);
return (-1);
}
pid = fork();
if (pid == 0)
{
process_setgroup(p);
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGTSTP, sigtstp_handler);
signal(SIGTTIN, SIG_DFL);
signal(SIGTTOU, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
process_redirect(p);
(*p->execf)(p->path, p->av, data_singleton()->env);
exit(42);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
/* Updated: 2017/01/03 18:04:09 by jhalford ### ########.fr */
/* Updated: 2017/01/08 15:23:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,8 +24,13 @@ int process_setgroup(t_process *p)
if (job->pgid == 0)
job->pgid = pid;
DG("job->pgid=%i", job->pgid);
setpgid(pid, job->pgid);
if (setpgid(pid, job->pgid))
ft_dprintf(2, "{red}setpgid failed{eoc}\n");
if (JOB_IS_FG(job->attributes))
tcsetpgrp(STDIN_FILENO, job->pgid);
{
signal(SIGTTOU, SIG_IGN);
tcsetpgrp(STDIN, job->pgid);
signal(SIGTTOU, SIG_DFL);
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
/* Updated: 2016/12/12 17:54:19 by jhalford ### ########.fr */
/* Updated: 2017/01/08 15:58:20 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtin_fg.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */
/* Updated: 2017/01/08 15:21:23 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "job_control.h"
int builtin_fg(const char *path, char *const av[], char *const envp[])
{
t_jobc *jobc;
t_job *job;
(void)path;
(void)envp;
(void)av;
jobc = &data_singleton()->jobc;
job = jobc->first_job->content;
if (job)
{
mark_job_as_running(job);
put_job_in_foreground(job, 1);
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
/* Updated: 2017/01/03 18:13:47 by jhalford ### ########.fr */
/* Updated: 2017/01/08 15:33:32 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */
/* Updated: 2017/01/02 18:21:20 by jhalford ### ########.fr */
/* Updated: 2017/01/08 14:00:23 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,8 +36,8 @@ int do_job_notification(void)
else if (job_is_stopped(j->id) && !(j->attributes & JOB_NOTIFIED))
{
ret = 1;
job_notify_change(j->id, 8);
j->attributes &= JOB_NOTIFIED;
job_notify_change(j->id, -1);
j->attributes |= JOB_NOTIFIED;
}
jlist = jlist->next;
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
/* Updated: 2017/01/03 18:16:00 by jhalford ### ########.fr */
/* Updated: 2017/01/08 15:41:56 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,6 +23,7 @@ int job_addprocess(t_process *p)
{
job_update_id();
job->id = jobc->current_id;
job->pgid = p->pid;
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
DG("added new job [%i]", job->id);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:10:20 by jhalford #+# #+# */
/* Updated: 2017/01/03 18:12:26 by jhalford ### ########.fr */
/* Updated: 2017/01/08 14:04:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */
/* Updated: 2016/12/15 12:42:02 by jhalford ### ########.fr */
/* Updated: 2017/01/08 14:39:35 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* job_kill_all.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 15:36:56 by jhalford #+# #+# */
/* Updated: 2017/01/08 15:44:07 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "job_control.h"
void job_kill_all(void)
{
t_jobc *jobc;
t_list *jlist;
t_job *job;
jobc = &data_singleton()->jobc;
jlist = jobc->first_job;
while (jlist)
{
job = jlist->content;
kill(-job->pgid, SIGKILL);
jlist = jlist->next;
}
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */
/* Updated: 2016/12/15 17:45:36 by jhalford ### ########.fr */
/* Updated: 2017/01/08 13:52:53 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,8 @@ void job_notify_change(int id, int status)
{
t_job *job;
t_jobc *jobc;
t_list *plist;
t_process *p;
char rank;
rank = ' ';
@ -30,13 +32,27 @@ void job_notify_change(int id, int status)
rank = '-';
}
ft_printf("{mag}[%i] %c ", id, rank);
if (status == 0)
ft_printf("{gre}done{mag}");
else if (status == 8)
job = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
if (status == -1)
ft_printf("{red}stopped{mag}");
else if (status == 9)
ft_printf("{red}killed{mag}");
else
ft_printf("exit %i", status);
ft_printf("\t 'process command goes here'{eoc}\n");
{
plist = job->first_process;
p = ft_lstlast(job->first_process)->content;
if (p->status == 0)
ft_printf("{gre}done{mag}");
else
ft_printf("{red}exit %i{mag}", p->status);
}
ft_printf("\t ");
plist = job->first_process;
while (plist)
{
p = plist->content;
ft_sstrprint(p->av, ' ');
if (plist->next)
ft_printf(" |");
plist = plist->next;
}
ft_printf("{eoc}\n");
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */
/* Updated: 2017/01/02 18:15:03 by jhalford ### ########.fr */
/* Updated: 2017/01/08 14:04:48 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,6 +17,8 @@ void job_remove(int id)
t_jobc *jobc;
jobc = &data_singleton()->jobc;
if (job_is_completed(id))
{
DG("job_remove");
if (id < data_singleton()->jobc.current_id)
{
@ -27,3 +29,6 @@ void job_remove(int id)
DG("ID_UPDATE(no downgrade): %i/%i", id, data_singleton()->jobc.current_id);
ft_lst_delif(&jobc->first_job, &id, job_cmp_id, job_free);
}
else
DG("job_remove failed (not completed)");
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
/* Updated: 2017/01/02 17:32:43 by jhalford ### ########.fr */
/* Updated: 2017/01/08 16:00:23 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,7 +28,5 @@ int job_wait(int id)
pid = waitpid(WAIT_ANY, &status, WUNTRACED);
DG("waitpid done");
}
DG("stopped: %i", job_is_stopped(id));
DG("completed: %i", job_is_completed(id));
return (0);
}

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mark_job_as_running.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 14:40:40 by jhalford #+# #+# */
/* Updated: 2017/01/08 14:53:34 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "job_control.h"
void mark_job_as_running (t_job *j)
{
t_list *plist;
t_process *p;
plist = j->first_process;
while (plist)
{
p = plist->content;
p->attributes &= ~PROCESS_STOPPED;
plist = plist->next;
}
j->attributes &= ~JOB_NOTIFIED;
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/01/03 18:01:15 by jhalford ### ########.fr */
/* Updated: 2017/01/08 14:55:52 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,15 +18,17 @@ int process_mark_status(pid_t pid, int status)
if (pid > 1)
{
DG("marking: pid=%i, status=%i", pid, status);
if ((p = job_getprocess(pid)))
{
DG("found process pid=%i", pid);
p->status = status;
if (WIFSTOPPED(status))
{
DG("marking: pid=%i, status=%i (stopped)", pid, status);
p->attributes |= PROCESS_STOPPED;
}
else
{
DG("marking: pid=%i, status=%i (completed)", pid, status);
p->attributes |= PROCESS_COMPLETED;
if (WIFSIGNALED(status))
ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}",

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:03:29 by jhalford #+# #+# */
/* Updated: 2016/12/15 17:53:24 by jhalford ### ########.fr */
/* Updated: 2017/01/08 13:24:53 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
/* Updated: 2017/01/02 18:15:09 by jhalford ### ########.fr */
/* Updated: 2017/01/08 15:33:03 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,25 +18,31 @@ int put_job_in_foreground(t_job *job, int cont)
jobc = &data_singleton()->jobc;
/* Put the job into the foreground. */
tcsetpgrp(STDIN_FILENO, job->pgid);
signal(SIGTTOU, SIG_IGN);
if (tcsetpgrp(STDIN, job->pgid) == -1)
DG("couldn't put process in control. errno=%i, pgid=%i", errno, job->pgid);
else
DG("pgid %i is now in control.", job->pgid);
signal(SIGTTOU, sigttou_handler);
/* Send the job a continue signal, if necessary. */
if (cont)
{
tcsetattr (STDIN_FILENO, TCSADRAIN, &job->tmodes);
tcsetattr (STDIN, TCSANOW, &job->tmodes);
if (kill(-job->pgid, SIGCONT) < 0)
perror("kill (SIGCONT)");
}
/* Wait for it to report. */
DG("gonna wait for job id=%i", job->id);
/* if (!(p->attributes & PROCESS_BUILTIN && p->fdout == STDOUT)) */
job_wait(job->id);
job_remove(job->id);
/* Put the shell back in the foreground. */
tcsetpgrp(STDIN_FILENO, jobc->shell_pgid);
signal(SIGTTOU, SIG_IGN);
tcsetpgrp(STDIN, jobc->shell_pgid);
signal(SIGTTOU, sigttou_handler);
/* Restore the shells terminal modes. */
tcgetattr(STDIN_FILENO, &job->tmodes);
tcsetattr(STDIN_FILENO, TCSADRAIN, &jobc->shell_tmodes);
tcgetattr(STDIN, &job->tmodes);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 17:37:56 by jhalford #+# #+# */
/* Updated: 2017/01/02 18:10:01 by jhalford ### ########.fr */
/* Updated: 2017/01/08 11:28:29 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,8 +18,9 @@ void sigchld_handler(int signo)
(void)signo;
data = data_singleton();
DG("got asynchronous notification (SIGCHLD)");
DG("got SIGCHLD");
/* if (do_job_notification()) */
/* ft_putstr(SHELL_PROMPT); */
if (data_singleton()->mode != MODE_EXEC)
job_update_status();
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */
/* Updated: 2016/12/10 18:20:57 by jhalford ### ########.fr */
/* Updated: 2017/01/08 14:30:53 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */
/* Updated: 2016/12/10 18:20:57 by jhalford ### ########.fr */
/* Updated: 2017/01/08 13:24:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:24 by jhalford #+# #+# */
/* Updated: 2016/12/12 17:40:27 by jhalford ### ########.fr */
/* Updated: 2017/01/08 15:56:51 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,5 +17,7 @@ int ft_key_ctrl_d(t_data *data, char *buf)
(void)data;
(void)buf;
ft_putendl("exit");
exit(0);
builtin_exit("exit", (char *[]){"exit", NULL}, data_singleton()->env);
ft_prompt();
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 14:22:34 by jhalford #+# #+# */
/* Updated: 2017/01/02 18:19:24 by jhalford ### ########.fr */
/* Updated: 2017/01/08 16:00:49 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:14:09 by jhalford #+# #+# */
/* Updated: 2016/12/12 17:35:27 by jhalford ### ########.fr */
/* Updated: 2017/01/08 14:26:55 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 13:35:03 by jhalford #+# #+# */
/* Updated: 2016/12/12 17:35:15 by jhalford ### ########.fr */
/* Updated: 2017/01/08 14:27:01 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 15:14:47 by jhalford #+# #+# */
/* Updated: 2016/12/10 15:31:56 by jhalford ### ########.fr */
/* Updated: 2017/01/08 15:12:58 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,13 +14,6 @@
void sigint_handler(int signo)
{
t_job *job;
(void)signo;
job = &data_singleton()->exec.job;
DG("got SIGINT; job->pgid=%i", job->pgid);
if (job->pgid)
kill(job->pgid, SIGINT);
if (kill(job->pgid, 0) == 0)
ft_putchar('\n');
DG("got SIGINT");
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2016/12/13 13:38:33 by jhalford ### ########.fr */
/* Updated: 2017/01/08 14:26:51 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:37:04 by jhalford #+# #+# */
/* Updated: 2016/12/12 17:51:20 by jhalford ### ########.fr */
/* Updated: 2017/01/08 15:55:39 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,8 +19,9 @@ extern char *BC;
void shell_exit(void)
{
DG("cleanup. char * UP at %p", UP);
DG("cleanup. char * BC at %p", BC);
/* DG("cleanup. char * UP at %p", UP); */
/* DG("cleanup. char * BC at %p", BC); */
data_exit();
/* job_kill_all(); */
tcsetattr(0, TCSANOW, &data_singleton()->jobc.shell_tmodes);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
/* Updated: 2016/12/13 15:14:35 by jhalford ### ########.fr */
/* Updated: 2017/01/08 15:11:34 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,13 +19,13 @@ void shell_init(void)
shell_pgid = &data_singleton()->jobc.shell_pgid;
data_init();
atexit(&shell_exit);
if (isatty(STDIN_FILENO))
if (isatty(STDIN))
{
while (tcgetpgrp(STDIN_FILENO) != (*shell_pgid = getpgrp()))
while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp()))
kill(-*shell_pgid, SIGTTIN);
signal(SIGINT, sigint_handler);
signal(SIGQUIT, SIG_IGN);
signal(SIGTSTP, sigtstp_handler);
signal(SIGTSTP, SIG_IGN);
signal(SIGTTIN, sigttin_handler);
signal(SIGTTOU, sigttou_handler);
signal(SIGCHLD, sigchld_handler);
@ -35,7 +35,7 @@ void shell_init(void)
ft_dprintf(2, "Couldnt put the shell in it's own process group");
exit (1);
}
tcsetpgrp(STDIN_FILENO, *shell_pgid);
tcgetattr(STDIN_FILENO, &data_singleton()->jobc.shell_tmodes);
tcsetpgrp(STDIN, *shell_pgid);
tcgetattr(STDIN, &data_singleton()->jobc.shell_tmodes);
}
}