<commit_before>// Copyright 2015-2017 Intecture Developers. See the COPYRIGHT file at the
// top-level directory of this distribution and at
// https://intecture.io/COPYRIGHT.
//
// Licensed under the Mozilla Public License 2.0 <LICENSE or
// https://www.tldrlegal.com/l/mpl-2.0>. This file may not be copied,
// modified, or distributed except according to those terms.

extern crate chan;
extern crate chan_signal;
extern crate czmq;
extern crate inapi;
extern crate inauth_client;
extern crate rustc_serialize;
extern crate serde;
extern crate serde_json;
#[cfg(test)]
extern crate tempdir;
extern crate zdaemon;
extern crate zfilexfer;

mod api;
mod config;
mod error;

use chan_signal::Signal;
use config::Config;
use czmq::{ZCert, ZSock, SocketType, ZSys};
use error::Result;
use inauth_client::{CertType, ZapHandler};
use std::env;
use std::process::exit;
use std::thread::spawn;
use zdaemon::{ConfigFile, Service};
use zfilexfer::Server as FileServer;

fn main() {
    let mut args = env::args();
    if args.nth(1).as_ref().map(|a| &**a) == Some("--version") {
        println!(env!("CARGO_PKG_VERSION"));
        exit(0);
    }
    else if let Err(e) = start() {
        println!("{}", e);
        exit(1);
    }
}

fn start() -> Result<()> {
    let signal = chan_signal::notify(&[Signal::INT, Signal::TERM]);
    let (parent, child) = try!(ZSys::create_pipe());

    let config = try!(Config::search("intecture/agent.json", None));
    let server_cert = try!(ZCert::load(&config.server_cert));
    let auth_cert = try!(ZCert::load(&config.auth_cert));

    let _auth = ZapHandler::new(
        Some(CertType::User),
        &server_cert,
        &auth_cert,
        &config.auth_server,
        config.auth_update_port,
        false);

    let mut file_sock = ZSock::new(SocketType::ROUTER);
    server_cert.apply(&mut file_sock);<commit_msg>Fix signal handling for some platforms like NixOS<commit_after>// Copyright 2015-2017 Intecture Developers. See the COPYRIGHT file at the
// top-level directory of this distribution and at
// https://intecture.io/COPYRIGHT.
//
// Licensed under the Mozilla Public License 2.0 <LICENSE or
// https://www.tldrlegal.com/l/mpl-2.0>. This file may not be copied,
// modified, or distributed except according to those terms.

extern crate chan;
extern crate chan_signal;
extern crate czmq;
extern crate inapi;
extern crate inauth_client;
extern crate rustc_serialize;
extern crate serde;
extern crate serde_json;
#[cfg(test)]
extern crate tempdir;
extern crate zdaemon;
extern crate zfilexfer;

mod api;
mod config;
mod error;

use chan_signal::Signal;
use config::Config;
use czmq::{ZCert, ZSock, SocketType, ZSys};
use error::Result;
use inauth_client::{CertType, ZapHandler};
use std::env;
use std::process::exit;
use std::thread::spawn;
use zdaemon::{ConfigFile, Service};
use zfilexfer::Server as FileServer;

fn main() {
    let mut args = env::args();
    if args.nth(1).as_ref().map(|a| &**a) == Some("--version") {
        println!(env!("CARGO_PKG_VERSION"));
        exit(0);
    }
    else if let Err(e) = start() {
        println!("{}", e);
        exit(1);
    }
}

fn start() -> Result<()> {
    let signal = chan_signal::notify(&[Signal::INT, Signal::TERM]);
    let (parent, child) = try!(ZSys::create_pipe());
    parent.set_linger(0);
    parent.set_sndtimeo(Some(100));

    let config = try!(Config::search("intecture/agent.json", None));
    let server_cert = try!(ZCert::load(&config.server_cert));
    let auth_cert = try!(ZCert::load(&config.auth_cert));

    let _auth = ZapHandler::new(
        Some(CertType::User),
        &server_cert,
        &auth_cert,
        &config.auth_server,
        config.auth_update_port,
        false);

    let mut file_sock = ZSock::new(SocketType::ROUTER);
    server_cert.apply(&mut file_sock);
{'fraction_non_alphanumeric': 0.14705882352941177, 'fraction_numerical': 0.008928571428571428, 'mean_word_length': 3.946753246753247, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1006873', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1247, 'n_words': 340}