From 4dcf3c319c3a1dfeca7ad5a5ee7af9e9deb6de14 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 2 Jan 2017 19:09:08 +0100 Subject: [PATCH] stuff --- 42sh/includes/exec.h | 4 +- 42sh/includes/job_control.h | 2 +- 42sh/libft | 2 +- 42sh/src/exec/exec_command.c | 6 +-- 42sh/src/exec/exec_or_if.c | 2 +- 42sh/src/exec/launch_process.c | 10 ++--- 42sh/src/exec/process_setexec.c | 10 ++--- 42sh/src/job-control/builtin_jobs.c | 41 +++++++++++++++++--- 42sh/src/job-control/check_chlds.c | 2 +- 42sh/src/job-control/do_job_notification.c | 2 +- 42sh/src/job-control/job_addprocess.c | 2 +- 42sh/src/job-control/job_remove.c | 2 +- 42sh/src/job-control/job_wait.c | 2 +- 42sh/src/job-control/process_free.c | 4 +- 42sh/src/job-control/put_job_in_foreground.c | 2 +- 42sh/src/job-control/sigchld_handler.c | 2 +- 42sh/src/line-editing/ft_prompt.c | 2 +- 17 files changed, 63 insertions(+), 34 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 92324800..2091b5dc 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:24:04 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 18:10:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ struct s_process { - char **argv; + char **av; char *path; t_execf *execf; pid_t pid; diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 037f4f30..2d2e7ec2 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:49:56 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 18:10:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft b/42sh/libft index e7cece57..a26a4be4 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit e7cece5732986cdcd159b40f1d927137e2d6c9f3 +Subproject commit a26a4be4adbf4d6d4887af95a7307356d52ce85d diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index c5e9198e..01b51f5f 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ -/* Updated: 2016/12/15 18:31:12 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 19:07:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,10 +21,10 @@ int exec_command(t_btree **ast) node = (*ast)->item; p = &data_singleton()->exec.process; job = &data_singleton()->exec.job; - p->argv = ft_sstrdup(node->data.sstr); + p->av = ft_sstrdup(node->data.sstr); if (process_setexec(p)) { - ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->argv[0]); + ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]); btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_or_if.c b/42sh/src/exec/exec_or_if.c index a5170f93..6b18060c 100644 --- a/42sh/src/exec/exec_or_if.c +++ b/42sh/src/exec/exec_or_if.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */ -/* Updated: 2016/12/12 18:04:08 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 18:10:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index e87fc724..8c3df938 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2016/12/15 15:21:15 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 18:14:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,15 +19,15 @@ int launch_process(t_process *p) exec = &data_singleton()->exec; if (p->attributes & PROCESS_UNKNOWN) - ft_dprintf(2, "%s: command not found: %s\n", SHELL_NAME, p->argv[0]); + ft_dprintf(2, "%s: command not found: %s\n", SHELL_NAME, p->av[0]); else if (p->attributes & PROCESS_BUILTIN && p->fdout != STDOUT) - set_exitstatus((*p->execf)(p->path, p->argv, data_singleton()->env)); + set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env)); else { if (p->attributes & (PROCESS_BINARY | PROCESS_SCRIPT) && access(p->path, X_OK) == -1) { - ft_dprintf(2, "%s: permission denied: %s\n", SHELL_NAME, p->argv[0]); + ft_dprintf(2, "%s: permission denied: %s\n", SHELL_NAME, p->av[0]); return (-1); } pid = fork(); @@ -35,7 +35,7 @@ int launch_process(t_process *p) { process_setgroup(p); process_redirect(p); - (*p->execf)(p->path, p->argv, data_singleton()->env); + (*p->execf)(p->path, p->av, data_singleton()->env); exit(42); } else if (pid > 0) diff --git a/42sh/src/exec/process_setexec.c b/42sh/src/exec/process_setexec.c index c3b81dc3..802f10a4 100644 --- a/42sh/src/exec/process_setexec.c +++ b/42sh/src/exec/process_setexec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ -/* Updated: 2016/12/15 15:19:11 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 18:15:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,15 +19,15 @@ int process_setexec(t_process *p) DG("process is a builtin"); p->attributes &= PROCESS_BUILTIN; } - else if (ft_strchr(p->argv[0], '/')) + else if (ft_strchr(p->av[0], '/')) { DG("process is a script"); p->execf = &execve; p->attributes &= PROCESS_SCRIPT; - p->path = ft_strdup(p->argv[0]); + p->path = ft_strdup(p->av[0]); } else if ((p->path = ft_findexec(ft_getenv( - data_singleton()->env, "PATH"), p->argv[0]))) + data_singleton()->env, "PATH"), p->av[0]))) { DG("process is binary"); p->execf = &execve; @@ -35,7 +35,7 @@ int process_setexec(t_process *p) } else { - DG("process is '%s' unknown type", p->argv[0]); + DG("process is '%s' unknown type", p->av[0]); p->execf = NULL; p->attributes &= PROCESS_UNKNOWN; return (1); diff --git a/42sh/src/job-control/builtin_jobs.c b/42sh/src/job-control/builtin_jobs.c index a9d9118e..74fe2865 100644 --- a/42sh/src/job-control/builtin_jobs.c +++ b/42sh/src/job-control/builtin_jobs.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:54:01 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 19:07:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,18 +14,26 @@ int builtin_jobs(const char *path, char *const av[], char *const envp[]) { - t_jobc *jobc; - t_list *jlist; - t_job *job; - char rank; + t_jobc *jobc; + t_list *jlist; + t_job *job; + t_list *plist; + t_process *p; + char rank; + int lg; + int firstp; jobc = &data_singleton()->jobc; jlist = jobc->first_job; (void)path; (void)envp; (void)av; + lg = 0; + if (ft_strcmp(av[1], "-l") == 0) + lg = 1; while (jlist) { + firstp = 1; job = jlist->content; rank = ' '; if (job->id == data_singleton()->jobc.rank[0]) @@ -33,8 +41,29 @@ int builtin_jobs(const char *path, char *const av[], char *const envp[]) else if (job->id == data_singleton()->jobc.rank[1]) rank = '-'; ft_printf("{mag}[%i] %c ", job->id, rank); - ft_printf("attributes=%x{eoc}\n", job->attributes); + if (lg) + ft_printf("%i ", p->pid); + ft_printf("attr=%x ", job->attributes); + plist = job->first_process; + while (plist) + { + p = plist->content; + if (lg) + { + if (!firstp) + ft_printf("\n "); + ft_printf("%i ", p->pid); + } + else + ft_putchar(' '); + ft_sstrprint(p->av, ' '); + if (plist->next) + ft_printf(" |"); + plist = plist->next; + firstp = 0; + } jlist = jlist->next; + ft_printf("{eoc}\n"); } return (0); } diff --git a/42sh/src/job-control/check_chlds.c b/42sh/src/job-control/check_chlds.c index b4e02bc7..74baaec3 100644 --- a/42sh/src/job-control/check_chlds.c +++ b/42sh/src/job-control/check_chlds.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:28:40 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:24:33 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 17:32:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/do_job_notification.c b/42sh/src/job-control/do_job_notification.c index b1615415..3e343bd5 100644 --- a/42sh/src/job-control/do_job_notification.c +++ b/42sh/src/job-control/do_job_notification.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:49:37 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 18:21:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index d18a5e20..7aea8e91 100644 --- a/42sh/src/job-control/job_addprocess.c +++ b/42sh/src/job-control/job_addprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ -/* Updated: 2016/12/15 18:31:22 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 18:16:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_remove.c b/42sh/src/job-control/job_remove.c index 3d93d244..ddba50fc 100644 --- a/42sh/src/job-control/job_remove.c +++ b/42sh/src/job-control/job_remove.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:58:48 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 18:15:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index 8cc0483b..e0a72b90 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:40:00 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 17:32:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index b6573002..cfe28194 100644 --- a/42sh/src/job-control/process_free.c +++ b/42sh/src/job-control/process_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2016/12/12 13:02:05 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 18:16:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,6 @@ void process_free(void *content, size_t content_size) (void)content_size; p = content; ft_strdel(&p->path); - ft_sstrfree(p->argv); + ft_sstrfree(p->av); free(p); } diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 108999e9..e9facc5a 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:58:51 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 18:15:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/sigchld_handler.c b/42sh/src/job-control/sigchld_handler.c index e011ebd2..afa70944 100644 --- a/42sh/src/job-control/sigchld_handler.c +++ b/42sh/src/job-control/sigchld_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 17:37:56 by jhalford #+# #+# */ -/* Updated: 2016/12/15 15:06:30 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 18:10:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_prompt.c b/42sh/src/line-editing/ft_prompt.c index 8c7a1338..c0db38fa 100644 --- a/42sh/src/line-editing/ft_prompt.c +++ b/42sh/src/line-editing/ft_prompt.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 14:22:34 by jhalford #+# #+# */ -/* Updated: 2016/12/15 15:07:13 by jhalford ### ########.fr */ +/* Updated: 2017/01/02 18:19:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */