Esempio n. 1
0
void	run(t_params const* params)
{
  int	fd;
  pid_t	master;
  pid_t	ptyfk;
  struct termios	term;

  fd = open(params->file, O_WRONLY | O_CREAT |
      (params->append == 1 ? O_APPEND : O_TRUNC), 0644);
  if (fd == -1)
      xperror();
  ptyfk = my_forkpty(&master, NULL);
  if (ptyfk == -1)
    xperror();
  if (ptyfk == 0)
  {
    dup2_fd(master);
    execl(params->shell, params->shell, NULL);
    exit(0);
  }
  update_win_size(master);
  signal(SIGWINCH, handle_resize);
  remove_block(master, 0);
  init_term(&term);
  printf("Script started, file is %s\n", params->file);
  read_input(ptyfk, master, fd);
  restore_term(&term);
  close(fd);
  printf("Script done, file is %s\n", params->file);
}
Esempio n. 2
0
static int child_io_setup (struct subprocess *p)
{
    /*
     *  Close parent end of stdio in child:
     */
    if (zio_close_dst_fd (p->zio_in) < 0
            || zio_close_src_fd (p->zio_out) < 0
            || zio_close_src_fd (p->zio_err) < 0)
        return (-1);

    /*
     *  Dup this process' fds onto zio
     */
    if (  (dup2_fd (zio_src_fd (p->zio_in), STDIN_FILENO) < 0)
       || (dup2_fd (zio_dst_fd (p->zio_out), STDOUT_FILENO) < 0)
       || (dup2_fd (zio_dst_fd (p->zio_err), STDERR_FILENO) < 0))
        return (-1);

    return (0);
}
Esempio n. 3
0
int
_kern_dup2(int ofd, int nfd)
{
	return dup2_fd(ofd, nfd, true);
}
Esempio n. 4
0
int
_user_dup2(int ofd, int nfd)
{
	return dup2_fd(ofd, nfd, false);
}