This commit is contained in:
Jack Halford 2017-01-02 19:09:08 +01:00
parent 72b9e72fc8
commit 4dcf3c319c
17 changed files with 63 additions and 34 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

@ -1 +1 @@
Subproject commit e7cece5732986cdcd159b40f1d927137e2d6c9f3
Subproject commit a26a4be4adbf4d6d4887af95a7307356d52ce85d

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
@ -17,15 +17,23 @@ int builtin_jobs(const char *path, char *const av[], char *const envp[])
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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */