コード例 #1
0
ファイル: parser.c プロジェクト: Zethir/42sh
void			exec_process(t_shell *sh, t_job *job, int *iofile)
{
	t_parse *parse;

	parse = init_parse(sh, job->process->cmd);
	if (check_builtins(parse->argv[0]))
	{
		if (iofile[0] != 0)
			job->process->stdio[0] = iofile[0];
		if (iofile[1] != 1)
			job->process->stdio[1] = iofile[1];
		launch_builtin(sh, parse, job);
	}
	else if ((job->process->pid = fork()) == 0)
	{
		if (iofile[0] != 0)
			job->process->stdio[0] = iofile[0];
		if (iofile[1] != 1)
			job->process->stdio[1] = iofile[1];
		launch_bin(parse, job);
	}
	free_parse(&parse);
	if (iofile[0] != 0)
		close(iofile[0]);
	if (iofile[1] != 1)
		close(iofile[1]);
}
コード例 #2
0
ファイル: cmd.c プロジェクト: agadiffe/ft_sh
void			handle_cmds(t_state *state, char *line, char **cmds)
{
	if (check_builtins(state, cmds[0]))
		run_builtins(state, cmds, line);
	else if (!is_exist_cmd(state->pwd))
		print_no_such_file_or_dir(state, cmds[0], state->pwd);
	else if (!is_exec_cmd(state->pwd))
		print_permission_denied(state, cmds[0], state->pwd);
	else
		handle_validated_cmd(state, cmds);
}
コード例 #3
0
ファイル: exec_cmd.c プロジェクト: Zethir/42sh
void		exec_env(t_shell *sh, char *arg, char **env_cpy)
{
	t_parse		*parse;
	t_job		*job;

	parse = init_parse(sh, arg);
	job = NULL;
	if (check_builtins(parse->argv[0]))
		do_builtins(sh, job, parse);
	else if ((parse->pid = fork()) == 0)
	{
		if (execve(parse->right_path, parse->argv, env_cpy) < 0)
		{
			ft_putstr_fd("42sh: command not found: ", 2);
			ft_putendl_fd(parse->argv[0], 2);
			exit(127);
		}
	}
	wait(0);
	free_parse(&parse);
}
コード例 #4
0
ファイル: execute_pipes.c プロジェクト: NegMozzie/42sh
int	execute_last_command(t_tree *tree, t_shell *st_shell)
{
  int	statut;
  pid_t	pid;

  if (is_builtin(tree->args[0]))
    return (check_builtins(st_shell, tree));
  if ((pid = xfork()) == 0)
    {
      xdup2(tree->fd_in, 0);
      xdup2(tree->fd_out, 1);
      xexecve(tree->full_path, tree->args, st_shell->my_env);
    }
  else if (pid > 0)
    {
      if (waitpid(pid, &statut, 0) == -1)
	perror("Waitpid() :");
      else
	return (write_statut(statut));
    }
  return (FATAL_ERROR);
}
コード例 #5
0
ファイル: parse.c プロジェクト: Laxa/minishell
void            parse(char *cmd, t_shell *shell)
{
  char          **tab;

  tab = my_str_to_wordtab(cmd);
  if (tab[0])
  {
    if (check_builtins(tab, shell));
    else if (is_dir(tab[0]))
      print_double_msg(tab[0], "Is a directory");
    else if (tab[0][0] != '/' && check_path(tab, shell));
    else if (access(tab[0], F_OK | X_OK | R_OK) == 0)
      exec(tab, NULL, NULL);
    else
    {
      if (errno == ENOENT && tab[0][0] != '/')
        print_error_double_msg(tab[0], "command not found");
      else
        print_errno(tab[0]);
    }
  }
  free_tab(tab);
}