<commit_before>package com.pty4j.unix;

import jtermios.JTermios;

/**
 * @author traff
 */
public class JnaPtyExecutor implements PtyExecutor {
  private static final int STDIN_FILENO = 0;
  private static final int STDOUT_FILENO = 1;
  private static final int STDERR_FILENO = 2;

  @Override
  public int execPty(String full_path, String[] argv, String[] envp,
                     String dirpath, int[] channels, String pts_name, int fdm, boolean console) {
    int[] pipe2 = new int[2];
    int childpid;

    PtyHelpers.OSFacade m_jpty = PtyHelpers.getInstance();
    
	/*
     *  Make sure we can create our pipes before forking.
	 */
    if (channels != null && console) {
      if (m_jpty.pipe(pipe2) < 0) {
//        fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno));
        return -1;
      }
    }

    childpid = m_jpty.fork();

    if (childpid < 0) {
//      fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno));
      return -1;
    } else if (childpid == 0) { /* child */


      PtyHelpers.chdir(dirpath);

      if (channels != null) {
        if (console && m_jpty.setsid() < 0) {
//          perror("setsid()");
          return -1;
        }

        int fds = ptySlaveOpen(fdm, pts_name);


        if (fds < 0) {
//          fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno));
          return -1;
        }

        m_jpty.login_tty(fds);

        //TODO: this hangs pty on mac
        //but we don't need it
//        if (JTermios.tcsetattr(fds, JTermios.TCSANOW, PtyHelpers.createTermios()) != 0) { 
//          throw new PtyException("tcsetattr(" + fds + ", TCSANOW, &terminalAttributes) with IXON cleared", fds);
//        }

			/* Close the read end of pipe2 */<commit_msg>set termios in JnaPtyExecutor.<commit_after>package com.pty4j.unix;

import jtermios.JTermios;

/**
 * @author traff
 */
public class JnaPtyExecutor implements PtyExecutor {
  private static final int STDIN_FILENO = 0;
  private static final int STDOUT_FILENO = 1;
  private static final int STDERR_FILENO = 2;

  @Override
  public int execPty(String full_path, String[] argv, String[] envp,
                     String dirpath, int[] channels, String pts_name, int fdm, boolean console) {
    int[] pipe2 = new int[2];
    int childpid;

    PtyHelpers.OSFacade m_jpty = PtyHelpers.getInstance();
    
	/*
     *  Make sure we can create our pipes before forking.
	 */
    if (channels != null && console) {
      if (m_jpty.pipe(pipe2) < 0) {
//        fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno));
        return -1;
      }
    }

    childpid = m_jpty.fork();

    if (childpid < 0) {
//      fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno));
      return -1;
    } else if (childpid == 0) { /* child */


      PtyHelpers.chdir(dirpath);

      if (channels != null) {
        if (console && m_jpty.setsid() < 0) {
//          perror("setsid()");
          return -1;
        }

        int fds = ptySlaveOpen(fdm, pts_name);


        if (fds < 0) {
//          fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno));
          return -1;
        }

        m_jpty.login_tty(fds);

        if (JTermios.tcsetattr(fds, JTermios.TCSANOW, PtyHelpers.createTermios()) != 0) { 
          return -1;
        }

			/* Close the read end of pipe2 */
{'fraction_non_alphanumeric': 0.13590033975084936, 'fraction_numerical': 0.010475651189127973, 'mean_word_length': 2.390595009596929, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6945453', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1201, 'n_words': 324}