This commit is contained in:
Jack Halford 2017-03-24 18:24:23 +01:00
parent 1ba52fff84
commit deb53a6b96
13 changed files with 81 additions and 33 deletions

View file

@ -141,6 +141,7 @@ sstr/ft_sstrcat.c\
sstr/ft_sstrdel.c\ sstr/ft_sstrdel.c\
sstr/ft_sstrdup.c\ sstr/ft_sstrdup.c\
sstr/ft_sstrfree.c\ sstr/ft_sstrfree.c\
sstr/ft_sstrmerge.c\
sstr/ft_sstrprint.c\ sstr/ft_sstrprint.c\
sstr/ft_sstrprint_fd.c\ sstr/ft_sstrprint_fd.c\
sstr/ft_sstrsort.c\ sstr/ft_sstrsort.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/18 13:16:25 by jhalford #+# #+# */ /* Created: 2017/02/18 13:16:25 by jhalford #+# #+# */
/* Updated: 2017/03/07 11:35:11 by ariard ### ########.fr */ /* Updated: 2017/03/24 17:46:36 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,6 +18,7 @@ void ft_sstrsort(char **list, int (*cmp)());
void ft_sstrprint(char **list, char sep); void ft_sstrprint(char **list, char sep);
void ft_sstrprint_fd(int fd, char **list, char sep); void ft_sstrprint_fd(int fd, char **list, char sep);
char **ft_sstrdup(char **list); char **ft_sstrdup(char **list);
char **ft_sstrmerge(char **s1, char **s2);
void ft_sstrdel(char **sstr, int index); void ft_sstrdel(char **sstr, int index);
void ft_sstrfree(char **sstr); void ft_sstrfree(char **sstr);
char *ft_sstrcat(char **sstr, char sep); char *ft_sstrcat(char **sstr, char sep);

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sstrmerge.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 17:40:50 by jhalford #+# #+# */
/* Updated: 2017/03/24 18:05:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_sstrmerge(char **s1, char **s2)
{
char **out;
out = ft_sstrdup(s1);
if (!s2)
return (out);
while (*s2)
{
out = ft_sstradd(out, *s2);
s2++;
}
return (out);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */ /* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */
/* Updated: 2017/03/24 15:11:42 by jhalford ### ########.fr */ /* Updated: 2017/03/24 17:59:00 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,11 +18,11 @@
t_cliopts g_env_opts[] = t_cliopts g_env_opts[] =
{ {
{'i', NULL, BT_ENV_LI, 0, bt_env_geti}, {'i', NULL, BT_ENV_LI, 0, NULL},
{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
}; };
int bt_env_geti(char ***av, t_env_data *data) int bt_env_getcustom(char ***av, t_env_data *data)
{ {
if (!av || !*av || !data) if (!av || !*av || !data)
return (1); return (1);
@ -31,7 +31,6 @@ int bt_env_geti(char ***av, t_env_data *data)
data->custom_env = ft_sstradd(data->custom_env, **av); data->custom_env = ft_sstradd(data->custom_env, **av);
++(*av); ++(*av);
} }
--(*av);
return (0); return (0);
} }
@ -39,9 +38,19 @@ static int bt_env_parse(t_env_data *data, char **av)
{ {
data->flag = 0; data->flag = 0;
data->av_data = NULL; data->av_data = NULL;
data->custom_env = NULL; DG();
if (cliopts_get(av, g_env_opts, data)) if (cliopts_get(av, g_env_opts, data))
return (1); return (1);
DG();
data->custom_env = NULL;
bt_env_getcustom(&data->av_data, data);
DG();
if (!(data->flag & BT_ENV_LI))
{
DG("no -i");
data->custom_env = ft_sstrmerge(data_singleton()->env, data->custom_env);
}
DG();
return (0); return (0);
} }
@ -55,11 +64,18 @@ int builtin_env(const char *path,
(void)envp; (void)envp;
if (bt_env_parse(&data, (char**)argv)) if (bt_env_parse(&data, (char**)argv))
return (ft_perror("env") && SH_ERR("usage: %s", ENV_USAGE) ? 0 : 0); return (ft_perror("env") && SH_ERR("usage: %s", ENV_USAGE));
else if (!*data.av_data) DG();
return (builtin_setenv(NULL, (char*[]){"setenv", 0}, NULL)); if (!*data.av_data)
{
DG();
ft_sstrprint(data.custom_env, '\n');
ft_putchar('\n');
return (0);
}
else if ((pid = fork()) == 0) else if ((pid = fork()) == 0)
{ {
DG();
if (!(path = ft_strchr(data.av_data[0], '/') ? if (!(path = ft_strchr(data.av_data[0], '/') ?
ft_strdup(data.av_data[0]) : ft_hash(data.av_data[0])) ft_strdup(data.av_data[0]) : ft_hash(data.av_data[0]))
|| access(path, F_OK) != 0) || access(path, F_OK) != 0)

View file

@ -6,7 +6,7 @@
/* 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/24 14:06:48 by jhalford ### ########.fr */ /* Updated: 2017/03/24 18:23:49 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,6 +18,7 @@ int exec_reset_job(t_job *job)
job->pgid = 0; job->pgid = 0;
job->attrs = 0; job->attrs = 0;
job->first_process = NULL; job->first_process = NULL;
tcgetattr(STDIN, &job->tmodes);
return (0); return (0);
} }
@ -31,12 +32,11 @@ int exec_reset(void)
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
i = -1; i = -1;
while (++i < 10) while (++i < 10)
exec->fd_save[i] = fcntl(i, F_DUPFD_CLOEXEC, 10); exec->fd_save[i] = fcntl(i, F_DUPFD, 10);
exec->op_stack = NULL; exec->op_stack = NULL;
exec->fdin = STDIN; exec->fdin = STDIN;
exec->attrs = 0; exec->attrs = 0;
exec_reset_job(&exec->job); exec_reset_job(&exec->job);
tcgetattr(STDIN, &exec->job.tmodes);
jobc->first_job = NULL; jobc->first_job = NULL;
jobc->current_id = 1; jobc->current_id = 1;
return (0); return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/03/21 14:05:28 by jhalford ### ########.fr */ /* Updated: 2017/03/24 17:28:45 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,6 +16,7 @@ int mark_process_status(pid_t pid, int status)
{ {
t_list *plist; t_list *plist;
t_process *p; t_process *p;
int signo;
if ((plist = job_getprocess(pid))) if ((plist = job_getprocess(pid)))
{ {
@ -26,8 +27,11 @@ int mark_process_status(pid_t pid, int status)
else else
{ {
p->state = PROCESS_COMPLETED; p->state = PROCESS_COMPLETED;
if (WIFSIGNALED(status) && WTERMSIG(status) != SIGPIPE) if (WIFSIGNALED(status) && (signo = WTERMSIG(status)))
ft_dprintf(2, "%s\n", strsignal((WTERMSIG(status)))); {
if (signo != SIGPIPE && signo != SIGINT)
ft_dprintf(2, "%s\n", strsignal(signo));
}
} }
return (0); return (0);
} }

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/24 14:56:32 by wescande ### ########.fr */ /* Updated: 2017/03/24 18:22:16 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,7 +41,10 @@ int process_launch(t_process *p)
if (process_redirect(p)) if (process_redirect(p))
set_exitstatus(1, 1); set_exitstatus(1, 1);
else else
{
exec_reset();
p->map.launch(p); p->map.launch(p);
}
shell_resetfds(); shell_resetfds();
shell_resetsig(); shell_resetsig();
process_free(p, 0); process_free(p, 0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */ /* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */
/* Updated: 2017/03/20 18:15:43 by gwojda ### ########.fr */ /* Updated: 2017/03/24 16:58:17 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,6 +21,6 @@ int redirect_great(t_redir *redir)
if ((fdold = open(redir->word, if ((fdold = open(redir->word,
O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
exit(1); exit(1);
dup2(fdold, fdnew); dup2_close(fdold, fdnew);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */ /* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
/* Updated: 2017/03/24 15:39:48 by jhalford ### ########.fr */ /* Updated: 2017/03/24 18:17:02 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -66,12 +66,9 @@ int builtin_jobs(const char *path, char *const av[], char *const envp[])
(void)path; (void)path;
(void)envp; (void)envp;
do_job_notification();
if (!SH_HAS_JOBC(data_singleton()->opts)) if (!SH_HAS_JOBC(data_singleton()->opts))
{ return (SH_ERR("jobs: %s", SH_MSG_NOJOBC));
SH_ERR("jobs: %s", SH_MSG_NOJOBC); do_job_notification();
return (1);
}
ft_bzero(&data, sizeof(t_data_template)); ft_bzero(&data, sizeof(t_data_template));
if (cliopts_get((char**)av, g_jobs_opts, &data)) if (cliopts_get((char**)av, g_jobs_opts, &data))
return (ft_perror("jobs")); return (ft_perror("jobs"));

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:10:38 by jhalford #+# #+# */ /* Created: 2017/01/09 13:10:38 by jhalford #+# #+# */
/* Updated: 2017/03/21 14:55:16 by jhalford ### ########.fr */ /* Updated: 2017/03/24 16:55:55 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,6 +20,5 @@ void job_format_head(t_job *j)
job_getrank(&rank); job_getrank(&rank);
crank = j->id == rank[0] ? '+' : ' '; crank = j->id == rank[0] ? '+' : ' ';
crank = j->id == rank[1] ? '-' : crank; crank = j->id == rank[1] ? '-' : crank;
DG("raks [%i:%i]", rank[0], rank[1]);
ft_printf("{mag}[%i]%c {eoc}", j->id, crank); ft_printf("{mag}[%i]%c {eoc}", j->id, crank);
} }

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/24 15:40:55 by jhalford ### ########.fr */ /* Updated: 2017/03/24 15:54:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,11 +25,8 @@ void job_hup_all(void)
while (jlist) while (jlist)
{ {
job = jlist->content; job = jlist->content;
DG("gonna SIGHUP %i", job->pgid);
builtin_jobs(NULL, NULL, NULL);
if (job->pgid != 1) if (job->pgid != 1)
kill(-job->pgid, SIGHUP); kill(-job->pgid, SIGHUP);
DG("after SIGHUP %i", job->pgid);
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/13 15:03:29 by jhalford #+# #+# */ /* Created: 2016/12/13 15:03:29 by jhalford #+# #+# */
/* Updated: 2017/03/10 15:08:14 by jhalford ### ########.fr */ /* Updated: 2017/03/24 17:24:46 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,6 +16,6 @@ int put_job_in_background(t_job *j, int cont)
{ {
if (cont) if (cont)
if (kill(-j->pgid, SIGCONT) < 0) if (kill(-j->pgid, SIGCONT) < 0)
DG("kill(SIGCONT) failed"); SH_ERR("kill(): %s", strerror(errno));
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
/* Updated: 2017/03/24 15:30:51 by jhalford ### ########.fr */ /* Updated: 2017/03/24 18:23:39 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -49,6 +49,8 @@ static int handle_instruction(t_list **token, t_btree **ast)
else if (ret > 0) else if (ret > 0)
break ; break ;
} }
/* btree_print(3, *ast, ft_putast); */
/* exit(1); */
if (data->parser.state == SUCCESS && ft_exec(ast) < 0) if (data->parser.state == SUCCESS && ft_exec(ast) < 0)
exit(1); exit(1);
else if (data->parser.state != SUCCESS) else if (data->parser.state != SUCCESS)