Beispiel #1
0
t_bool			access_error(const char *file)
{
	int				error;

	error = ft_access(file);
	if (error == 0)
		return (FALSE);
	else if (error == ACCESS_NO)
		ft_fdprintf(2, "ft_minishell1: %s: No such file or directory\n", file);
	else if (error == ACCESS_DIR)
		ft_fdprintf(2, "ft_minishell1: %s: Is a directory\n", file);
	else if (error == ACCESS_RIGHT)
		ft_fdprintf(2, "ft_minishell1: %s: Permission denied\n", file);
	else
		ft_fdprintf(2, "ft_minishell1: %s: Cannot access\n", file);
	return (TRUE);
}
Beispiel #2
0
static int		sh_execve(t_info *info, char **env, char **args)
{
	char		buf[PATH_MAX];
	char		*envpath;
	char		defpath[14];
	int			error;

	(void)info;
	(void)args;
	ft_strcpy(defpath, "/bin:/usr/bin");
	if (!(envpath = ft_getenv("PATH", env)))
		envpath = defpath;
	error = resolve_path(info->args[0], envpath, buf);
	if (!error && !(error = ft_access(buf)))
		execve(buf, info->args, env);
	ft_error(error, info->args[0]);
	exit(EXIT_FAILURE);
}
void		msh_saveredir_read(t_mshc *msh, t_red *red, const t_tkn *t[2],
						const t_cmd *cmd)
{
	red->error |= msh_get_redir_nbr(t[0]->ptr, &red->lhsfd, 0);
	if (t[1]->type != MTK_FILE)
		red->error |= MSH_RMISSING;
	else if (*t[1]->ptr == '&')
		red->error |= msh_get_redir_nbr(t[1]->ptr + 1, &red->rhsfd, -1) << 3;
	else
	{
		red->rhsfd = -2;
		red->file = ft_memdup((void*)t[1]->ptr, t[1]->len + 1);
		if (red->file == NULL)
			msh_errmem(msh);
		red->file[t[1]->len] = '\0';
		msh_expand_redir_tilde(msh, red, cmd);
		if (red->file_err || (red->file_err = ft_access(red->file, R_OK)) != 0)
			red->error |= MSH_RINVALID;
	}
	return ;
}
static int	homeroot(const char *src, const char *home, char **ptr)
{
	char	buf[PATH_MAX + 1];
	int		ret;

	if (home == NULL)
		return (-1);
	if ((ret = home_cat(src, home, buf)))
		return (ret);
	if (ft_access(buf, 0) != 0)
		return (-1);
	*ptr = malloc(sizeof(char) * (ft_strlen(buf) +
		ft_strlen(src + ft_strcharlen(src + 1, '/')) + 1));
	if (*ptr == NULL)
		return (ENOMEM);
	**ptr = '\0';
	ft_strcpy(*ptr, buf);
	ft_strcat(*ptr, src + ft_strcharlen(src + 1, '/') + 1);
	ft_resolve_path(*ptr);
	return (0);
}
Beispiel #5
0
int				ft_exec(t_env *env, char **exec_opt, char *path)
{
	pid_t	pid;
	int		statut;
	char	**env_local;
	char	*exec;

	env_local = ft_conv_lst(env);
	pid = fork();
	if (pid == -1)
		return (ft_error("Impossible de chercher le fils dans fork\n", "fork"));
	else if (pid == 0)
	{
		if ((exec = ft_access(exec_opt[0], path)) == NULL ||
				execve(exec, exec_opt, env_local) == -1)
			ft_notfound(exec);
	}
	else
		wait(&statut);
	ft_free_arg(env_local);
	return (0);
}