<commit_before>use strict;
use File::Temp qw(tempdir);

our @sshOpts = split ' ', ($ENV{"NIX_SSHOPTS"} or "");

my $sshStarted = 0;
my $sshHost;

# Open a master SSH connection to `host', unless there already is a
# running master connection (as determined by `-O check').
sub openSSHConnection {
    my ($host) = @_;
    die if $sshStarted;
    $sshHost = $host;
    return 1 if system("ssh $sshHost @sshOpts -O check 2> /dev/null") == 0;

    my $tmpDir = tempdir("nix-ssh.XXXXXX", CLEANUP => 1, TMPDIR => 1)
        or die "cannot create a temporary directory";
    
    push @sshOpts, "-S", "$tmpDir/control";
    system("ssh $sshHost @sshOpts -M -N -f") == 0
        or return 0;
    $sshStarted = 1;
    return 1;
}

# Tell the master SSH client to exit.
sub closeSSHConnection {
    if ($sshStarted) {
        system("ssh $sshHost @sshOpts -O exit 2> /dev/null") == 0
            or warn "unable to stop SSH master: $?";
    }
}

END { my $saved = $?; closeSSHConnection; $? = $saved; }

return 1;
<commit_msg>* Don't use ssh's -f flag since it leads to lots of lingering ssh   processes.<commit_after>use strict;
use File::Temp qw(tempdir);

our @sshOpts = split ' ', ($ENV{"NIX_SSHOPTS"} or "");

my $sshStarted = 0;
my $sshHost;

# Open a master SSH connection to `host', unless there already is a
# running master connection (as determined by `-O check').
sub openSSHConnection {
    my ($host) = @_;
    die if $sshStarted;
    $sshHost = $host;
    return 1 if system("ssh $sshHost @sshOpts -O check 2> /dev/null") == 0;

    my $tmpDir = tempdir("nix-ssh.XXXXXX", CLEANUP => 1, TMPDIR => 1)
        or die "cannot create a temporary directory";
    
    push @sshOpts, "-S", "$tmpDir/control";

    # Start the master.  We can't use the `-f' flag (fork into
    # background after establishing the connection) because then the
    # child continues to run if we are killed.  So instead make SSH
    # print "started" when it has established the connection, and wait
    # until we see that.
    open SSH, "ssh $sshHost @sshOpts -M -N -o LocalCommand='echo started' -o PermitLocalCommand=yes |" or die;
    while (<SSH>) {
        chomp;
        last if /started/;
    }
    
    $sshStarted = 1;
    return 1;
}

# Tell the master SSH client to exit.
sub closeSSHConnection {
    if ($sshStarted) {
        system("ssh $sshHost @sshOpts -O exit 2> /dev/null") == 0
            or warn "unable to stop SSH master: $?";
    }
}

END { my $saved = $?; closeSSHConnection; $? = $saved; }

return 1;

{'fraction_non_alphanumeric': 0.1351135910721403, 'fraction_numerical': 0.009565563969709047, 'mean_word_length': 2.8615384615384616, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, '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': '6667860', 'n_tokens_mistral': 918, 'n_tokens_neox': 847, 'n_words': 311}