builtin now return their exit status, gonna merge onto master
This commit is contained in:
parent
9e8855a9ef
commit
3ef3bc8f0a
15 changed files with 23 additions and 54 deletions
|
|
@ -40,7 +40,6 @@ builtin/builtin_hash.c\
|
|||
builtin/builtin_history.c\
|
||||
builtin/builtin_math.c\
|
||||
builtin/builtin_read.c\
|
||||
builtin/builtin_return_status.c\
|
||||
builtin/builtin_setenv.c\
|
||||
builtin/builtin_unset.c\
|
||||
builtin/builtin_unsetenv.c\
|
||||
|
|
|
|||
|
|
@ -59,6 +59,6 @@ int builtin_env(const char *path,
|
|||
}
|
||||
waitpid(pid, &status, 0);
|
||||
ft_sstrfree(data.custom_env);
|
||||
tcsetpgrp(STDIN, data_singleton()->jobc.shell_pgid);
|
||||
return (0);
|
||||
/* return (builtin_return_status(pid, 0)); */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ int builtin_exit(const char *path, char *const av[], char *const envp[])
|
|||
tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes);
|
||||
job_hup_all();
|
||||
data_exit();
|
||||
DG("EXITING NOW");
|
||||
exit(status);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ int builtin_export(
|
|||
if (cliopts_get((char**)av, g_export_opts, &data))
|
||||
ft_perror();
|
||||
if (data.flag & BT_EXPORT_LP)
|
||||
return (builtin_return_status(0, bt_export_print()));
|
||||
return (bt_export_print());
|
||||
av = data.av_data;
|
||||
while (*av)
|
||||
{
|
||||
|
|
@ -61,5 +61,5 @@ int builtin_export(
|
|||
builtin_unsetenv("internal", (char*[]){"local", *av, NULL}, NULL);
|
||||
av++;
|
||||
}
|
||||
return (builtin_return_status(0, 0));
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ int builtin_hash(const char *path, char *const av[], char *const envp[])
|
|||
(void)path;
|
||||
(void)envp;
|
||||
if (!av || ft_hash_opt(av))
|
||||
return (builtin_return_status(0, 1));
|
||||
return (1);
|
||||
i = 0;
|
||||
while (i < MAX_HASH)
|
||||
{
|
||||
|
|
@ -52,5 +52,5 @@ int builtin_hash(const char *path, char *const av[], char *const envp[])
|
|||
ft_hash_lst_print(g_hash[i]);
|
||||
++i;
|
||||
}
|
||||
return (builtin_return_status(0, 0));
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ int builtin_history(const char *path, char *const av[], char *const envp[])
|
|||
head = data_singleton()->line.list_end;
|
||||
len = 1;
|
||||
if (!head)
|
||||
return (builtin_return_status(0, 0));
|
||||
return (0);
|
||||
if (head && !head->str)
|
||||
head = head->next;
|
||||
while (head && head->str)
|
||||
|
|
@ -34,5 +34,5 @@ int builtin_history(const char *path, char *const av[], char *const envp[])
|
|||
++len;
|
||||
head = head->next;
|
||||
}
|
||||
return (builtin_return_status(0, 0));
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,19 +90,19 @@ int builtin_math(const char *path, char *const av[], char *const envp[])
|
|||
(void)path;
|
||||
(void)envp;
|
||||
if (!av || !av[1] || !av[2] || !av[3] || av[4])
|
||||
return (builtin_return_status(0, SH_ERR(MATHERR_0)));
|
||||
return (SH_ERR(MATHERR_0));
|
||||
init_math(&var, &value, &operator, &operand);
|
||||
var = av[1];
|
||||
if (get_value(var, &value))
|
||||
return (builtin_return_status(0, 1));
|
||||
return (1);
|
||||
operator = av[2];
|
||||
if (ft_strlen(operator) != 1 || !(ft_strchr("+-/*%", operator[0])))
|
||||
return (builtin_return_status(0, SH_ERR(MATHERR_2)));
|
||||
return (SH_ERR(MATHERR_2));
|
||||
operand = av[3];
|
||||
if (!ft_stris(operand, &ft_isdigit))
|
||||
return (builtin_return_status(0, SH_ERR(MATHERR_3)));
|
||||
return (SH_ERR(MATHERR_3));
|
||||
if (do_math(&value, operator, operand))
|
||||
return (builtin_return_status(0, 1));
|
||||
return (1);
|
||||
builtin_setenv("setenv", (char *[]){"local", var, value, 0}, NULL);
|
||||
return (builtin_return_status(0, 0));
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,5 +114,5 @@ int builtin_read(const char *path, char *const av[], char *const envp[])
|
|||
SH_ERR("usage: read %s %s\n", US_READ, US_READ_1);
|
||||
if (ret != 2)
|
||||
bt_read_exit(&data);
|
||||
return (builtin_return_status(0, ret));
|
||||
return (ret);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* builtin_return_status.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/20 12:48:04 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/21 15:21:09 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int builtin_return_status(int ret, int status)
|
||||
{
|
||||
set_exitstatus(status, 1);
|
||||
return (ret);
|
||||
}
|
||||
|
|
@ -44,8 +44,9 @@ int builtin_setenv(const char *path,
|
|||
int ret;
|
||||
|
||||
(void)path;
|
||||
(void)envp;
|
||||
if (!av || !av[0])
|
||||
return (builtin_return_status(0, 1));
|
||||
return (1);
|
||||
env = (ft_strcmp(av[0], "local") == 0) ? &data_singleton()->local_var :
|
||||
&data_singleton()->env;
|
||||
if (!av[1])
|
||||
|
|
@ -62,5 +63,5 @@ int builtin_setenv(const char *path,
|
|||
return (SH_ERR(SETERR_0));
|
||||
assign_var(av, env);
|
||||
}
|
||||
return (envp ? builtin_return_status(0, 0) : 0);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,5 +35,5 @@ int builtin_unsetenv(const char *path, char *const av[], char *const envp[])
|
|||
}
|
||||
i++;
|
||||
}
|
||||
return (builtin_return_status(0, 0));
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,9 +38,8 @@ int exec_leaf(t_btree **ast)
|
|||
if (p.type >= PROCESS_MAX)
|
||||
return (1);
|
||||
p.map = g_process_map[p.type];
|
||||
if (!(process_launch(&p)))
|
||||
if (process_launch(&p))
|
||||
{
|
||||
DG("check");
|
||||
job_addprocess(&p);
|
||||
if (IS_PIPEEND(p))
|
||||
{
|
||||
|
|
@ -51,7 +50,5 @@ int exec_leaf(t_btree **ast)
|
|||
job->pgid = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
DG("WHY HERE? --> because no fork means no job control");
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,14 +42,12 @@ int process_launch(t_process *p)
|
|||
&& p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL)
|
||||
{
|
||||
if (process_redirect(p))
|
||||
{
|
||||
set_exitstatus(1, 1);
|
||||
return (0);
|
||||
}
|
||||
set_exitstatus(p->map.launch(p), 1);
|
||||
else
|
||||
set_exitstatus(p->map.launch(p), 1);
|
||||
process_resetfds(p);
|
||||
process_free(p, 0);
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
p->pid = process_fork(p);
|
||||
process_setgroup(p, p->pid);
|
||||
|
|
@ -57,5 +55,5 @@ int process_launch(t_process *p)
|
|||
close(p->fdin);
|
||||
if (p->fdout != STDOUT)
|
||||
close(p->fdout);
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,6 @@ void process_resetfds(t_process *p)
|
|||
while (++i < 10)
|
||||
{
|
||||
if (exec->fd_save[i] != -1)
|
||||
{
|
||||
DG("dup2(%i, %i)", exec->fd_save[i], i);
|
||||
dup2(exec->fd_save[i], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,10 +59,7 @@ static int read_stdin(int *ret, int *j)
|
|||
*j = 0;
|
||||
*ret = 0;
|
||||
if (read(STDIN, ret, sizeof(int)) < 0)
|
||||
{
|
||||
DG("read problem: %s", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue