process_launch refactor
This commit is contained in:
parent
d2add7891e
commit
6b67ceb224
4 changed files with 18 additions and 21 deletions
|
|
@ -6,14 +6,14 @@
|
||||||
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||||
# Updated: 2017/03/27 15:09:22 by ariard ### ########.fr #
|
# Updated: 2017/03/27 16:09:37 by jhalford ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
NAME = 42sh
|
NAME = 42sh
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
FLAGS = -Wall -Wextra -Werror -fsanitize=address
|
FLAGS = -Wall -Wextra -Werror #-fsanitize=address
|
||||||
D_FLAGS = -g
|
D_FLAGS = -g
|
||||||
|
|
||||||
DELTA = $$(echo "$$(tput cols)-47"|bc)
|
DELTA = $$(echo "$$(tput cols)-47"|bc)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
|
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/27 16:02:52 by jhalford ### ########.fr */
|
/* Updated: 2017/03/27 16:46:06 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -28,8 +28,8 @@ int plaunch_file(t_process *p)
|
||||||
error_launch(p->data.cmd.av[0], ": is a directory", 126);
|
error_launch(p->data.cmd.av[0], ": is a directory", 126);
|
||||||
else if (access(p->data.cmd.path, X_OK) == -1)
|
else if (access(p->data.cmd.path, X_OK) == -1)
|
||||||
error_launch("permission denied: ", p->data.cmd.av[0], 126);
|
error_launch("permission denied: ", p->data.cmd.av[0], 126);
|
||||||
execve(
|
shell_fds_destroy();
|
||||||
p->data.cmd.path,
|
execve(p->data.cmd.path,
|
||||||
p->data.cmd.av,
|
p->data.cmd.av,
|
||||||
data_singleton()->env);
|
data_singleton()->env);
|
||||||
error_launch("internal execve error on ", p->data.cmd.av[0], 42);
|
error_launch("internal execve error on ", p->data.cmd.av[0], 42);
|
||||||
|
|
|
||||||
|
|
@ -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/27 16:04:22 by jhalford ### ########.fr */
|
/* Updated: 2017/03/27 16:46:26 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,25 +16,22 @@ int process_fork(t_process *p)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
|
if (!p)
|
||||||
|
return (0);
|
||||||
if ((pid = fork()) == -1)
|
if ((pid = fork()) == -1)
|
||||||
exit(SH_ERR("fork(): %s", strerror(errno)));
|
exit(SH_ERR("fork(): %s", strerror(errno)));
|
||||||
else if (pid)
|
else if (pid != 0)
|
||||||
return (pid);
|
return (pid);
|
||||||
if (!p)
|
|
||||||
return (pid);
|
|
||||||
if (process_redirect(p))
|
|
||||||
exit(1);
|
|
||||||
process_setgroup(p, 0);
|
|
||||||
process_setsig();
|
|
||||||
exec_destroy(&data_singleton()->exec);
|
exec_destroy(&data_singleton()->exec);
|
||||||
jobc_destroy(&data_singleton()->jobc);
|
jobc_destroy(&data_singleton()->jobc);
|
||||||
if (p->type == PROCESS_FILE)
|
if ((pid = 1) && process_redirect(p) == 0)
|
||||||
shell_fds_destroy();
|
{
|
||||||
else
|
|
||||||
shell_fds_push();
|
shell_fds_push();
|
||||||
data_singleton()->opts &= ~SH_INTERACTIVE;
|
process_setgroup(p, 0);
|
||||||
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
process_setsig();
|
||||||
pid = p->map.launch(p);
|
data_singleton()->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC);
|
||||||
|
pid = p->map.launch(p);
|
||||||
|
}
|
||||||
shell_fds_destroy();
|
shell_fds_destroy();
|
||||||
exit(pid);
|
exit(pid);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/26 22:36:20 by jhalford ### ########.fr */
|
/* Updated: 2017/03/27 16:40:05 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ int redirect_great(t_redir *redir)
|
||||||
if ((try_access(redir->word, 0, W_OK)))
|
if ((try_access(redir->word, 0, W_OK)))
|
||||||
return (ft_perror(NULL));
|
return (ft_perror(NULL));
|
||||||
if ((fdold = open(redir->word, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
|
if ((fdold = open(redir->word, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
|
||||||
exit (1);
|
exit(1);
|
||||||
fd_replace(fdold, fdnew);
|
fd_replace(fdold, fdnew);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue