job control: retrieval of dat as a global g_data so signal handlers can access it

This commit is contained in:
Jack Halford 2016-12-10 18:26:09 +01:00
parent 4cfeb62747
commit 09e823bf2b
8 changed files with 31 additions and 11 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2016/12/10 17:36:55 by jhalford ### ########.fr */
/* Updated: 2016/12/10 18:20:40 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,7 +24,13 @@ struct s_job
char *command;
};
extern t_data *g_data;
void job_new(t_data *data, char **av, pid_t pid);
void job_announce(t_job *job);
void sigchld_handler(int signo);
void sigint_handler(int signo);
void sigtstp_handler(int signo);
#endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2016/12/10 17:12:35 by jhalford ### ########.fr */
/* Updated: 2016/12/10 17:56:39 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -76,8 +76,6 @@ typedef enum e_qstate t_qstate;
extern t_stof g_builtins[];
extern pid_t g_pid;
void sigint_handler(int signo);
void sigstop_handler(int signo);
int data_init(t_data *data);
void data_exit(t_data *data);
void ft_cleanup(void);

@ -1 +1 @@
Subproject commit 97bc4fed552dce523e2de8fb744ba46ec877f8eb
Subproject commit 42e1a190bd86ea288ee9a367fefeac8284a67cf4

View file

@ -6,13 +6,13 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:51:54 by jhalford #+# #+# */
/* Updated: 2016/12/10 17:37:33 by jhalford ### ########.fr */
/* Updated: 2016/12/10 17:58:04 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "job_control.h"
void job_new(t_data *data, char **av, pid_t pid, t_type type)
void job_new(t_data *data, char **av, pid_t pid)
{
t_job job;

View file

@ -6,14 +6,26 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 17:37:56 by jhalford #+# #+# */
/* Updated: 2016/12/10 17:46:12 by jhalford ### ########.fr */
/* Updated: 2016/12/10 18:25:01 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_data *g_data;
void sigchld_handler(int signo)
{
t_job *job;
t_list *list;
(void)signo;
DG("got SIGCHLD");
list = g_data->jobc.list;
if (list)
job = list->content;
else
job = NULL;
if (job)
DG("job pid=%i", job->pid);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */
/* Updated: 2016/12/10 17:46:16 by jhalford ### ########.fr */
/* Updated: 2016/12/10 18:20:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2016/12/10 17:35:16 by jhalford ### ########.fr */
/* Updated: 2016/12/10 17:58:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,5 +39,6 @@ int data_init(t_data *data)
if (signal(SIGTSTP, sigtstp_handler) == SIG_ERR)
ft_dprintf(STDERR, "\ncan't catch SIGTSTP\n");
if (signal(SIGCHLD, sigchld_handler) == SIG_ERR)
ft_dprintf(STDERR, "\ncan't catch SIGCHLD\n");
return (0);
}

View file

@ -6,12 +6,14 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2016/12/10 17:16:19 by jhalford ### ########.fr */
/* Updated: 2016/12/10 17:58:39 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_data *g_data;
int main(void)
{
t_data data;
@ -20,6 +22,7 @@ int main(void)
token = NULL;
ast = NULL;
g_data = &data;
if (data_init(&data))
return (1);
DG("{inv}{bol}{gre}start of shell");