コード例 #1
0
ファイル: pipe_simple.c プロジェクト: GayKevin/42sh
int		pipe_simple(t_node *tree, t_shell *sh)
{
  pid_t		pid;
  int		pipefd[2];
  int		dp;

  if (check_err_pipe(tree, sh) == -1)
    return (-1);
  if ((pipe(pipefd)) == -1)
    return (-1);
  if ((pid = fork()) == -1)
    return (-1);
  if (pid == 0)
    {
      if ((dp = dup(1)) == -1)
	return (-1);
      close(pipefd[0]);
      if ((dup2(pipefd[1], 1)) == -1)
	return (-1);
      gere_operator(tree->left, sh);
      if ((dup2(dp, 1)) == -1)
	return (-1);
      exit(1);
    }
  else
    master_pipe(pipefd, tree, sh);
  return (0);
}
コード例 #2
0
ファイル: exe.c プロジェクト: Docteur-RS/42sh
int	get_it_on(t_manage *man, t_list *list)
{
  int	ret;
  int	p[2];

  if (check_cmd_in_list(list, man) == 0)
    return (0);
  pipe(p);
  get_status(MASTER_ERROR, 'e');
  if ((ret = only_one_redirec_manage(man, list)) == MASTER_ERROR)
    return (MASTER_ERROR);
  if (ret == 1)
    return (0);
  my_static(0, 'o');
  if ((ret = master_pipe(man, list, p)) == MASTER_ERROR)
    return (MASTER_ERROR);
  my_static(0, 'o');
  get_status(0, 'e');
  return (0);
}