This commit is contained in:
Jack Halford 2017-03-20 20:53:23 +01:00
parent 7beeaa517e
commit 338913ade0
10 changed files with 46 additions and 31 deletions

View file

@ -6,14 +6,14 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ # # By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# # # Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/03/20 12:04:31 by wescande ### ########.fr # # Updated: 2017/03/20 19:08:06 by jhalford ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
NAME = 42sh NAME = 42sh
CC = gcc CC = gcc
FLAGS = -Wall -Wextra -Werror -fvisibility=hidden FLAGS = -Wall -Wextra -Werror -fvisibility=hidden -fsanitize=address
D_FLAGS = -g D_FLAGS = -g
DELTA = $$(echo "$$(tput cols)-47"|bc) DELTA = $$(echo "$$(tput cols)-47"|bc)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */ /* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */
/* Updated: 2017/03/20 15:02:31 by wescande ### ########.fr */ /* Updated: 2017/03/20 20:51:55 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -87,7 +87,7 @@ static int env_treat_flag(char ***custom_env, char *const *arg[])
return (0); return (0);
} }
int builtin_env(const char *path, int builtin_env(const char *path,
char *const argv[], char *const envp[]) char *const argv[], char *const envp[])
{ {
char **env; char **env;

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
/* Updated: 2017/03/20 12:47:34 by jhalford ### ########.fr */ /* Updated: 2017/03/20 20:41:34 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -40,6 +40,7 @@ int exec_leaf(t_btree **ast)
p.map = g_process_map[p.type]; p.map = g_process_map[p.type];
if (!(process_launch(&p))) if (!(process_launch(&p)))
{ {
DG("check");
job_addprocess(&p); job_addprocess(&p);
if (IS_PIPEEND(p)) if (IS_PIPEEND(p))
{ {

View file

@ -6,16 +6,26 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */
/* Updated: 2017/03/20 16:09:02 by gwojda ### ########.fr */ /* Updated: 2017/03/20 20:40:43 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static void print_error(char *std) static int print_error(char *std)
{ {
ft_dprintf(2, "{red}%s: internal fcntl %s error errno=%i{eoc}\n", ft_dprintf(2, "{red}%s: internal fcntl %s error errno=%i{eoc}\n",
SHELL_NAME, std, errno); SHELL_NAME, std, errno);
return (errno);
}
int exec_reset_job(t_job *job)
{
job->id = 0;
job->pgid = 0;
job->attrs = JOB_NOTIFIED;
job->first_process = NULL;
return (0);
} }
int exec_reset(void) int exec_reset(void)
@ -27,20 +37,20 @@ int exec_reset(void)
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
if (errno != EBADF) if (errno != EBADF)
{ {
if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1) if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1
print_error("STDIN"); && errno != EBADF)
if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1) return (print_error("STDIN"));
print_error("STDOUT"); if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1
if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1) && errno != EBADF)
print_error("STDERR"); return (print_error("STDOUT"));
if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1
&& errno != EBADF)
return (print_error("STDERR"));
} }
exec->op_stack = NULL; exec->op_stack = NULL;
exec->fdin = STDIN; exec->fdin = STDIN;
exec->attrs = 0; exec->attrs = 0;
exec->job.id = 0; exec_reset_job(&exec->job);
exec->job.pgid = 0;
exec->job.attrs = JOB_NOTIFIED;
exec->job.first_process = NULL;
tcgetattr(STDIN, &exec->job.tmodes); tcgetattr(STDIN, &exec->job.tmodes);
jobc->first_job = NULL; jobc->first_job = NULL;
jobc->current_id = 1; jobc->current_id = 1;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
/* Updated: 2017/03/20 18:41:25 by wescande ### ########.fr */ /* Updated: 2017/03/20 20:52:03 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -45,7 +45,8 @@ static int do_the_fork_if_i_have_to(t_process *p)
set_exitstatus(1, 1); set_exitstatus(1, 1);
return (0); return (0);
} }
return (p->map.launch(p)); set_exitstatus(p->map.launch(p), 1);
return (0);
} }
return (do_the_muther_forker(p)); return (do_the_muther_forker(p));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/09 14:51:23 by jhalford #+# #+# */ /* Created: 2017/03/09 14:51:23 by jhalford #+# #+# */
/* Updated: 2017/03/19 19:36:11 by wescande ### ########.fr */ /* Updated: 2017/03/20 20:25:06 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -29,7 +29,10 @@ void process_resetfds(t_process *p)
/* else */ /* else */
/* i++; */ /* i++; */
} }
dup2(exec->fd_save[0], STDIN); if (exec->fd_save[0] != -1)
dup2(exec->fd_save[1], STDOUT); dup2(exec->fd_save[0], STDIN);
dup2(exec->fd_save[2], STDERR); if (exec->fd_save[1] != -1)
dup2(exec->fd_save[1], STDOUT);
if (exec->fd_save[2] != -1)
dup2(exec->fd_save[2], STDERR);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/20 18:50:44 by wescande ### ########.fr */ /* Updated: 2017/03/20 20:41:48 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -65,6 +65,7 @@ int process_set(t_process *p, t_btree *ast)
p->fdin = exec->fdin; p->fdin = exec->fdin;
p->to_close = fds[PIPE_READ]; p->to_close = fds[PIPE_READ];
p->fdout = fds[PIPE_WRITE]; p->fdout = fds[PIPE_WRITE];
p->pid = 0;
exec->fdin = fds[PIPE_READ]; exec->fdin = fds[PIPE_READ];
if (!ast) if (!ast)
return (0); return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
/* Updated: 2017/03/20 14:16:48 by jhalford ### ########.fr */ /* Updated: 2017/03/20 20:51:59 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,7 +24,7 @@ int job_addprocess(t_process *p)
job_update_id(); job_update_id();
job->id = jobc->current_id; job->id = jobc->current_id;
job->pgid = SH_IS_INTERACTIVE(data_singleton()->opts) ? job->pgid = SH_IS_INTERACTIVE(data_singleton()->opts) ?
p->pid : getpgid(0); p->pid : data_singleton()->jobc.shell_pgid;
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
} }
job = jobc->first_job->content; job = jobc->first_job->content;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 11:37:40 by jhalford #+# #+# */ /* Created: 2017/03/20 11:37:40 by jhalford #+# #+# */
/* Updated: 2017/03/20 11:37:53 by jhalford ### ########.fr */ /* Updated: 2017/03/20 20:51:54 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,7 +23,8 @@ void job_hup_all(void)
while (jlist) while (jlist)
{ {
job = jlist->content; job = jlist->content;
kill(-job->pgid, SIGHUP); if (job->pgid != 1)
kill(-job->pgid, SIGHUP);
jlist = jlist->next; jlist = jlist->next;
} }
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */ /* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */
/* Updated: 2017/03/20 14:31:22 by jhalford ### ########.fr */ /* Updated: 2017/03/20 20:19:55 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,12 +25,10 @@ void job_remove(int id)
j = jlist->content; j = jlist->content;
if (job_is_completed(j)) if (job_is_completed(j))
{ {
DG();
p = ft_lstlast(j->first_process)->content; p = ft_lstlast(j->first_process)->content;
set_exitstatus(p->status, 0); set_exitstatus(p->status, 0);
if (id < data_singleton()->jobc.current_id) if (id < data_singleton()->jobc.current_id)
data_singleton()->jobc.current_id = id; data_singleton()->jobc.current_id = id;
ft_lst_delif(&jobc->first_job, &id, job_cmp_id, job_free); ft_lst_delif(&jobc->first_job, &id, job_cmp_id, job_free);
DG();
} }
} }