days work, still a lot to do
This commit is contained in:
parent
fc53e40a4f
commit
72b9e72fc8
31 changed files with 245 additions and 72 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:58:12 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 17:49:35 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,11 +16,13 @@
|
||||||
# include "types.h"
|
# include "types.h"
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
|
|
||||||
t_execf *is_builtin(t_process *p);
|
t_execf *is_builtin(t_process *p);
|
||||||
int builtin_env(const char *path, char *const argv[], char *const envp[]);
|
int builtin_env(const char *path, char *const argv[], char *const envp[]);
|
||||||
int builtin_echo(const char *path, char *const argv[], char *const envp[]);
|
int builtin_echo(const char *path, char *const argv[], char *const envp[]);
|
||||||
int builtin_cd(const char *path, char *const argv[], char *const envp[]);
|
int builtin_cd(const char *path, char *const argv[], char *const envp[]);
|
||||||
int builtin_exit(const char *path, char *const argv[], char *const envp[]);
|
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_setenv(const char *path, char *const argv[], char *const envp[]);
|
||||||
int builtin_unsetenv(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[]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:50:40 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 17:24:04 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:50:50 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 17:49:56 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -55,17 +55,25 @@ struct s_jobc
|
||||||
t_process *job_getprocess(pid_t pid);
|
t_process *job_getprocess(pid_t pid);
|
||||||
int job_addprocess(t_process *p);
|
int job_addprocess(t_process *p);
|
||||||
void job_update_id(void);
|
void job_update_id(void);
|
||||||
void job_print_change(t_job *job, int status);
|
|
||||||
void job_update_rank(void);
|
void job_update_rank(void);
|
||||||
|
|
||||||
|
void do_job_notification(void);
|
||||||
void job_notify_new(t_job *job);
|
void job_notify_new(t_job *job);
|
||||||
|
void job_notify_change(t_job *job, int status);
|
||||||
|
|
||||||
int job_wait(t_job *job);
|
int job_wait(t_job *job);
|
||||||
|
void job_update_status(void);
|
||||||
|
int job_is_stopped(t_job *job);
|
||||||
|
int job_is_completed(t_job *job);
|
||||||
|
void job_remove(t_job *job);
|
||||||
|
void job_free(void *content, size_t content_size);
|
||||||
|
int process_mark_status(pid_t pid, int status);
|
||||||
|
|
||||||
int put_job_in_foreground(t_job *job, int cont);
|
int put_job_in_foreground(t_job *job, int cont);
|
||||||
int put_job_in_background(t_job *job, int cont);
|
int put_job_in_background(t_job *job, int cont);
|
||||||
|
|
||||||
void job_new(char **av, pid_t pid);
|
void job_new(char **av, pid_t pid);
|
||||||
|
|
||||||
void job_free(void *content, size_t content_size);
|
|
||||||
int job_cmp_pid(t_job *job, pid_t *pid);
|
int job_cmp_pid(t_job *job, pid_t *pid);
|
||||||
int job_cmp_id(t_job *job, int *id);
|
int job_cmp_id(t_job *job, int *id);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit c4890729647c61fbe8f4fb627d0fcc098d224e54
|
Subproject commit e7cece5732986cdcd159b40f1d927137e2d6c9f3
|
||||||
|
|
@ -6,11 +6,12 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
|
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:56:40 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 17:50:04 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "builtin.h"
|
||||||
|
|
||||||
#define CDOPT_L 0x001
|
#define CDOPT_L 0x001
|
||||||
#define CDOPT_P 0x002
|
#define CDOPT_P 0x002
|
||||||
#define HAS_CDOPT_P(x) (x & CD_OPT_P)
|
#define HAS_CDOPT_P(x) (x & CD_OPT_P)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:59:05 by jhalford ### ########.fr */
|
/* Updated: 2016/12/13 18:00:26 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:31:18 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 17:48:23 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,6 +19,7 @@ t_stof g_builtin[] = {
|
||||||
{"unsetenv", &builtin_unsetenv},
|
{"unsetenv", &builtin_unsetenv},
|
||||||
{"env", &builtin_env},
|
{"env", &builtin_env},
|
||||||
{"exit", &builtin_exit},
|
{"exit", &builtin_exit},
|
||||||
|
{"jobs", &builtin_jobs},
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
|
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:17:38 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 13:28:36 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,17 +18,13 @@ void ast_free(void *data, size_t content_size)
|
||||||
|
|
||||||
(void)content_size;
|
(void)content_size;
|
||||||
node = data;
|
node = data;
|
||||||
DG("gonna free a node");
|
|
||||||
if (node->type == TK_COMMAND)
|
if (node->type == TK_COMMAND)
|
||||||
{
|
{
|
||||||
DG("ast_free TK_COMMAND");
|
|
||||||
if (node->data.sstr)
|
if (node->data.sstr)
|
||||||
ft_sstrfree(node->data.sstr);
|
ft_sstrfree(node->data.sstr);
|
||||||
}
|
}
|
||||||
else if (node->type == TK_LESS || node->type == TK_GREAT || node->type == TK_DGREAT)
|
else if (node->type == TK_LESS || node->type == TK_GREAT || node->type == TK_DGREAT)
|
||||||
{
|
{
|
||||||
DG("ast_free TK_REDIR %p", node->data.redir.word.word);
|
|
||||||
ft_strdel(&node->data.redir.word.word);
|
ft_strdel(&node->data.redir.word.word);
|
||||||
}
|
}
|
||||||
DG("ast_free done");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */
|
/* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:19:19 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 13:40:11 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:41:09 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 18:31:12 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,10 +22,15 @@ int exec_command(t_btree **ast)
|
||||||
p = &data_singleton()->exec.process;
|
p = &data_singleton()->exec.process;
|
||||||
job = &data_singleton()->exec.job;
|
job = &data_singleton()->exec.job;
|
||||||
p->argv = ft_sstrdup(node->data.sstr);
|
p->argv = ft_sstrdup(node->data.sstr);
|
||||||
DG("gonna launch_process");
|
if (process_setexec(p))
|
||||||
DG("job attr=%i", job->attributes);
|
{
|
||||||
process_setexec(p);
|
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->argv[0]);
|
||||||
|
btree_delone(ast, &ast_free);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
DG("gonna launch_process now");
|
||||||
launch_process(p);
|
launch_process(p);
|
||||||
|
job_addprocess(p);
|
||||||
if (p->fdout == STDOUT)
|
if (p->fdout == STDOUT)
|
||||||
{
|
{
|
||||||
if (JOB_IS_FG(job->attributes))
|
if (JOB_IS_FG(job->attributes))
|
||||||
|
|
@ -33,7 +38,6 @@ int exec_command(t_btree **ast)
|
||||||
else
|
else
|
||||||
put_job_in_background(job, 0);
|
put_job_in_background(job, 0);
|
||||||
}
|
}
|
||||||
job_addprocess(p);
|
|
||||||
btree_delone(ast, &ast_free);
|
btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:40:43 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 15:18:21 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:50:38 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 15:21:15 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -42,11 +42,6 @@ int launch_process(t_process *p)
|
||||||
p->pid = pid;
|
p->pid = pid;
|
||||||
else if (pid == -1)
|
else if (pid == -1)
|
||||||
perror("fork");
|
perror("fork");
|
||||||
if (p->fdout == STDOUT)
|
|
||||||
{
|
|
||||||
waitpid(pid, &p->status, 0);
|
|
||||||
set_exitstatus(p->status);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 17:50:26 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 15:19:11 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -35,9 +35,10 @@ int process_setexec(t_process *p)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DG("process is unknown type");
|
DG("process is '%s' unknown type", p->argv[0]);
|
||||||
p->execf = NULL;
|
p->execf = NULL;
|
||||||
p->attributes &= PROCESS_UNKNOWN;
|
p->attributes &= PROCESS_UNKNOWN;
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
40
42sh/src/job-control/builtin_jobs.c
Normal file
40
42sh/src/job-control/builtin_jobs.c
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* builtin_jobs.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/15 17:54:01 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "job_control.h"
|
||||||
|
|
||||||
|
int builtin_jobs(const char *path, char *const av[], char *const envp[])
|
||||||
|
{
|
||||||
|
t_jobc *jobc;
|
||||||
|
t_list *jlist;
|
||||||
|
t_job *job;
|
||||||
|
char rank;
|
||||||
|
|
||||||
|
jobc = &data_singleton()->jobc;
|
||||||
|
jlist = jobc->first_job;
|
||||||
|
(void)path;
|
||||||
|
(void)envp;
|
||||||
|
(void)av;
|
||||||
|
while (jlist)
|
||||||
|
{
|
||||||
|
job = jlist->content;
|
||||||
|
rank = ' ';
|
||||||
|
if (job->id == data_singleton()->jobc.rank[0])
|
||||||
|
rank = '+';
|
||||||
|
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);
|
||||||
|
jlist = jlist->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/12 12:28:40 by jhalford #+# #+# */
|
/* Created: 2016/12/12 12:28:40 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/12 17:23:14 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 17:24:33 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
40
42sh/src/job-control/do_job_notification.c
Normal file
40
42sh/src/job-control/do_job_notification.c
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* do_job_notification.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/15 17:49:37 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "job_control.h"
|
||||||
|
|
||||||
|
void do_job_notification(void)
|
||||||
|
{
|
||||||
|
t_job *j;
|
||||||
|
t_list *jlist;
|
||||||
|
t_jobc *jobc;
|
||||||
|
|
||||||
|
job_update_status();
|
||||||
|
jobc = &data_singleton()->jobc;
|
||||||
|
jlist = jobc->first_job;
|
||||||
|
while (jlist)
|
||||||
|
{
|
||||||
|
j = jlist->content;
|
||||||
|
DG("checking job [%i]", j->id);
|
||||||
|
if (job_is_completed(j))
|
||||||
|
{
|
||||||
|
job_notify_change(j, 0);
|
||||||
|
job_remove(j);
|
||||||
|
}
|
||||||
|
else if (job_is_stopped(j) && !(j->attributes & JOB_NOTIFIED))
|
||||||
|
{
|
||||||
|
job_notify_change(j, 8);
|
||||||
|
j->attributes &= JOB_NOTIFIED;
|
||||||
|
}
|
||||||
|
jlist = jlist->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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: 2016/12/13 17:06:57 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 18:31:22 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,17 +19,18 @@ int job_addprocess(t_process *p)
|
||||||
|
|
||||||
jobc = &data_singleton()->jobc;
|
jobc = &data_singleton()->jobc;
|
||||||
job = &data_singleton()->exec.job;
|
job = &data_singleton()->exec.job;
|
||||||
if (JOB_IS_BG(job->attributes) && p->fdin == STDIN)
|
if (p->fdin == STDIN)
|
||||||
{
|
{
|
||||||
job_update_id();
|
|
||||||
job->id = jobc->current_id;
|
job->id = jobc->current_id;
|
||||||
|
job_update_id();
|
||||||
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
|
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
|
||||||
jobc->rank[1] = jobc->rank[0];
|
jobc->rank[1] = jobc->rank[0];
|
||||||
jobc->rank[0] = job->id;
|
jobc->rank[0] = job->id;
|
||||||
}
|
}
|
||||||
job = jobc->first_job->content;
|
job = jobc->first_job->content;
|
||||||
|
ft_lstadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
|
||||||
if (JOB_IS_BG(job->attributes) && p->fdout == STDOUT)
|
if (JOB_IS_BG(job->attributes) && p->fdout == STDOUT)
|
||||||
job_notify_new(job);
|
job_notify_new(job);
|
||||||
ft_lstadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
|
DG("adding process to first_job : %i", p->pid);
|
||||||
return (0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */
|
/* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 15:24:26 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 12:42:02 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */
|
/* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/12 16:39:31 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 17:45:36 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "job_control.h"
|
||||||
|
|
||||||
void job_notify_change(t_job *job, int status)
|
void job_notify_change(t_job *job, int status)
|
||||||
{
|
{
|
||||||
|
|
@ -24,6 +24,8 @@ void job_notify_change(t_job *job, int status)
|
||||||
ft_printf("{mag}[%i] %c ", job->id, rank);
|
ft_printf("{mag}[%i] %c ", job->id, rank);
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
ft_printf("{gre}done{mag}");
|
ft_printf("{gre}done{mag}");
|
||||||
|
else if (status == 8)
|
||||||
|
ft_printf("{red}stopped{mag}");
|
||||||
else if (status == 9)
|
else if (status == 9)
|
||||||
ft_printf("{red}killed{mag}");
|
ft_printf("{red}killed{mag}");
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 14:27:01 by jhalford #+# #+# */
|
/* Created: 2016/12/13 14:27:01 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 14:58:23 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 17:15:54 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,14 +14,16 @@
|
||||||
|
|
||||||
void job_notify_new(t_job *job)
|
void job_notify_new(t_job *job)
|
||||||
{
|
{
|
||||||
t_list *process;
|
t_list *plist;
|
||||||
|
t_process *p;
|
||||||
|
|
||||||
ft_printf("{mag}[%i]", job->id);
|
ft_printf("{mag}[%i]", job->id);
|
||||||
process = job->first_process;
|
plist = job->first_process;
|
||||||
while (process)
|
while (plist)
|
||||||
{
|
{
|
||||||
ft_printf(" %i", ((t_process*)process->content)->pid);
|
p = plist->content;
|
||||||
process=process->next;
|
ft_printf(" %i", p->pid);
|
||||||
|
plist = plist->next;
|
||||||
}
|
}
|
||||||
ft_printf("{eoc}\n");
|
ft_printf("{eoc}\n");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
42sh/src/job-control/job_remove.c
Normal file
28
42sh/src/job-control/job_remove.c
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* job_remove.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/15 17:58:48 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "job_control.h"
|
||||||
|
|
||||||
|
void job_remove(t_job *job)
|
||||||
|
{
|
||||||
|
t_jobc *jobc;
|
||||||
|
|
||||||
|
jobc = &data_singleton()->jobc;
|
||||||
|
if (job->id < data_singleton()->jobc.current_id)
|
||||||
|
{
|
||||||
|
data_singleton()->jobc.current_id = job->id;
|
||||||
|
DG("ID_UPDATE(downgrade):%i", job->id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DG("ID_UPDATE(no downgrade): %i/%i", job->id, data_singleton()->jobc.current_id);
|
||||||
|
ft_lst_delif(&jobc->first_job, job, ft_addrcmp, job_free);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/12 13:33:08 by jhalford #+# #+# */
|
/* Created: 2016/12/12 13:33:08 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/12 17:27:59 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 17:15:36 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,6 +24,6 @@ void job_update_id(void)
|
||||||
while (ft_lst_find(start, id, job_cmp_id))
|
while (ft_lst_find(start, id, job_cmp_id))
|
||||||
{
|
{
|
||||||
*id += 1;
|
*id += 1;
|
||||||
DG("id = %i", *id);
|
DG("ID_UPDATE:%i", *id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
42sh/src/job-control/job_update_status.c
Normal file
24
42sh/src/job-control/job_update_status.c
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* job_update_status.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/15 15:09:05 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "job_control.h"
|
||||||
|
|
||||||
|
void job_update_status(void)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
|
DG("updating job status'");
|
||||||
|
pid = waitpid (WAIT_ANY, &status, WUNTRACED|WNOHANG);
|
||||||
|
while (!process_mark_status(pid, status))
|
||||||
|
pid = waitpid (WAIT_ANY, &status, WUNTRACED|WNOHANG);
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* job_wait.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/12/15 17:40:00 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "job_control.h"
|
#include "job_control.h"
|
||||||
|
|
||||||
int job_wait(t_job *job)
|
int job_wait(t_job *job)
|
||||||
{
|
{
|
||||||
(void)job;
|
pid_t pid;
|
||||||
return (0);
|
int status;
|
||||||
|
|
||||||
|
pid = waitpid(WAIT_ANY, &status, WUNTRACED);
|
||||||
|
while (!(process_mark_status(pid, status)
|
||||||
|
|| job_is_stopped(job)
|
||||||
|
|| job_is_completed(job)))
|
||||||
|
{
|
||||||
|
pid = waitpid(WAIT_ANY, &status, WUNTRACED);
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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: 2016/12/12 13:02:05 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 15:12:38 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,13 +15,13 @@
|
||||||
int process_mark_status(pid_t pid, int status)
|
int process_mark_status(pid_t pid, int status)
|
||||||
{
|
{
|
||||||
t_process *p;
|
t_process *p;
|
||||||
t_jobc *jobc;
|
|
||||||
|
|
||||||
jobc = &data_singleton()->jobc;
|
DG("marking: pid=%i, status=%i", pid, status);
|
||||||
if (pid > 0)
|
if (pid > 0)
|
||||||
{
|
{
|
||||||
if ((p = job_getprocess(pid)))
|
if ((p = job_getprocess(pid)))
|
||||||
{
|
{
|
||||||
|
DG("found process pid=%i", pid);
|
||||||
p->status = status;
|
p->status = status;
|
||||||
if (WIFSTOPPED(status))
|
if (WIFSTOPPED(status))
|
||||||
p->attributes &= PROCESS_STOPPED;
|
p->attributes &= PROCESS_STOPPED;
|
||||||
|
|
@ -30,13 +30,15 @@ int process_mark_status(pid_t pid, int status)
|
||||||
p->attributes &= PROCESS_COMPLETED;
|
p->attributes &= PROCESS_COMPLETED;
|
||||||
if (WIFSIGNALED(status))
|
if (WIFSIGNALED(status))
|
||||||
ft_printf("%d: Terminated by signal %d.\n",
|
ft_printf("%d: Terminated by signal %d.\n",
|
||||||
(int) pid, WTERMSIG (p->status));
|
(int) pid, WTERMSIG(p->status));
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
ft_dprintf(STDERR, "No child process %d.\n", pid);
|
ft_dprintf(2, "No child process %d.\n", pid);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return(-1);
|
return(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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: 2016/12/13 15:04:12 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 17:53:24 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
|
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 15:06:21 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 17:58:51 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -27,7 +27,10 @@ int put_job_in_foreground(t_job *job, int cont)
|
||||||
perror("kill (SIGCONT)");
|
perror("kill (SIGCONT)");
|
||||||
}
|
}
|
||||||
/* Wait for it to report. */
|
/* Wait for it to report. */
|
||||||
|
DG("gonna wait for job");
|
||||||
job_wait(job);
|
job_wait(job);
|
||||||
|
DG("gonna remove job");
|
||||||
|
job_remove(job);
|
||||||
|
|
||||||
/* Put the shell back in the foreground. */
|
/* Put the shell back in the foreground. */
|
||||||
tcsetpgrp(STDIN_FILENO, jobc->shell_pgid);
|
tcsetpgrp(STDIN_FILENO, jobc->shell_pgid);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/10 17:37:56 by jhalford #+# #+# */
|
/* Created: 2016/12/10 17:37:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/12 16:49:07 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 15:06:30 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,5 +18,6 @@ void sigchld_handler(int signo)
|
||||||
|
|
||||||
(void)signo;
|
(void)signo;
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
DG("got asynchronous notification (SIGCHLD)");
|
DG("got asynchronous notification (SIGCHLD)");
|
||||||
|
job_update_status();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 14:22:34 by jhalford #+# #+# */
|
/* Created: 2016/11/10 14:22:34 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/12 16:49:05 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 15:07:13 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,6 +17,8 @@ int ft_prompt(void)
|
||||||
t_data *data;
|
t_data *data;
|
||||||
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
|
do_job_notification();
|
||||||
|
DG("new prompt now");
|
||||||
ft_putstr(SHELL_PROMPT);
|
ft_putstr(SHELL_PROMPT);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 11:19:51 by jhalford #+# #+# */
|
/* Created: 2016/12/13 11:19:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 11:52:47 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 15:41:08 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/13 12:05:51 by jhalford ### ########.fr */
|
/* Updated: 2016/12/15 17:03:55 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -33,15 +33,14 @@ int main(void)
|
||||||
return (1);
|
return (1);
|
||||||
if (!token)
|
if (!token)
|
||||||
continue ;
|
continue ;
|
||||||
token_print(token);
|
/* token_print(token); */
|
||||||
if (ft_parse(&ast, &token))
|
if (ft_parse(&ast, &token))
|
||||||
return (1);
|
return (1);
|
||||||
btree_print(STDERR, ast, &ft_putast);
|
btree_print(STDBUG, ast, &ft_putast);
|
||||||
/* ft_dprintf(STDERR, "\n--- INFIX BREAKDOWN ---\n"); */
|
/* ft_dprintf(STDBUG, "\n--- INFIX BREAKDOWN ---\n"); */
|
||||||
/* btree_apply_infix(ast, &ft_putast2); */
|
/* btree_apply_infix(ast, &ft_putast2); */
|
||||||
if (ft_exec(&ast))
|
if (ft_exec(&ast))
|
||||||
return (1);
|
return (1);
|
||||||
DG("end of loop");
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue