Merge branch 'dev' of github.com:tvdu29/minishell into dev

This commit is contained in:
Tanguy Maze 2019-10-18 14:22:39 +02:00
commit e32efb9312
7 changed files with 29 additions and 31 deletions

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 14:42:42 by tmaze #+# #+# */ /* Created: 2019/09/20 14:42:42 by tmaze #+# #+# */
/* Updated: 2019/09/26 15:26:44 by tmaze ### ########.fr */ /* Updated: 2019/10/17 10:59:38 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 14:42:30 by tmaze #+# #+# */ /* Created: 2019/09/20 14:42:30 by tmaze #+# #+# */
/* Updated: 2019/09/26 15:26:53 by tmaze ### ########.fr */ /* Updated: 2019/10/17 10:58:52 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 14:33:48 by tmaze #+# #+# */ /* Created: 2019/09/20 14:33:48 by tmaze #+# #+# */
/* Updated: 2019/10/10 13:49:33 by tmaze ### ########.fr */ /* Updated: 2019/10/17 10:07:21 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 14:41:08 by tmaze #+# #+# */ /* Created: 2019/09/20 14:41:08 by tmaze #+# #+# */
/* Updated: 2019/10/10 14:31:47 by tmaze ### ########.fr */ /* Updated: 2019/10/17 09:59:40 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,10 +20,14 @@ int cmd_setenv(char** argv, t_env** env)
{ {
lstaddend(env, new); lstaddend(env, new);
return (0); return (0);
} else if (argv[1]) { }
else if (argv[1])
{
ft_printf("minishell: setenv: memory error\n"); ft_printf("minishell: setenv: memory error\n");
return (2); return (2);
} else { }
else
{
printf("usage: setenv [KEY]=[value]\n"); printf("usage: setenv [KEY]=[value]\n");
return (1); return (1);
} }

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 14:42:01 by tmaze #+# #+# */ /* Created: 2019/09/20 14:42:01 by tmaze #+# #+# */
/* Updated: 2019/10/10 16:05:56 by tmaze ### ########.fr */ /* Updated: 2019/10/17 10:58:23 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 11:43:53 by tmaze #+# #+# */ /* Created: 2019/09/20 11:43:53 by tmaze #+# #+# */
/* Updated: 2019/10/18 14:17:12 by tmaze ### ########.fr */ /* Updated: 2019/10/18 14:20:41 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/26 16:25:00 by tmaze #+# #+# */ /* Created: 2019/09/26 16:25:00 by tmaze #+# #+# */
/* Updated: 2019/10/18 14:10:59 by tmaze ### ########.fr */ /* Updated: 2019/10/18 14:22:23 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -98,19 +98,9 @@ char *check_path(char *exec, t_env *env)
if (exec) if (exec)
{ {
if (ft_isin(exec, '/') != -1 && ft_isin(exec, '.') == -1) if (ft_isin(exec, '/') != -1 && ft_isin(exec, '.') == -1)
{ return (check_path_slash(exec));
if ((ret = check_path_slash(exec)) != NULL)
return (ret);
else
return (NULL);
}
if (exec[0] == '.') if (exec[0] == '.')
{ return (check_path_dot(exec, env));
if ((ret = check_path_dot(exec, env)) != NULL)
return (ret);
else
return (NULL);
}
if ((path = lstgetelem("PATH", env)) == NULL if ((path = lstgetelem("PATH", env)) == NULL
|| path->val == NULL || path->val == NULL
|| (path_elems = ft_strsplit(path->val, ':')) == NULL) || (path_elems = ft_strsplit(path->val, ':')) == NULL)
@ -137,6 +127,9 @@ char *check_path(char *exec, t_env *env)
if (access(ret, X_OK) == 0) if (access(ret, X_OK) == 0)
break ; break ;
put_error(exec, "permission denied"); put_error(exec, "permission denied");
ft_strdel(&ret);
ft_del_words_tables(&path_elems);
return (NULL);
} }
ft_strdel(&ret); ft_strdel(&ret);
i++; i++;
@ -158,6 +151,7 @@ int exec_cmd(char **argv, t_env **env)
return (-1); return (-1);
if ((path = check_path(argv[0], *env)) == NULL) if ((path = check_path(argv[0], *env)) == NULL)
ft_del_words_tables(&env_tab); ft_del_words_tables(&env_tab);
ft_printf("path after resolve: %s\n", path);
if (path == NULL) if (path == NULL)
return (-1); return (-1);
if ((ret = fork()) == 0) if ((ret = fork()) == 0)