diff -Nru distinst-0.1.0/Cargo.lock distinst-0.2.0+1513882807+18.04~34a6ac4/Cargo.lock --- distinst-0.1.0/Cargo.lock 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/Cargo.lock 2017-12-21 19:00:07.000000000 +0000 @@ -30,11 +30,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "cfg-if" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] name = "clap" version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -50,14 +45,13 @@ [[package]] name = "distinst" -version = "0.1.0" +version = "0.2.0" dependencies = [ "clap 2.27.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "moz-cheddar 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "pbr 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syslog 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -189,17 +183,6 @@ ] [[package]] -name = "syslog" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", - "unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "tempdir" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -264,15 +247,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "unix_socket" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "vec_map" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -293,7 +267,6 @@ "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" -"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum clap 2.27.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1b8c532887f1a292d17de05ae858a8fe50a301e196f9ef0ddb7ccd0d1d00f180" "checksum fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c0581a4e363262e52b87f59ee2afe3415361c6ec35e665924eb08afe8ff159" "checksum fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43f3795b4bae048dc6123a6b972cadde2e676f9ded08aef6bb77f5f157684a82" @@ -311,7 +284,6 @@ "checksum syntex_errors 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "867cc5c2d7140ae7eaad2ae9e8bf39cb18a67ca651b7834f88d46ca98faadb9c" "checksum syntex_pos 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13ad4762fe52abc9f4008e85c4fb1b1fe3aa91ccb99ff4826a439c7c598e1047" "checksum syntex_syntax 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6e0e4dbae163dd98989464c23dd503161b338790640e11537686f2ef0f25c791" -"checksum syslog 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bbc9b0acde4f7c05fdc1cfb05239b8a53a66815dd86c67fee5aa9bfac5b4ed42" "checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6" "checksum term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" @@ -320,7 +292,6 @@ "checksum toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7540f4ffc193e0d3c94121edb19b055670d369f77d5804db11ae053a45b6e7e" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" -"checksum unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6aa2700417c405c38f5e6902d699345241c28c0b7ade4abaad71e35a87eb1564" "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff -Nru distinst-0.1.0/Cargo.toml distinst-0.2.0+1513882807+18.04~34a6ac4/Cargo.toml --- distinst-0.1.0/Cargo.toml 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/Cargo.toml 2017-12-21 19:00:07.000000000 +0000 @@ -1,7 +1,7 @@ [package] name = "distinst" description = "Distribution Installer Backend" -version = "0.1.0" +version = "0.2.0" authors = ["Jeremy Soller "] build = "build.rs" @@ -17,6 +17,5 @@ "libc" = "0.2" "log" = "0.3" "pbr" = "1.0" -"syslog" = "3.3" "tempdir" = "0.3" #TODO "libparted" = { "git" = "https://github.com/system76/libparted.git" } diff -Nru distinst-0.1.0/debian/changelog distinst-0.2.0+1513882807+18.04~34a6ac4/debian/changelog --- distinst-0.1.0/debian/changelog 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/debian/changelog 2017-12-21 19:00:07.000000000 +0000 @@ -1,6 +1,6 @@ -distinst (0.1.0-4+1513024233+18.04~d39312d) bionic; urgency=medium +distinst (0.2.0+1513882807+18.04~34a6ac4) bionic; urgency=medium * Auto Build - -- Pop OS (ISO Signing Key) Mon, 11 Dec 2017 13:30:33 -0700 + -- Pop OS (ISO Signing Key) Thu, 21 Dec 2017 12:00:07 -0700 diff -Nru distinst-0.1.0/examples/c/install.c distinst-0.2.0+1513882807+18.04~34a6ac4/examples/c/install.c --- distinst-0.1.0/examples/c/install.c 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/examples/c/install.c 2017-12-21 19:00:07.000000000 +0000 @@ -3,6 +3,23 @@ #include #include +const char * level_name (DISTINST_LOG_LEVEL level) { + switch(level) { + case DISTINST_LOG_LEVEL_TRACE: + return "Trace"; + case DISTINST_LOG_LEVEL_DEBUG: + return "Debug"; + case DISTINST_LOG_LEVEL_INFO: + return "Info"; + case DISTINST_LOG_LEVEL_WARN: + return "Warn"; + case DISTINST_LOG_LEVEL_ERROR: + return "Error"; + default: + return "Unknown"; + } +} + const char * step_name(DISTINST_STEP step) { switch(step) { case DISTINST_STEP_PARTITION: @@ -20,6 +37,10 @@ } } +void on_log(DISTINST_LOG_LEVEL level, const char * message, void * user_data) { + printf("Log: %s %s %p\n", level_name(level), message, user_data); +} + void on_error(const DistinstError * error, void * user_data) { printf("Error: %s %s %p\n", step_name(error->step), strerror(error->err), user_data); } @@ -29,6 +50,8 @@ } int main(int argc, char ** argv) { + distinst_log(on_log, (void*)0xFEEEF000); + DistinstInstaller * installer = distinst_installer_new(); distinst_installer_on_error(installer, on_error, (void*)0x12C0FFEE); distinst_installer_on_status(installer, on_status, (void *)0xDEADBEEF); diff -Nru distinst-0.1.0/examples/vala/install.vala distinst-0.2.0+1513882807+18.04~34a6ac4/examples/vala/install.vala --- distinst-0.1.0/examples/vala/install.vala 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/examples/vala/install.vala 2017-12-21 19:00:07.000000000 +0000 @@ -1,3 +1,20 @@ +public static string level_name (Distinst.LogLevel level) { + switch(level) { + case Distinst.LogLevel.TRACE: + return "Trace"; + case Distinst.LogLevel.DEBUG: + return "Debug"; + case Distinst.LogLevel.INFO: + return "Info"; + case Distinst.LogLevel.WARN: + return "Warn"; + case Distinst.LogLevel.ERROR: + return "Error"; + default: + return "Unknown"; + } +} + public static string step_name (Distinst.Step step) { switch(step) { case Distinst.Step.PARTITION: @@ -16,9 +33,14 @@ } public static int main (string[] args) { - var installer = new Distinst.Installer (); var user_data = 0x12C0FFEE; + Distinst.log((level, message) => { + warning ("Log: %s %s %X", level_name (level), message, user_data); + }); + + var installer = new Distinst.Installer (); + installer.on_error((error) => { warning ("Error: %s %s %X", step_name (error.step), strerror (error.err), user_data); }); diff -Nru distinst-0.1.0/src/c.rs distinst-0.2.0+1513882807+18.04~34a6ac4/src/c.rs --- distinst-0.1.0/src/c.rs 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/src/c.rs 2017-12-21 19:00:07.000000000 +0000 @@ -1,10 +1,24 @@ extern crate libc; -use std::ffi::CStr; +use std::ffi::{CStr, CString}; use std::io; use super::{log, Config, Error, Installer, Status, Step}; +/// Log level +#[repr(C)] +#[derive(Copy, Clone, Debug)] +pub enum DISTINST_LOG_LEVEL { + TRACE, + DEBUG, + INFO, + WARN, + ERROR, +} + +/// Installer log callback +pub type DistinstLogCallback = extern "C" fn(level: DISTINST_LOG_LEVEL, message: *const libc::c_char, user_data: * mut libc::c_void); + /// Bootloader steps #[repr(C)] #[derive(Copy, Clone, Debug)] @@ -100,14 +114,22 @@ /// Initialize logging #[no_mangle] -pub unsafe extern fn distinst_log(name: *const libc::c_char) -> libc::c_int { - let name_cstr = CStr::from_ptr(name); - let name_str = match name_cstr.to_str() { - Ok(name_str) => name_str, - Err(_err) => return libc::EINVAL - }; - - match log(name_str) { +pub unsafe extern fn distinst_log(callback: DistinstLogCallback, user_data: * mut libc::c_void) -> libc::c_int { + use DISTINST_LOG_LEVEL::*; + use log::LogLevel; + + let user_data_sync = user_data as usize; + match log(move |level, message| { + let c_level = match level { + LogLevel::Trace => TRACE, + LogLevel::Debug => DEBUG, + LogLevel::Info => INFO, + LogLevel::Warn => WARN, + LogLevel::Error => ERROR, + }; + let c_message = CString::new(message).unwrap(); + callback(c_level, c_message.as_ptr(), user_data_sync as * mut libc::c_void); + }) { Ok(()) => 0, Err(_err) => libc::EINVAL } diff -Nru distinst-0.1.0/src/distinst.vapi distinst-0.2.0+1513882807+18.04~34a6ac4/src/distinst.vapi --- distinst-0.1.0/src/distinst.vapi 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/src/distinst.vapi 2017-12-21 19:00:07.000000000 +0000 @@ -1,6 +1,17 @@ [CCode (cprefix = "Distinst", lower_case_cprefix = "distinst_", cheader_filename = "distinst.h")] namespace Distinst { + [CCode (cname = "DISTINST_LOG_LEVEL", has_type_id = false)] + public enum LogLevel { + TRACE, + DEBUG, + INFO, + WARN, + ERROR + } + + public delegate void LogCallback (Distinst.LogLevel level, string message); + [CCode (cname = "DISTINST_STEP", has_type_id = false)] public enum Step { INIT, @@ -33,7 +44,7 @@ public delegate void StatusCallback (Distinst.Status status); - int log (string name); + int log (Distinst.LogCallback callback); [Compact] [CCode (free_function = "distinst_installer_destroy", has_type_id = false)] diff -Nru distinst-0.1.0/src/lib.rs distinst-0.2.0+1513882807+18.04~34a6ac4/src/lib.rs --- distinst-0.1.0/src/lib.rs 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/src/lib.rs 2017-12-21 19:00:07.000000000 +0000 @@ -2,7 +2,6 @@ #[macro_use] extern crate log; -extern crate syslog; extern crate tempdir; use tempdir::TempDir; @@ -25,17 +24,17 @@ mod chroot; mod disk; mod format; +mod logger; mod mount; mod partition; mod squashfs; /// Initialize logging -pub fn log(name: &str) -> Result<(), syslog::SyslogError> { - match syslog::init( - syslog::Facility::LOG_SYSLOG, - log::LogLevelFilter::Debug, - Some(name) - ) { +pub fn log(callback: F) -> Result<(), log::SetLoggerError> { + match log::set_logger(|max_log_level| { + max_log_level.set(log::LogLevelFilter::Debug); + Box::new(logger::Logger::new(callback)) + }) { Ok(()) => { info!("Logging enabled"); Ok(()) diff -Nru distinst-0.1.0/src/logger.rs distinst-0.2.0+1513882807+18.04~34a6ac4/src/logger.rs --- distinst-0.1.0/src/logger.rs 1970-01-01 00:00:00.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/src/logger.rs 2017-12-21 19:00:07.000000000 +0000 @@ -0,0 +1,25 @@ +use log::{Log, LogLevel, LogRecord, LogMetadata}; + +pub struct Logger { + callback: F +} + +impl Logger { + pub fn new(callback: F) -> Logger { + Logger { + callback: callback + } + } +} + +impl Log for Logger { + fn enabled(&self, _metadata: &LogMetadata) -> bool { + true + } + + fn log(&self, record: &LogRecord) { + if self.enabled(record.metadata()) { + (self.callback)(record.level(), &format!("{}", record.args())); + } + } +} diff -Nru distinst-0.1.0/src/main.rs distinst-0.2.0+1513882807+18.04~34a6ac4/src/main.rs --- distinst-0.1.0/src/main.rs 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/src/main.rs 2017-12-21 19:00:07.000000000 +0000 @@ -22,7 +22,9 @@ ) .get_matches(); - if let Err(err) = distinst::log("distinst") { + if let Err(err) = distinst::log(|_level, message| { + println!("{}", message); + }) { println!("Failed to initialize logging: {}", err); } diff -Nru distinst-0.1.0/vendor/cfg-if/.cargo-checksum.json distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/.cargo-checksum.json --- distinst-0.1.0/vendor/cfg-if/.cargo-checksum.json 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/.cargo-checksum.json 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -{"files":{".travis.yml":"50f67b20a376d437e0706d9bbb0343c677295529991370b2962f814c0b2efea3","Cargo.toml":"764b9ce160653e841430da3919ff968b957ff811f7da42c8483c8bfc2f06be25","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"3fa9368c60bc701dea294fbacae0469188c4be1de79f82e972bb9b321776cd52","src/lib.rs":"6915169e3ca05f28e1cb0e052379d74f2496400de1240b74c56e55c2674a6560","tests/xcrate.rs":"30dcb70fbb9c96fda2b7825592558279f534776f72e2a8a0a3e26df4dedb3caa"},"package":"d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"} \ No newline at end of file diff -Nru distinst-0.1.0/vendor/cfg-if/Cargo.toml distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/Cargo.toml --- distinst-0.1.0/vendor/cfg-if/Cargo.toml 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/Cargo.toml 1970-01-01 00:00:00.000000000 +0000 @@ -1,14 +0,0 @@ -[package] -name = "cfg-if" -version = "0.1.2" -authors = ["Alex Crichton "] -license = "MIT/Apache-2.0" -readme = "README.md" -repository = "https://github.com/alexcrichton/cfg-if" -homepage = "https://github.com/alexcrichton/cfg-if" -documentation = "http://alexcrichton.com/cfg-if" -description = """ -A macro to ergonomically define an item depending on a large number of #[cfg] -parameters. Structured like an if-else chain, the first matching branch is the -item that gets emitted. -""" diff -Nru distinst-0.1.0/vendor/cfg-if/LICENSE-APACHE distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/LICENSE-APACHE --- distinst-0.1.0/vendor/cfg-if/LICENSE-APACHE 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/LICENSE-APACHE 1970-01-01 00:00:00.000000000 +0000 @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff -Nru distinst-0.1.0/vendor/cfg-if/LICENSE-MIT distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/LICENSE-MIT --- distinst-0.1.0/vendor/cfg-if/LICENSE-MIT 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/LICENSE-MIT 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ -Copyright (c) 2014 Alex Crichton - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff -Nru distinst-0.1.0/vendor/cfg-if/README.md distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/README.md --- distinst-0.1.0/vendor/cfg-if/README.md 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/README.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ -# cfg-if - -[![Build Status](https://travis-ci.org/alexcrichton/cfg-if.svg?branch=master)](https://travis-ci.org/alexcrichton/cfg-if) - -[Documentation](http://alexcrichton.com/cfg-if) - -A macro to ergonomically define an item depending on a large number of #[cfg] -parameters. Structured like an if-else chain, the first matching branch is the -item that gets emitted. - -```toml -[dependencies] -cfg-if = "0.1" -``` - -## Example - -```rust -#[macro_use] -extern crate cfg_if; - -cfg_if! { - if #[cfg(unix)] { - fn foo() { /* unix specific functionality */ } - } else if #[cfg(target_pointer_width = "32")] { - fn foo() { /* non-unix, 32-bit functionality */ } - } else { - fn foo() { /* fallback implementation */ } - } -} - -fn main() { - foo(); -} -``` - -# License - -`cfg-if` is primarily distributed under the terms of both the MIT license and -the Apache License (Version 2.0), with portions covered by various BSD-like -licenses. - -See LICENSE-APACHE, and LICENSE-MIT for details. - diff -Nru distinst-0.1.0/vendor/cfg-if/src/lib.rs distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/src/lib.rs --- distinst-0.1.0/vendor/cfg-if/src/lib.rs 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/src/lib.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,133 +0,0 @@ -//! A macro for defining #[cfg] if-else statements. -//! -//! The macro provided by this crate, `cfg_if`, is similar to the `if/elif` C -//! preprocessor macro by allowing definition of a cascade of `#[cfg]` cases, -//! emitting the implementation which matches first. -//! -//! This allows you to conveniently provide a long list #[cfg]'d blocks of code -//! without having to rewrite each clause multiple times. -//! -//! # Example -//! -//! ``` -//! #[macro_use] -//! extern crate cfg_if; -//! -//! cfg_if! { -//! if #[cfg(unix)] { -//! fn foo() { /* unix specific functionality */ } -//! } else if #[cfg(target_pointer_width = "32")] { -//! fn foo() { /* non-unix, 32-bit functionality */ } -//! } else { -//! fn foo() { /* fallback implementation */ } -//! } -//! } -//! -//! # fn main() {} -//! ``` - -#![no_std] - -#![doc(html_root_url = "http://alexcrichton.com/cfg-if")] -#![deny(missing_docs)] -#![cfg_attr(test, deny(warnings))] - -#[macro_export] -macro_rules! cfg_if { - ($( - if #[cfg($($meta:meta),*)] { $($it:item)* } - ) else * else { - $($it2:item)* - }) => { - __cfg_if_items! { - () ; - $( ( ($($meta),*) ($($it)*) ), )* - ( () ($($it2)*) ), - } - }; - ( - if #[cfg($($i_met:meta),*)] { $($i_it:item)* } - $( - else if #[cfg($($e_met:meta),*)] { $($e_it:item)* } - )* - ) => { - __cfg_if_items! { - () ; - ( ($($i_met),*) ($($i_it)*) ), - $( ( ($($e_met),*) ($($e_it)*) ), )* - ( () () ), - } - } -} - -#[macro_export] -#[doc(hidden)] -macro_rules! __cfg_if_items { - (($($not:meta,)*) ; ) => {}; - (($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ), $($rest:tt)*) => { - __cfg_if_apply! { cfg(all($($m,)* not(any($($not),*)))), $($it)* } - __cfg_if_items! { ($($not,)* $($m,)*) ; $($rest)* } - } -} - -#[macro_export] -#[doc(hidden)] -macro_rules! __cfg_if_apply { - ($m:meta, $($it:item)*) => { - $(#[$m] $it)* - } -} - -#[cfg(test)] -mod tests { - cfg_if! { - if #[cfg(test)] { - use core::option::Option as Option2; - fn works1() -> Option2 { Some(1) } - } else { - fn works1() -> Option { None } - } - } - - cfg_if! { - if #[cfg(foo)] { - fn works2() -> bool { false } - } else if #[cfg(test)] { - fn works2() -> bool { true } - } else { - fn works2() -> bool { false } - } - } - - cfg_if! { - if #[cfg(foo)] { - fn works3() -> bool { false } - } else { - fn works3() -> bool { true } - } - } - - cfg_if! { - if #[cfg(test)] { - use core::option::Option as Option3; - fn works4() -> Option3 { Some(1) } - } - } - - cfg_if! { - if #[cfg(foo)] { - fn works5() -> bool { false } - } else if #[cfg(test)] { - fn works5() -> bool { true } - } - } - - #[test] - fn it_works() { - assert!(works1().is_some()); - assert!(works2()); - assert!(works3()); - assert!(works4().is_some()); - assert!(works5()); - } -} diff -Nru distinst-0.1.0/vendor/cfg-if/tests/xcrate.rs distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/tests/xcrate.rs --- distinst-0.1.0/vendor/cfg-if/tests/xcrate.rs 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/tests/xcrate.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,17 +0,0 @@ -#[macro_use] -extern crate cfg_if; - -cfg_if! { - if #[cfg(foo)] { - fn works() -> bool { false } - } else if #[cfg(test)] { - fn works() -> bool { true } - } else { - fn works() -> bool { false } - } -} - -#[test] -fn smoke() { - assert!(works()); -} diff -Nru distinst-0.1.0/vendor/cfg-if/.travis.yml distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/.travis.yml --- distinst-0.1.0/vendor/cfg-if/.travis.yml 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/cfg-if/.travis.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -language: rust -rust: - - stable - - beta - - nightly -sudo: false -before_script: - - pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH -script: - - cargo build --verbose - - cargo test --verbose - - rustdoc --test README.md -L target/debug -L target/debug/deps - - cargo doc --no-deps -after_success: - - travis-cargo --only nightly doc-upload -env: - global: - secure: "TyMGH+sbPmKs9lKCziKShxWr3G6im0owEchVrbUChWnQIQv1WydXftFoEoUsVl6qZspjehWK1b1AsnIgCXK0HtEi4DnqLsxs0s36bOjfg5yHBT/pETTr6kcq7KAL4Be4GmI331k6gT1Oi0TPFp7Sg9xpiWsQqKIHA5Szk2wpFQ8=" - - -notifications: - email: - on_success: never diff -Nru distinst-0.1.0/vendor/syslog/.cargo-checksum.json distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/.cargo-checksum.json --- distinst-0.1.0/vendor/syslog/.cargo-checksum.json 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/.cargo-checksum.json 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -{"files":{".travis.yml":"61c9ace2b33a1185c4d743fb7a53e5d0e9244fd925f68cfaa6a7c0d8215177c4","Cargo.toml":"145676d5dd632ee27918160db335d61d7c0ab9cdccea2b3edcac3fc97b3bc873","Makefile":"73be69d4f2a7bc7f7610c8c409fa9cc89be539278dfa57f881223a7d87e976c3","README.md":"6c8eb62c9a4f9dc9d2081a6d2a52d1ecc83b9ad38073a022e9c620a645f57eef","cargo-lite.conf":"6d8f9591aa1618394b08d776464e72ddcec33299ca53aa5e1d293d8abda329a5","examples/write.rs":"76621eaf5dac578eee32a028fb42a4d64fd4e91f82d8cfed5722bdaa5f9c0c4c","src/facility.rs":"d01d730d3e4c8b20199071f4211cd4823d885dd8f52fe4d1997a4380b3c0d722","src/lib.rs":"40221dc9b25978426a0e0a4666cdca978de0fa60b3eedb173909578d819611bd"},"package":"bbc9b0acde4f7c05fdc1cfb05239b8a53a66815dd86c67fee5aa9bfac5b4ed42"} \ No newline at end of file diff -Nru distinst-0.1.0/vendor/syslog/cargo-lite.conf distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/cargo-lite.conf --- distinst-0.1.0/vendor/syslog/cargo-lite.conf 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/cargo-lite.conf 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -[build] -crate_root = "src/syslog/lib.rs" -crate_type = "library" - diff -Nru distinst-0.1.0/vendor/syslog/Cargo.toml distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/Cargo.toml --- distinst-0.1.0/vendor/syslog/Cargo.toml 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/Cargo.toml 1970-01-01 00:00:00.000000000 +0000 @@ -1,35 +0,0 @@ -# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO -# -# When uploading crates to the registry Cargo will automatically -# "normalize" Cargo.toml files for maximal compatibility -# with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g. crates.io) dependencies -# -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) - -[package] -name = "syslog" -version = "3.3.0" -authors = ["contact@geoffroycouprie.com"] -description = "Send log messages to syslog" -documentation = "http://rust.unhandledexpression.com/syslog/" -keywords = ["syslog", "logs", "logging"] -license = "MIT" -repository = "https://github.com/Geal/rust-syslog" -[dependencies.libc] -version = "~0.2" - -[dependencies.log] -version = "~0.3.5" - -[dependencies.unix_socket] -version = "~0.5" - -[dependencies.time] -version = "~0.1" - -[features] -nightly = [] diff -Nru distinst-0.1.0/vendor/syslog/examples/write.rs distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/examples/write.rs --- distinst-0.1.0/vendor/syslog/examples/write.rs 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/examples/write.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,15 +0,0 @@ -extern crate syslog; - -use syslog::{Facility,Severity}; - -fn main() { - match syslog::unix(Facility::LOG_USER) { - Err(e) => println!("impossible to connect to syslog: {:?}", e), - Ok(writer) => { - let r = writer.send(Severity::LOG_ALERT, "hello world"); - if r.is_err() { - println!("error sending the log {}", r.err().expect("got error")); - } - } - } -} diff -Nru distinst-0.1.0/vendor/syslog/Makefile distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/Makefile --- distinst-0.1.0/vendor/syslog/Makefile 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/Makefile 1970-01-01 00:00:00.000000000 +0000 @@ -1,14 +0,0 @@ -build: - mkdir -p build - rustc --out-dir build -O src/syslog/lib.rs - -test: build - rustc -L build -o build/test --test src/syslog/test.rs - ./build/test - -examples: build - rustc -L build -o build/example examples/write.rs - ./build/example - -clean: - rm -rf build diff -Nru distinst-0.1.0/vendor/syslog/README.md distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/README.md --- distinst-0.1.0/vendor/syslog/README.md 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/README.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -# Sending to Syslog in Rust - -[![Build Status](https://travis-ci.org/Geal/rust-syslog.png?branch=master)](https://travis-ci.org/Geal/rust-syslog) -[![Coverage Status](https://coveralls.io/repos/Geal/rust-syslog/badge.svg?branch=master&service=github)](https://coveralls.io/github/Geal/rust-syslog?branch=master) - -A small library to write to local syslog. - -## Installation - -syslog is available on [crates.io](https://crates.io/crates/syslog) and can be included in your Cargo enabled project like this: - -```toml -[dependencies] -syslog = "~3.3.0" -``` - -## documentation - -Reference documentation is available [here](http://rust.unhandledexpression.com/syslog/). - -## Example - -```rust -extern crate syslog; - -use syslog::{Facility,Severity}; - -fn main() { - match syslog::unix(Facility::LOG_USER) { - Err(e) => println!("impossible to connect to syslog: {:?}", e), - Ok(writer) => { - let r = writer.send_3164(Severity::LOG_ALERT, "hello world"); - if r.is_err() { - println!("error sending the log {}", r.err().expect("got error")); - } - } - } -} -``` - -The struct `syslog::Logger` implements `Log` from the `log` crate, so it can be used as backend for other logging systems. - -There are 3 functions to create loggers: - -* the `unix` function sends to the local syslog through a Unix socket: `syslog::unix(Facility::LOG_USER)` -* the `tcp` function takes an address for a remote TCP syslog server and a hostname: `tcp("127.0.0.1:4242", "localhost".to_string(), Facility::LOG_USER)` -* the `udp` function takes an address for a local port, and the address remote UDP syslog server and a hostname: `udp("127.0.0.1:1234", "127.0.0.1:4242", "localhost".to_string(), Facility::LOG_USER)` diff -Nru distinst-0.1.0/vendor/syslog/src/facility.rs distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/src/facility.rs --- distinst-0.1.0/vendor/syslog/src/facility.rs 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/src/facility.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,56 +0,0 @@ -use std::str::FromStr; - -#[allow(non_camel_case_types)] -#[derive(Copy,Clone)] -pub enum Facility { - LOG_KERN = 0 << 3, - LOG_USER = 1 << 3, - LOG_MAIL = 2 << 3, - LOG_DAEMON = 3 << 3, - LOG_AUTH = 4 << 3, - LOG_SYSLOG = 5 << 3, - LOG_LPR = 6 << 3, - LOG_NEWS = 7 << 3, - LOG_UUCP = 8 << 3, - LOG_CRON = 9 << 3, - LOG_AUTHPRIV = 10 << 3, - LOG_FTP = 11 << 3, - LOG_LOCAL0 = 16 << 3, - LOG_LOCAL1 = 17 << 3, - LOG_LOCAL2 = 18 << 3, - LOG_LOCAL3 = 19 << 3, - LOG_LOCAL4 = 20 << 3, - LOG_LOCAL5 = 21 << 3, - LOG_LOCAL6 = 22 << 3, - LOG_LOCAL7 = 23 << 3 -} - -impl FromStr for Facility { - type Err = (); - fn from_str(s: &str) -> Result { - let result = match &s.to_lowercase()[..] { - "log_kern" | "kern" => Facility::LOG_KERN, - "log_user" | "user" => Facility::LOG_USER, - "log_mail" | "mail" => Facility::LOG_MAIL, - "log_daemon" | "daemon" => Facility::LOG_DAEMON, - "log_auth" | "auth" => Facility::LOG_AUTH, - "log_syslog" | "syslog" => Facility::LOG_SYSLOG, - "log_lpr" | "lpr" => Facility::LOG_LPR, - "log_news" | "news" => Facility::LOG_NEWS, - "log_uucp" | "uucp" => Facility::LOG_UUCP, - "log_cron" | "cron" => Facility::LOG_CRON, - "log_authpriv"| "authpriv" => Facility::LOG_AUTHPRIV, - "log_ftp" | "ftp" => Facility::LOG_FTP, - "log_local0" | "local0" => Facility::LOG_LOCAL0, - "log_local1" | "local1" => Facility::LOG_LOCAL1, - "log_local2" | "local2" => Facility::LOG_LOCAL2, - "log_local3" | "local3" => Facility::LOG_LOCAL3, - "log_local4" | "local4" => Facility::LOG_LOCAL4, - "log_local5" | "local5" => Facility::LOG_LOCAL5, - "log_local6" | "local6" => Facility::LOG_LOCAL6, - "log_local7" | "local7" => Facility::LOG_LOCAL7, - _ => return Err(()) - }; - Ok(result) - } -} diff -Nru distinst-0.1.0/vendor/syslog/src/lib.rs distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/src/lib.rs --- distinst-0.1.0/vendor/syslog/src/lib.rs 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/src/lib.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,459 +0,0 @@ -//! Syslog -//! -//! This crate provides facilities to send log messages via syslog. -//! It supports Unix sockets for local syslog, UDP and TCP for remote servers. -//! -//! Messages can be passed directly without modification, or in RFC 3164 or RFC 5424 format -//! -//! The code is available on [Github](https://github.com/Geal/rust-syslog) -//! -//! # Example -//! -//! ``` -//! extern crate syslog; -//! -//! use syslog::{Facility,Severity}; -//! -//! fn main() { -//! match syslog::unix(Facility::LOG_USER) { -//! Err(e) => println!("impossible to connect to syslog: {:?}", e), -//! Ok(writer) => { -//! let r = writer.send(Severity::LOG_ALERT, "hello world"); -//! if r.is_err() { -//! println!("error sending the log {}", r.err().expect("got error")); -//! } -//! } -//! } -//! } -//! ``` -#![crate_type = "lib"] - -extern crate unix_socket; -extern crate libc; -extern crate time; -extern crate log; - -use std::result::Result; -use std::io::{self, Write}; -use std::env; -use std::collections::HashMap; -use std::net::{SocketAddr,ToSocketAddrs,UdpSocket,TcpStream}; -use std::sync::{Arc, Mutex}; -use std::path::Path; -use std::fmt; -use std::error::Error; - -use libc::getpid; -use unix_socket::{UnixDatagram, UnixStream}; -use log::{Log,LogRecord,LogMetadata,LogLevel,SetLoggerError}; - -mod facility; -pub use facility::Facility; - -pub type Priority = u8; - -/// RFC 5424 structured data -pub type StructuredData = HashMap>; - - -#[allow(non_camel_case_types)] -#[derive(Copy,Clone)] -pub enum Severity { - LOG_EMERG, - LOG_ALERT, - LOG_CRIT, - LOG_ERR, - LOG_WARNING, - LOG_NOTICE, - LOG_INFO, - LOG_DEBUG -} - -enum LoggerBackend { - /// Unix socket, temp file path, log file path - Unix(UnixDatagram), - UnixStream(Arc>), - Udp(Box, SocketAddr), - Tcp(Arc>) -} - -#[derive(Debug)] -pub struct SyslogError { - description: String, -} - -impl Error for SyslogError { - fn description(&self) -> &str { - &self.description - } - - fn cause(&self) -> Option<&Error> { None } -} - -impl fmt::Display for SyslogError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.description) - } -} - -/// Main logging structure -pub struct Logger { - facility: Facility, - hostname: Option, - process: String, - pid: i32, - s: LoggerBackend -} - -/// Returns a Logger using unix socket to target local syslog ( using /dev/log or /var/run/syslog) -pub fn unix(facility: Facility) -> Result, io::Error> { - unix_custom(facility, "/dev/log").or_else(|e| if e.kind() == io::ErrorKind::NotFound { - unix_custom(facility, "/var/run/syslog") - } else { - Err(e) - }) -} - -/// Returns a Logger using unix socket to target local syslog at user provided path -pub fn unix_custom>(facility: Facility, path: P) -> Result, io::Error> { - let (process_name, pid) = get_process_info().unwrap(); - let sock = try!(UnixDatagram::unbound()); - match sock.connect(&path) { - Ok(()) => { - Ok(Box::new(Logger { - facility: facility.clone(), - hostname: None, - process: process_name, - pid: pid, - s: LoggerBackend::Unix(sock), - })) - }, - Err(ref e) if e.raw_os_error() == Some(libc::EPROTOTYPE) => { - let sock = try!(UnixStream::connect(path)); - Ok(Box::new(Logger { - facility: facility.clone(), - hostname: None, - process: process_name, - pid: pid, - s: LoggerBackend::UnixStream(Arc::new(Mutex::new(sock))), - })) - }, - Err(e) => Err(e), - } -} - -/// returns a UDP logger connecting `local` and `server` -pub fn udp(local: T, server: T, hostname:String, facility: Facility) -> Result, io::Error> { - server.to_socket_addrs().and_then(|mut server_addr_opt| { - server_addr_opt.next().ok_or( - io::Error::new( - io::ErrorKind::InvalidInput, - "invalid server address" - ) - ) - }).and_then(|server_addr| { - UdpSocket::bind(local).map(|socket| { - let (process_name, pid) = get_process_info().unwrap(); - Box::new(Logger { - facility: facility.clone(), - hostname: Some(hostname), - process: process_name, - pid: pid, - s: LoggerBackend::Udp(Box::new(socket), server_addr) - }) - }) - }) -} - -/// returns a TCP logger connecting `local` and `server` -pub fn tcp(server: T, hostname: String, facility: Facility) -> Result, io::Error> { - TcpStream::connect(server).map(|socket| { - let (process_name, pid) = get_process_info().unwrap(); - Box::new(Logger { - facility: facility.clone(), - hostname: Some(hostname), - process: process_name, - pid: pid, - s: LoggerBackend::Tcp(Arc::new(Mutex::new(socket))) - }) - }) -} - -/// Unix socket Logger init function compatible with log crate -pub fn init_unix(facility: Facility, log_level: log::LogLevelFilter) -> Result<(), SetLoggerError> { - log::set_logger(|max_level| { - max_level.set(log_level); - unix(facility).unwrap() - }) -} - -/// Unix socket Logger init function compatible with log crate and user provided socket path -pub fn init_unix_custom>(facility: Facility, log_level: log::LogLevelFilter, path: P) -> Result<(), SetLoggerError> { - log::set_logger(|max_level| { - max_level.set(log_level); - unix_custom(facility, path).unwrap() - }) -} - -/// UDP Logger init function compatible with log crate -pub fn init_udp(local: T, server: T, hostname:String, facility: Facility, log_level: log::LogLevelFilter) -> Result<(), SetLoggerError> { - log::set_logger(|max_level| { - max_level.set(log_level); - udp(local, server, hostname, facility).unwrap() - }) -} - -/// TCP Logger init function compatible with log crate -pub fn init_tcp(server: T, hostname: String, facility: Facility, log_level: log::LogLevelFilter) -> Result<(), SetLoggerError> { - log::set_logger(|max_level| { - max_level.set(log_level); - tcp(server, hostname, facility).unwrap() - }) -} - -/// Initializes logging subsystem for log crate -/// -/// This tries to connect to syslog by following ways: -/// -/// 1. Unix sockets /dev/log and /var/run/syslog (in this order) -/// 2. Tcp connection to 127.0.0.1:601 -/// 3. Udp connection to 127.0.0.1:514 -/// -/// Note the last option usually (almost) never fails in this method. So -/// this method doesn't return error even if there is no syslog. -/// -/// If `application_name` is `None` name is derived from executable name -pub fn init(facility: Facility, log_level: log::LogLevelFilter, - application_name: Option<&str>) - -> Result<(), SyslogError> -{ - let backend = unix(facility).map(|logger| logger.s) - .or_else(|_| { - TcpStream::connect(("127.0.0.1", 601)) - .map(|s| LoggerBackend::Tcp(Arc::new(Mutex::new(s)))) - }) - .or_else(|_| { - let udp_addr = "127.0.0.1:514".parse().unwrap(); - UdpSocket::bind(("127.0.0.1", 0)) - .map(|s| LoggerBackend::Udp(Box::new(s), udp_addr)) - }).map_err(|e| SyslogError{ description: e.description().to_owned() })?; - let (process_name, pid) = get_process_info().unwrap(); - log::set_logger(|max_level| { - max_level.set(log_level); - Box::new(Logger { - facility: facility.clone(), - hostname: None, - process: application_name - .map(|v| v.to_string()) - .unwrap_or(process_name), - pid: pid, - s: backend, - }) - }).map_err(|e| SyslogError{ description: e.description().to_owned() }) -} - -impl Logger { - /// format a message as a RFC 3164 log message - pub fn format_3164(&self, severity:Severity, message: T) -> String { - if let Some(ref hostname) = self.hostname { - format!("<{}>{} {} {}[{}]: {}", - self.encode_priority(severity, self.facility), - time::now().strftime("%b %d %T").unwrap(), - hostname, self.process, self.pid, message) - } else { - format!("<{}>{} {}[{}]: {}", - self.encode_priority(severity, self.facility), - time::now().strftime("%b %d %T").unwrap(), - self.process, self.pid, message) - } - } - - /// format RFC 5424 structured data as `([id (name="value")*])*` - pub fn format_5424_structured_data(&self, data: StructuredData) -> String { - if data.is_empty() { - "-".to_string() - } else { - let mut res = String::new(); - for (id, params) in data.iter() { - res = res + "["+id; - for (name,value) in params.iter() { - res = res + " " + name + "=\"" + value + "\""; - } - res = res + "]"; - } - - res - } - } - - /// format a message as a RFC 5424 log message - pub fn format_5424(&self, severity:Severity, message_id: i32, data: StructuredData, message: T) -> String { - let f = format!("<{}> {} {} {} {} {} {} {} {}", - self.encode_priority(severity, self.facility), - 1, // version - time::now_utc().rfc3339(), - self.hostname.as_ref().map(|x| &x[..]).unwrap_or("localhost"), - self.process, self.pid, message_id, - self.format_5424_structured_data(data), message); - return f; - } - - fn encode_priority(&self, severity: Severity, facility: Facility) -> Priority { - return facility as u8 | severity as u8 - } - - /// Sends a basic log message of the format ` message` - pub fn send(&self, severity: Severity, message: T) -> Result { - let formatted = format!("<{}> {}", - self.encode_priority(severity, self.facility.clone()), - message).into_bytes(); - self.send_raw(&formatted[..]) - } - - /// Sends a RFC 3164 log message - pub fn send_3164(&self, severity: Severity, message: T) -> Result { - let formatted = self.format_3164(severity, message).into_bytes(); - self.send_raw(&formatted[..]) - } - - /// Sends a RFC 5424 log message - pub fn send_5424(&self, severity: Severity, message_id: i32, data: StructuredData, message: T) -> Result { - let formatted = self.format_5424(severity, message_id, data, message).into_bytes(); - self.send_raw(&formatted[..]) - } - - /// Sends a message directly, without any formatting - pub fn send_raw(&self, message: &[u8]) -> Result { - match self.s { - LoggerBackend::Unix(ref dgram) => dgram.send(&message[..]), - LoggerBackend::UnixStream(ref socket_wrap) => { - let mut socket = socket_wrap.lock().unwrap(); - let null = [0 ; 1]; - socket.write(&message[..]).and_then(|_| socket.write(&null)) - }, - LoggerBackend::Udp(ref socket, ref addr) => socket.send_to(&message[..], addr), - LoggerBackend::Tcp(ref socket_wrap) => { - let mut socket = socket_wrap.lock().unwrap(); - socket.write(&message[..]) - } - } - } - - pub fn emerg(&self, message: T) -> Result { - self.send_3164(Severity::LOG_EMERG, message) - } - - pub fn alert(&self, message: T) -> Result { - self.send_3164(Severity::LOG_ALERT, message) - } - - pub fn crit(&self, message: T) -> Result { - self.send_3164(Severity::LOG_CRIT, message) - } - - pub fn err(&self, message: T) -> Result { - self.send_3164(Severity::LOG_ERR, message) - } - - pub fn warning(&self, message: T) -> Result { - self.send_3164(Severity::LOG_WARNING, message) - } - - pub fn notice(&self, message: T) -> Result { - self.send_3164(Severity::LOG_NOTICE, message) - } - - pub fn info(&self, message: T) -> Result { - self.send_3164(Severity::LOG_INFO, message) - } - - pub fn debug(&self, message: T) -> Result { - self.send_3164(Severity::LOG_DEBUG, message) - } - - pub fn process_name(&self) -> &String { - &self.process - } - - pub fn process_id(&self) -> i32 { - self.pid - } - - pub fn set_process_name(&mut self, name: String) { - self.process = name - } - - pub fn set_process_id(&mut self, id: i32) { - self.pid = id - } - - /// Changes facility - pub fn set_facility(&mut self, facility: Facility) { - self.facility = facility; - } -} - -#[allow(unused_variables,unused_must_use)] -impl Log for Logger { - fn enabled(&self, metadata: &LogMetadata) -> bool { - true - } - - fn log(&self, record: &LogRecord) { - let message = &(format!("{}", record.args())); - match record.level() { - LogLevel::Error => self.err(message), - LogLevel::Warn => self.warning(message), - LogLevel::Info => self.info(message), - LogLevel::Debug => self.debug(message), - LogLevel::Trace => self.debug(message) - }; - } -} - -fn get_process_info() -> Option<(String,i32)> { - env::current_exe().ok().and_then(|path| { - path.file_name().and_then(|os_name| os_name.to_str()).map(|name| name.to_string()) - }).map(|name| { - let pid = unsafe { getpid() }; - (name, pid) - }) -} - -#[test] -#[allow(unused_must_use)] -fn message() { - use std::thread; - use std::sync::mpsc::channel; - - let r = unix(Facility::LOG_USER); - //let r = tcp("127.0.0.1:4242", "localhost".to_string(), Facility::LOG_USER); - if r.is_ok() { - let w = r.unwrap(); - let m:String = w.format_3164(Severity::LOG_ALERT, "hello"); - println!("test: {}", m); - let r = w.send_3164(Severity::LOG_ALERT, "pouet"); - if r.is_err() { - println!("error sending: {}", r.unwrap_err()); - } - //assert_eq!(m, "<9> test hello".to_string()); - - let data = Arc::new(w); - let (tx, rx) = channel(); - for i in 0..3 { - let shared = data.clone(); - let tx = tx.clone(); - thread::spawn(move || { - //let mut logger = *shared; - let message = &format!("sent from {}", i); - shared.send_3164(Severity::LOG_DEBUG, message); - tx.send(()); - }); - } - - for _ in 0..3 { - rx.recv(); - } - } -} - diff -Nru distinst-0.1.0/vendor/syslog/.travis.yml distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/.travis.yml --- distinst-0.1.0/vendor/syslog/.travis.yml 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/syslog/.travis.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,42 +0,0 @@ -language: rust - -addons: - apt: - packages: - - libcurl4-openssl-dev - - libelf-dev - - libdw-dev - -rust: - - nightly - - beta - - stable - -before_script: - - pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH - -script: - - | - travis-cargo build && - travis-cargo test && - travis-cargo bench - travis-cargo --only stable doc - -after_success: - - travis-cargo coveralls --no-sudo - -notifications: - webhooks: - urls: - - https://webhooks.gitter.im/e/9c035a194ac4fd4cc061 - on_success: change - on_failure: always - on_start: false - - -env: - global: - # override the default `--features unstable` used for the nightly branch (optional) - - TRAVIS_CARGO_NIGHTLY_FEATURE=nightly - -sudo: false diff -Nru distinst-0.1.0/vendor/unix_socket/.cargo-checksum.json distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/.cargo-checksum.json --- distinst-0.1.0/vendor/unix_socket/.cargo-checksum.json 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/.cargo-checksum.json 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -{"files":{".travis.yml":"e6fd9818745bd70a6636ef51f6fa0fa8a35b1c3a3ebc47aa2fdd2f9300eb8169","Cargo.toml":"4797f544ab47bb0d0095100547b81f931c9f3802c4770924c7207b23840864cc","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"9a6e9bd4ddad6dd80f8d6304cd071182dc3e9a31e4b4a2ec0d91a791f36b4fab","README.md":"dbe7aafbed574e8aa813efa660f49c349518e3016ec84138ea6168d7e9ed5cf1","src/lib.rs":"dc5f9a1351f1f2d271998830fbaf3230b6ba595b0055a18946c4efee63895baf"},"package":"6aa2700417c405c38f5e6902d699345241c28c0b7ade4abaad71e35a87eb1564"} \ No newline at end of file diff -Nru distinst-0.1.0/vendor/unix_socket/Cargo.toml distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/Cargo.toml --- distinst-0.1.0/vendor/unix_socket/Cargo.toml 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/Cargo.toml 1970-01-01 00:00:00.000000000 +0000 @@ -1,17 +0,0 @@ -[package] -name = "unix_socket" -version = "0.5.0" -authors = ["Steven Fackler "] -license = "MIT/Apache-2.0" -description = "Unix domain socket bindings" -repository = "https://github.com/rust-lang-nursery/unix-socket" -documentation = "https://doc.rust-lang.org/unix-socket/doc/v0.5.0/unix_socket" -readme = "README.md" -keywords = ["posix", "unix", "socket", "domain"] - -[dependencies] -libc = "0.2.1" -cfg-if = "0.1" - -[dev-dependencies] -tempdir = "0.3" diff -Nru distinst-0.1.0/vendor/unix_socket/LICENSE-APACHE distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/LICENSE-APACHE --- distinst-0.1.0/vendor/unix_socket/LICENSE-APACHE 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/LICENSE-APACHE 1970-01-01 00:00:00.000000000 +0000 @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff -Nru distinst-0.1.0/vendor/unix_socket/LICENSE-MIT distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/LICENSE-MIT --- distinst-0.1.0/vendor/unix_socket/LICENSE-MIT 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/LICENSE-MIT 1970-01-01 00:00:00.000000000 +0000 @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Steven Fackler - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - diff -Nru distinst-0.1.0/vendor/unix_socket/README.md distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/README.md --- distinst-0.1.0/vendor/unix_socket/README.md 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/README.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,7 +0,0 @@ -# unix-socket - -[![Build Status](https://travis-ci.org/rust-lang-nursery/unix-socket.svg?branch=master)](https://travis-ci.org/rust-lang-nursery/unix-socket) [![Latest Version](https://img.shields.io/crates/v/unix_socket.svg)](https://crates.io/crates/unix_socket) - -Support for Unix domain socket clients and servers. - -[Documentation](https://doc.rust-lang.org/unix-socket/doc/v0.4.6/unix_socket) diff -Nru distinst-0.1.0/vendor/unix_socket/src/lib.rs distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/src/lib.rs --- distinst-0.1.0/vendor/unix_socket/src/lib.rs 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/src/lib.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,1242 +0,0 @@ -//! Support for Unix domain socket clients and servers. -#![warn(missing_docs)] -#![doc(html_root_url="https://doc.rust-lang.org/unix-socket/doc/v0.5.0")] - -#[macro_use] -extern crate cfg_if; -extern crate libc; - -use std::ascii; -use std::cmp::Ordering; -use std::convert::AsRef; -use std::ffi::OsStr; -use std::fmt; -use std::io; -use std::iter::IntoIterator; -use std::mem; -use std::mem::size_of; -use std::net::Shutdown; -use std::os::unix::ffi::OsStrExt; -use std::os::unix::io::{RawFd, AsRawFd, FromRawFd, IntoRawFd}; -use std::path::Path; -use std::time::Duration; - -fn sun_path_offset() -> usize { - unsafe { - // Work with an actual instance of the type since using a null pointer is UB - let addr: libc::sockaddr_un = mem::uninitialized(); - let base = &addr as *const _ as usize; - let path = &addr.sun_path as *const _ as usize; - path - base - } -} - -fn cvt(v: libc::c_int) -> io::Result { - if v < 0 { - Err(io::Error::last_os_error()) - } else { - Ok(v) - } -} - -fn cvt_s(v: libc::ssize_t) -> io::Result { - if v < 0 { - Err(io::Error::last_os_error()) - } else { - Ok(v) - } -} - -struct Inner(RawFd); - -impl Drop for Inner { - fn drop(&mut self) { - unsafe { - libc::close(self.0); - } - } -} - -impl Inner { - fn new(kind: libc::c_int) -> io::Result { - unsafe { cvt(libc::socket(libc::AF_UNIX, kind, 0)).map(Inner) } - } - - fn new_pair(kind: libc::c_int) -> io::Result<(Inner, Inner)> { - unsafe { - let mut fds = [0, 0]; - try!(cvt(libc::socketpair(libc::AF_UNIX, kind, 0, fds.as_mut_ptr()))); - Ok((Inner(fds[0]), Inner(fds[1]))) - } - } - - fn try_clone(&self) -> io::Result { - unsafe { cvt(libc::dup(self.0)).map(Inner) } - } - - fn shutdown(&self, how: Shutdown) -> io::Result<()> { - let how = match how { - Shutdown::Read => libc::SHUT_RD, - Shutdown::Write => libc::SHUT_WR, - Shutdown::Both => libc::SHUT_RDWR, - }; - - unsafe { cvt(libc::shutdown(self.0, how)).map(|_| ()) } - } - - fn timeout(&self, kind: libc::c_int) -> io::Result> { - let timeout = unsafe { - let mut timeout: libc::timeval = mem::zeroed(); - let mut size = mem::size_of::() as libc::socklen_t; - try!(cvt(libc::getsockopt(self.0, - libc::SOL_SOCKET, - kind, - &mut timeout as *mut _ as *mut _, - &mut size as *mut _ as *mut _))); - timeout - }; - - if timeout.tv_sec == 0 && timeout.tv_usec == 0 { - Ok(None) - } else { - Ok(Some(Duration::new(timeout.tv_sec as u64, (timeout.tv_usec as u32) * 1000))) - } - } - - fn set_timeout(&self, dur: Option, kind: libc::c_int) -> io::Result<()> { - let timeout = match dur { - Some(dur) => { - if dur.as_secs() == 0 && dur.subsec_nanos() == 0 { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout")); - } - - let (secs, usecs) = if dur.as_secs() > libc::time_t::max_value() as u64 { - (libc::time_t::max_value(), 999_999) - } else { - (dur.as_secs() as libc::time_t, - (dur.subsec_nanos() / 1000) as libc::suseconds_t) - }; - let mut timeout = libc::timeval { - tv_sec: secs, - tv_usec: usecs, - }; - if timeout.tv_sec == 0 && timeout.tv_usec == 0 { - timeout.tv_usec = 1; - } - timeout - } - None => { - libc::timeval { - tv_sec: 0, - tv_usec: 0, - } - } - }; - - unsafe { - cvt(libc::setsockopt(self.0, - libc::SOL_SOCKET, - kind, - &timeout as *const _ as *const _, - mem::size_of::() as libc::socklen_t)) - .map(|_| ()) - } - } - - fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { - let mut nonblocking = nonblocking as libc::c_ulong; - unsafe { cvt(libc::ioctl(self.0, libc::FIONBIO, &mut nonblocking)).map(|_| ()) } - } - - fn take_error(&self) -> io::Result> { - let mut errno: libc::c_int = 0; - - unsafe { - try!(cvt(libc::getsockopt(self.0, - libc::SOL_SOCKET, - libc::SO_ERROR, - &mut errno as *mut _ as *mut _, - &mut mem::size_of_val(&errno) as *mut _ as *mut _))); - } - - if errno == 0 { - Ok(None) - } else { - Ok(Some(io::Error::from_raw_os_error(errno))) - } - } -} - -unsafe fn sockaddr_un>(path: P) -> io::Result<(libc::sockaddr_un, libc::socklen_t)> { - let mut addr: libc::sockaddr_un = mem::zeroed(); - addr.sun_family = libc::AF_UNIX as libc::sa_family_t; - - let bytes = path.as_ref().as_os_str().as_bytes(); - - match (bytes.get(0), bytes.len().cmp(&addr.sun_path.len())) { - // Abstract paths don't need a null terminator - (Some(&0), Ordering::Greater) => { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "path must be no longer than SUN_LEN")); - } - (_, Ordering::Greater) | (_, Ordering::Equal) => { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "path must be shorter than SUN_LEN")); - } - _ => {} - } - for (dst, src) in addr.sun_path.iter_mut().zip(bytes.iter()) { - *dst = *src as libc::c_char; - } - // null byte for pathname addresses is already there because we zeroed the - // struct - - let mut len = sun_path_offset() + bytes.len(); - match bytes.get(0) { - Some(&0) | None => {} - Some(_) => len += 1, - } - Ok((addr, len as libc::socklen_t)) -} - -enum AddressKind<'a> { - Unnamed, - Pathname(&'a Path), - Abstract(&'a [u8]), -} - -/// An address associated with a Unix socket. -#[derive(Clone)] -pub struct SocketAddr { - addr: libc::sockaddr_un, - len: libc::socklen_t, -} - -impl SocketAddr { - fn new(f: F) -> io::Result - where F: FnOnce(*mut libc::sockaddr, *mut libc::socklen_t) -> libc::c_int - { - unsafe { - let mut addr: libc::sockaddr_un = mem::zeroed(); - let mut len = mem::size_of::() as libc::socklen_t; - try!(cvt(f(&mut addr as *mut _ as *mut _, &mut len))); - - if len == 0 { - // When there is a datagram from unnamed unix socket - // linux returns zero bytes of address - len = sun_path_offset() as libc::socklen_t; // i.e. zero-length address - } else if addr.sun_family != libc::AF_UNIX as libc::sa_family_t { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "file descriptor did not correspond to a Unix socket")); - } - - Ok(SocketAddr { - addr: addr, - len: len, - }) - } - } - - /// Returns true iff the address is unnamed. - pub fn is_unnamed(&self) -> bool { - if let AddressKind::Unnamed = self.address() { - true - } else { - false - } - } - - /// Returns the contents of this address if it is a `pathname` address. - pub fn as_pathname(&self) -> Option<&Path> { - if let AddressKind::Pathname(path) = self.address() { - Some(path) - } else { - None - } - } - - fn address<'a>(&'a self) -> AddressKind<'a> { - let len = self.len as usize - sun_path_offset(); - let path = unsafe { mem::transmute::<&[libc::c_char], &[u8]>(&self.addr.sun_path) }; - - // OSX seems to return a len of 16 and a zeroed sun_path for unnamed addresses - if len == 0 || (cfg!(not(target_os = "linux")) && self.addr.sun_path[0] == 0) { - AddressKind::Unnamed - } else if self.addr.sun_path[0] == 0 { - AddressKind::Abstract(&path[1..len]) - } else { - AddressKind::Pathname(OsStr::from_bytes(&path[..len - 1]).as_ref()) - } - } -} - -impl fmt::Debug for SocketAddr { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - match self.address() { - AddressKind::Unnamed => write!(fmt, "(unnamed)"), - AddressKind::Abstract(name) => write!(fmt, "{} (abstract)", AsciiEscaped(name)), - AddressKind::Pathname(path) => write!(fmt, "{:?} (pathname)", path), - } - } -} - -struct AsciiEscaped<'a>(&'a [u8]); - -impl<'a> fmt::Display for AsciiEscaped<'a> { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - try!(write!(fmt, "\"")); - for byte in self.0.iter().cloned().flat_map(ascii::escape_default) { - try!(write!(fmt, "{}", byte as char)); - } - write!(fmt, "\"") - } -} - -/// OS specific extension traits. -pub mod os { - /// Linux specific extension traits. - #[cfg(target_os = "linux")] - pub mod linux { - use {AddressKind, SocketAddr}; - - /// Linux specific extensions for the `SocketAddr` type. - pub trait SocketAddrExt { - /// Returns the contents of this address (without the leading - /// null byte) if it is an `abstract` address. - fn as_abstract(&self) -> Option<&[u8]>; - } - - impl SocketAddrExt for SocketAddr { - fn as_abstract(&self) -> Option<&[u8]> { - if let AddressKind::Abstract(path) = self.address() { - Some(path) - } else { - None - } - } - } - } -} - -/// A Unix stream socket. -/// -/// # Examples -/// -/// ```rust,no_run -/// use unix_socket::UnixStream; -/// use std::io::prelude::*; -/// -/// let mut stream = UnixStream::connect("/path/to/my/socket").unwrap(); -/// stream.write_all(b"hello world").unwrap(); -/// let mut response = String::new(); -/// stream.read_to_string(&mut response).unwrap(); -/// println!("{}", response); -/// ``` -pub struct UnixStream { - inner: Inner, -} - -impl fmt::Debug for UnixStream { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - let mut builder = fmt.debug_struct("UnixStream"); - builder.field("fd", &self.inner.0); - if let Ok(addr) = self.local_addr() { - builder.field("local", &addr); - } - if let Ok(addr) = self.peer_addr() { - builder.field("peer", &addr); - } - builder.finish() - } -} - -impl UnixStream { - /// Connects to the socket named by `path`. - /// - /// Linux provides, as a nonportable extension, a separate "abstract" - /// address namespace as opposed to filesystem-based addressing. If `path` - /// begins with a null byte, it will be interpreted as an "abstract" - /// address. Otherwise, it will be interpreted as a "pathname" address, - /// corresponding to a path on the filesystem. - pub fn connect>(path: P) -> io::Result { - unsafe { - let inner = try!(Inner::new(libc::SOCK_STREAM)); - let (addr, len) = try!(sockaddr_un(path)); - - let ret = libc::connect(inner.0, &addr as *const _ as *const _, len); - if ret < 0 { - Err(io::Error::last_os_error()) - } else { - Ok(UnixStream { inner: inner }) - } - } - } - - /// Creates an unnamed pair of connected sockets. - /// - /// Returns two `UnixStream`s which are connected to each other. - pub fn pair() -> io::Result<(UnixStream, UnixStream)> { - let (i1, i2) = try!(Inner::new_pair(libc::SOCK_STREAM)); - Ok((UnixStream { inner: i1 }, UnixStream { inner: i2 })) - } - - /// Creates a new independently owned handle to the underlying socket. - /// - /// The returned `UnixStream` is a reference to the same stream that this - /// object references. Both handles will read and write the same stream of - /// data, and options set on one stream will be propogated to the other - /// stream. - pub fn try_clone(&self) -> io::Result { - Ok(UnixStream { inner: try!(self.inner.try_clone()) }) - } - - /// Returns the socket address of the local half of this connection. - pub fn local_addr(&self) -> io::Result { - SocketAddr::new(|addr, len| unsafe { libc::getsockname(self.inner.0, addr, len) }) - } - - /// Returns the socket address of the remote half of this connection. - pub fn peer_addr(&self) -> io::Result { - SocketAddr::new(|addr, len| unsafe { libc::getpeername(self.inner.0, addr, len) }) - } - - /// Sets the read timeout for the socket. - /// - /// If the provided value is `None`, then `read` calls will block - /// indefinitely. It is an error to pass the zero `Duration` to this - /// method. - pub fn set_read_timeout(&self, timeout: Option) -> io::Result<()> { - self.inner.set_timeout(timeout, libc::SO_RCVTIMEO) - } - - /// Sets the write timeout for the socket. - /// - /// If the provided value is `None`, then `write` calls will block - /// indefinitely. It is an error to pass the zero `Duration` to this - /// method. - pub fn set_write_timeout(&self, timeout: Option) -> io::Result<()> { - self.inner.set_timeout(timeout, libc::SO_SNDTIMEO) - } - - /// Returns the read timeout of this socket. - pub fn read_timeout(&self) -> io::Result> { - self.inner.timeout(libc::SO_RCVTIMEO) - } - - /// Returns the write timeout of this socket. - pub fn write_timeout(&self) -> io::Result> { - self.inner.timeout(libc::SO_SNDTIMEO) - } - - /// Moves the socket into or out of nonblocking mode. - pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { - self.inner.set_nonblocking(nonblocking) - } - - /// Returns the value of the `SO_ERROR` option. - pub fn take_error(&self) -> io::Result> { - self.inner.take_error() - } - - /// Shuts down the read, write, or both halves of this connection. - /// - /// This function will cause all pending and future I/O calls on the - /// specified portions to immediately return with an appropriate value - /// (see the documentation of `Shutdown`). - pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { - self.inner.shutdown(how) - } -} - -impl io::Read for UnixStream { - fn read(&mut self, buf: &mut [u8]) -> io::Result { - io::Read::read(&mut &*self, buf) - } -} - -impl<'a> io::Read for &'a UnixStream { - fn read(&mut self, buf: &mut [u8]) -> io::Result { - unsafe { - cvt_s(libc::recv(self.inner.0, buf.as_mut_ptr() as *mut _, buf.len(), 0)) - .map(|r| r as usize) - } - } -} - -impl io::Write for UnixStream { - fn write(&mut self, buf: &[u8]) -> io::Result { - io::Write::write(&mut &*self, buf) - } - - fn flush(&mut self) -> io::Result<()> { - io::Write::flush(&mut &*self) - } -} - -impl<'a> io::Write for &'a UnixStream { - fn write(&mut self, buf: &[u8]) -> io::Result { - unsafe { - cvt_s(libc::send(self.inner.0, buf.as_ptr() as *const _, buf.len(), 0)) - .map(|r| r as usize) - } - } - - fn flush(&mut self) -> io::Result<()> { - Ok(()) - } -} - -impl AsRawFd for UnixStream { - fn as_raw_fd(&self) -> RawFd { - self.inner.0 - } -} - -impl FromRawFd for UnixStream { - unsafe fn from_raw_fd(fd: RawFd) -> UnixStream { - UnixStream { inner: Inner(fd) } - } -} - -impl IntoRawFd for UnixStream { - fn into_raw_fd(self) -> RawFd { - let fd = self.inner.0; - mem::forget(self); - fd - } -} - -/// A structure representing a Unix domain socket server. -/// -/// # Examples -/// -/// ```rust,no_run -/// use std::thread; -/// use unix_socket::{UnixStream, UnixListener}; -/// -/// fn handle_client(stream: UnixStream) { -/// // ... -/// } -/// -/// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); -/// -/// // accept connections and process them, spawning a new thread for each one -/// for stream in listener.incoming() { -/// match stream { -/// Ok(stream) => { -/// /* connection succeeded */ -/// thread::spawn(|| handle_client(stream)); -/// } -/// Err(err) => { -/// /* connection failed */ -/// break; -/// } -/// } -/// } -/// -/// // close the listener socket -/// drop(listener); -/// ``` -pub struct UnixListener { - inner: Inner, -} - -impl fmt::Debug for UnixListener { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - let mut builder = fmt.debug_struct("UnixListener"); - builder.field("fd", &self.inner.0); - if let Ok(addr) = self.local_addr() { - builder.field("local", &addr); - } - builder.finish() - } -} - -impl UnixListener { - /// Creates a new `UnixListener` bound to the specified socket. - /// - /// Linux provides, as a nonportable extension, a separate "abstract" - /// address namespace as opposed to filesystem-based addressing. If `path` - /// begins with a null byte, it will be interpreted as an "abstract" - /// address. Otherwise, it will be interpreted as a "pathname" address, - /// corresponding to a path on the filesystem. - pub fn bind>(path: P) -> io::Result { - unsafe { - let inner = try!(Inner::new(libc::SOCK_STREAM)); - let (addr, len) = try!(sockaddr_un(path)); - - try!(cvt(libc::bind(inner.0, &addr as *const _ as *const _, len))); - try!(cvt(libc::listen(inner.0, 128))); - - Ok(UnixListener { inner: inner }) - } - } - - /// Accepts a new incoming connection to this listener. - /// - /// This function will block the calling thread until a new Unix connection - /// is established. When established, the corersponding `UnixStream` and - /// the remote peer's address will be returned. - pub fn accept(&self) -> io::Result<(UnixStream, SocketAddr)> { - unsafe { - let mut fd = 0; - let addr = try!(SocketAddr::new(|addr, len| { - fd = libc::accept(self.inner.0, addr, len); - fd - })); - - Ok((UnixStream { inner: Inner(fd) }, addr)) - } - } - - /// Creates a new independently owned handle to the underlying socket. - /// - /// The returned `UnixListener` is a reference to the same socket that this - /// object references. Both handles can be used to accept incoming - /// connections and options set on one listener will affect the other. - pub fn try_clone(&self) -> io::Result { - Ok(UnixListener { inner: try!(self.inner.try_clone()) }) - } - - /// Returns the local socket address of this listener. - pub fn local_addr(&self) -> io::Result { - SocketAddr::new(|addr, len| unsafe { libc::getsockname(self.inner.0, addr, len) }) - } - - /// Moves the socket into or out of nonblocking mode. - pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { - self.inner.set_nonblocking(nonblocking) - } - - /// Returns the value of the `SO_ERROR` option. - pub fn take_error(&self) -> io::Result> { - self.inner.take_error() - } - - /// Returns an iterator over incoming connections. - /// - /// The iterator will never return `None` and will also not yield the - /// peer's `SocketAddr` structure. - pub fn incoming<'a>(&'a self) -> Incoming<'a> { - Incoming { listener: self } - } -} - -impl AsRawFd for UnixListener { - fn as_raw_fd(&self) -> RawFd { - self.inner.0 - } -} - -impl FromRawFd for UnixListener { - unsafe fn from_raw_fd(fd: RawFd) -> UnixListener { - UnixListener { inner: Inner(fd) } - } -} - -impl IntoRawFd for UnixListener { - fn into_raw_fd(self) -> RawFd { - let fd = self.inner.0; - mem::forget(self); - fd - } -} - -impl<'a> IntoIterator for &'a UnixListener { - type Item = io::Result; - type IntoIter = Incoming<'a>; - - fn into_iter(self) -> Incoming<'a> { - self.incoming() - } -} - -/// An iterator over incoming connections to a `UnixListener`. -/// -/// It will never return `None`. -#[derive(Debug)] -pub struct Incoming<'a> { - listener: &'a UnixListener, -} - -impl<'a> Iterator for Incoming<'a> { - type Item = io::Result; - - fn next(&mut self) -> Option> { - Some(self.listener.accept().map(|s| s.0)) - } - - fn size_hint(&self) -> (usize, Option) { - (usize::max_value(), None) - } -} - -/// A Unix datagram socket. -/// -/// # Examples -/// -/// ```rust,no_run -/// use unix_socket::UnixDatagram; -/// -/// let socket = UnixDatagram::bind("/path/to/my/socket").unwrap(); -/// socket.send_to(b"hello world", "/path/to/other/socket").unwrap(); -/// let mut buf = [0; 100]; -/// let (count, address) = socket.recv_from(&mut buf).unwrap(); -/// println!("socket {:?} sent {:?}", address, &buf[..count]); -/// ``` -pub struct UnixDatagram { - inner: Inner, -} - -impl fmt::Debug for UnixDatagram { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - let mut builder = fmt.debug_struct("UnixDatagram"); - builder.field("fd", &self.inner.0); - if let Ok(addr) = self.local_addr() { - builder.field("local", &addr); - } - if let Ok(addr) = self.peer_addr() { - builder.field("peer", &addr); - } - builder.finish() - } -} - -impl UnixDatagram { - /// Creates a Unix datagram socket bound to the given path. - /// - /// Linux provides, as a nonportable extension, a separate "abstract" - /// address namespace as opposed to filesystem-based addressing. If `path` - /// begins with a null byte, it will be interpreted as an "abstract" - /// address. Otherwise, it will be interpreted as a "pathname" address, - /// corresponding to a path on the filesystem. - pub fn bind>(path: P) -> io::Result { - unsafe { - let inner = try!(Inner::new(libc::SOCK_DGRAM)); - let (addr, len) = try!(sockaddr_un(path)); - - try!(cvt(libc::bind(inner.0, &addr as *const _ as *const _, len))); - - Ok(UnixDatagram { inner: inner }) - } - } - - /// Creates a Unix Datagram socket which is not bound to any address. - pub fn unbound() -> io::Result { - let inner = try!(Inner::new(libc::SOCK_DGRAM)); - Ok(UnixDatagram { inner: inner }) - } - - /// Create an unnamed pair of connected sockets. - /// - /// Returns two `UnixDatagrams`s which are connected to each other. - pub fn pair() -> io::Result<(UnixDatagram, UnixDatagram)> { - let (i1, i2) = try!(Inner::new_pair(libc::SOCK_DGRAM)); - Ok((UnixDatagram { inner: i1 }, UnixDatagram { inner: i2 })) - } - - /// Connects the socket to the specified address. - /// - /// The `send` method may be used to send data to the specified address. - /// `recv` and `recv_from` will only receive data from that address. - pub fn connect>(&self, path: P) -> io::Result<()> { - unsafe { - let (addr, len) = try!(sockaddr_un(path)); - - try!(cvt(libc::connect(self.inner.0, &addr as *const _ as *const _, len))); - - Ok(()) - } - } - - /// Returns the address of this socket. - pub fn local_addr(&self) -> io::Result { - SocketAddr::new(|addr, len| unsafe { libc::getsockname(self.inner.0, addr, len) }) - } - - /// Returns the address of this socket's peer. - /// - /// The `connect` method will connect the socket to a peer. - pub fn peer_addr(&self) -> io::Result { - SocketAddr::new(|addr, len| unsafe { libc::getpeername(self.inner.0, addr, len) }) - } - - /// Receives data from the socket. - /// - /// On success, returns the number of bytes read and the address from - /// whence the data came. - pub fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { - let mut count = 0; - let addr = try!(SocketAddr::new(|addr, len| { - unsafe { - count = libc::recvfrom(self.inner.0, - buf.as_mut_ptr() as *mut _, - buf.len(), - 0, - addr, - len); - if count > 0 { - 1 - } else if count == 0 { - 0 - } else { - -1 - } - } - })); - - Ok((count as usize, addr)) - } - - /// Receives data from the socket. - /// - /// On success, returns the number of bytes read. - pub fn recv(&self, buf: &mut [u8]) -> io::Result { - unsafe { - let count = try!(cvt_s(libc::recv(self.inner.0, - buf.as_mut_ptr() as *mut _, - buf.len(), - 0))); - Ok(count as usize) - } - } - - /// Sends data on the socket to the specified address. - /// - /// On success, returns the number of bytes written. - pub fn send_to>(&self, buf: &[u8], path: P) -> io::Result { - unsafe { - let (addr, len) = try!(sockaddr_un(path)); - - let count = try!(cvt_s(libc::sendto(self.inner.0, - buf.as_ptr() as *const _, - buf.len(), - 0, - &addr as *const _ as *const _, - len))); - Ok(count as usize) - } - } - - /// Sends data on the socket to the socket's peer. - /// - /// The peer address may be set by the `connect` method, and this method - /// will return an error if the socket has not already been connected. - /// - /// On success, returns the number of bytes written. - pub fn send(&self, buf: &[u8]) -> io::Result { - unsafe { - let count = try!(cvt_s(libc::send(self.inner.0, - buf.as_ptr() as *const _, - buf.len(), - 0))); - Ok(count as usize) - } - } - - /// Sets the read timeout for the socket. - /// - /// If the provided value is `None`, then `recv` and `recv_from` calls will - /// block indefinitely. It is an error to pass the zero `Duration` to this - /// method. - pub fn set_read_timeout(&self, timeout: Option) -> io::Result<()> { - self.inner.set_timeout(timeout, libc::SO_RCVTIMEO) - } - - /// Sets the write timeout for the socket. - /// - /// If the provided value is `None`, then `send` and `send_to` calls will - /// block indefinitely. It is an error to pass the zero `Duration` to this - /// method. - pub fn set_write_timeout(&self, timeout: Option) -> io::Result<()> { - self.inner.set_timeout(timeout, libc::SO_SNDTIMEO) - } - - /// Returns the read timeout of this socket. - pub fn read_timeout(&self) -> io::Result> { - self.inner.timeout(libc::SO_RCVTIMEO) - } - - /// Returns the write timeout of this socket. - pub fn write_timeout(&self) -> io::Result> { - self.inner.timeout(libc::SO_SNDTIMEO) - } - - /// Moves the socket into or out of nonblocking mode. - pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { - self.inner.set_nonblocking(nonblocking) - } - - /// Returns the value of the `SO_ERROR` option. - pub fn take_error(&self) -> io::Result> { - self.inner.take_error() - } - - /// Shut down the read, write, or both halves of this connection. - /// - /// This function will cause all pending and future I/O calls on the - /// specified portions to immediately return with an appropriate value - /// (see the documentation of `Shutdown`). - pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { - self.inner.shutdown(how) - } -} - -impl AsRawFd for UnixDatagram { - fn as_raw_fd(&self) -> RawFd { - self.inner.0 - } -} - -impl FromRawFd for UnixDatagram { - unsafe fn from_raw_fd(fd: RawFd) -> UnixDatagram { - UnixDatagram { inner: Inner(fd) } - } -} - -impl IntoRawFd for UnixDatagram { - fn into_raw_fd(self) -> RawFd { - let fd = self.inner.0; - mem::forget(self); - fd - } -} - -#[cfg(test)] -mod test { - extern crate tempdir; - - use std::thread; - use std::io; - use std::io::prelude::*; - use std::time::Duration; - use self::tempdir::TempDir; - - use super::*; - - macro_rules! or_panic { - ($e:expr) => { - match $e { - Ok(e) => e, - Err(e) => panic!("{}", e), - } - } - } - - #[test] - fn basic() { - let dir = or_panic!(TempDir::new("unix_socket")); - let socket_path = dir.path().join("sock"); - let msg1 = b"hello"; - let msg2 = b"world!"; - - let listener = or_panic!(UnixListener::bind(&socket_path)); - let thread = thread::spawn(move || { - let mut stream = or_panic!(listener.accept()).0; - let mut buf = [0; 5]; - or_panic!(stream.read(&mut buf)); - assert_eq!(&msg1[..], &buf[..]); - or_panic!(stream.write_all(msg2)); - }); - - let mut stream = or_panic!(UnixStream::connect(&socket_path)); - assert_eq!(Some(&*socket_path), - stream.peer_addr().unwrap().as_pathname()); - or_panic!(stream.write_all(msg1)); - let mut buf = vec![]; - or_panic!(stream.read_to_end(&mut buf)); - assert_eq!(&msg2[..], &buf[..]); - drop(stream); - - thread.join().unwrap(); - } - - #[test] - fn pair() { - let msg1 = b"hello"; - let msg2 = b"world!"; - - let (mut s1, mut s2) = or_panic!(UnixStream::pair()); - let thread = thread::spawn(move || { - // s1 must be moved in or the test will hang! - let mut buf = [0; 5]; - or_panic!(s1.read(&mut buf)); - assert_eq!(&msg1[..], &buf[..]); - or_panic!(s1.write_all(msg2)); - }); - - or_panic!(s2.write_all(msg1)); - let mut buf = vec![]; - or_panic!(s2.read_to_end(&mut buf)); - assert_eq!(&msg2[..], &buf[..]); - drop(s2); - - thread.join().unwrap(); - } - - #[test] - #[cfg(target_os = "linux")] - fn abstract_address() { - use os::linux::SocketAddrExt; - - let socket_path = "\0the path"; - let msg1 = b"hello"; - let msg2 = b"world!"; - - let listener = or_panic!(UnixListener::bind(&socket_path)); - let thread = thread::spawn(move || { - let mut stream = or_panic!(listener.accept()).0; - let mut buf = [0; 5]; - or_panic!(stream.read(&mut buf)); - assert_eq!(&msg1[..], &buf[..]); - or_panic!(stream.write_all(msg2)); - }); - - let mut stream = or_panic!(UnixStream::connect(&socket_path)); - assert_eq!(Some(&b"the path"[..]), - stream.peer_addr().unwrap().as_abstract()); - or_panic!(stream.write_all(msg1)); - let mut buf = vec![]; - or_panic!(stream.read_to_end(&mut buf)); - assert_eq!(&msg2[..], &buf[..]); - drop(stream); - - thread.join().unwrap(); - } - - #[test] - fn try_clone() { - let dir = or_panic!(TempDir::new("unix_socket")); - let socket_path = dir.path().join("sock"); - let msg1 = b"hello"; - let msg2 = b"world"; - - let listener = or_panic!(UnixListener::bind(&socket_path)); - let thread = thread::spawn(move || { - let mut stream = or_panic!(listener.accept()).0; - or_panic!(stream.write_all(msg1)); - or_panic!(stream.write_all(msg2)); - }); - - let mut stream = or_panic!(UnixStream::connect(&socket_path)); - let mut stream2 = or_panic!(stream.try_clone()); - - let mut buf = [0; 5]; - or_panic!(stream.read(&mut buf)); - assert_eq!(&msg1[..], &buf[..]); - or_panic!(stream2.read(&mut buf)); - assert_eq!(&msg2[..], &buf[..]); - - thread.join().unwrap(); - } - - #[test] - fn iter() { - let dir = or_panic!(TempDir::new("unix_socket")); - let socket_path = dir.path().join("sock"); - - let listener = or_panic!(UnixListener::bind(&socket_path)); - let thread = thread::spawn(move || { - for stream in listener.incoming().take(2) { - let mut stream = or_panic!(stream); - let mut buf = [0]; - or_panic!(stream.read(&mut buf)); - } - }); - - for _ in 0..2 { - let mut stream = or_panic!(UnixStream::connect(&socket_path)); - or_panic!(stream.write_all(&[0])); - } - - thread.join().unwrap(); - } - - #[test] - fn long_path() { - let dir = or_panic!(TempDir::new("unix_socket")); - let socket_path = dir.path() - .join("asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfa\ - sasdfasdfasdasdfasdfasdfadfasdfasdfasdfasdfasdf"); - match UnixStream::connect(&socket_path) { - Err(ref e) if e.kind() == io::ErrorKind::InvalidInput => {} - Err(e) => panic!("unexpected error {}", e), - Ok(_) => panic!("unexpected success"), - } - - match UnixListener::bind(&socket_path) { - Err(ref e) if e.kind() == io::ErrorKind::InvalidInput => {} - Err(e) => panic!("unexpected error {}", e), - Ok(_) => panic!("unexpected success"), - } - - match UnixDatagram::bind(&socket_path) { - Err(ref e) if e.kind() == io::ErrorKind::InvalidInput => {} - Err(e) => panic!("unexpected error {}", e), - Ok(_) => panic!("unexpected success"), - } - } - - #[test] - fn timeouts() { - let dir = or_panic!(TempDir::new("unix_socket")); - let socket_path = dir.path().join("sock"); - - let _listener = or_panic!(UnixListener::bind(&socket_path)); - - let stream = or_panic!(UnixStream::connect(&socket_path)); - let dur = Duration::new(15410, 0); - - assert_eq!(None, or_panic!(stream.read_timeout())); - - or_panic!(stream.set_read_timeout(Some(dur))); - assert_eq!(Some(dur), or_panic!(stream.read_timeout())); - - assert_eq!(None, or_panic!(stream.write_timeout())); - - or_panic!(stream.set_write_timeout(Some(dur))); - assert_eq!(Some(dur), or_panic!(stream.write_timeout())); - - or_panic!(stream.set_read_timeout(None)); - assert_eq!(None, or_panic!(stream.read_timeout())); - - or_panic!(stream.set_write_timeout(None)); - assert_eq!(None, or_panic!(stream.write_timeout())); - } - - #[test] - fn test_read_timeout() { - let dir = or_panic!(TempDir::new("unix_socket")); - let socket_path = dir.path().join("sock"); - - let _listener = or_panic!(UnixListener::bind(&socket_path)); - - let mut stream = or_panic!(UnixStream::connect(&socket_path)); - or_panic!(stream.set_read_timeout(Some(Duration::from_millis(1000)))); - - let mut buf = [0; 10]; - let kind = stream.read(&mut buf).err().expect("expected error").kind(); - assert!(kind == io::ErrorKind::WouldBlock || kind == io::ErrorKind::TimedOut); - } - - #[test] - fn test_read_with_timeout() { - let dir = or_panic!(TempDir::new("unix_socket")); - let socket_path = dir.path().join("sock"); - - let listener = or_panic!(UnixListener::bind(&socket_path)); - - let mut stream = or_panic!(UnixStream::connect(&socket_path)); - or_panic!(stream.set_read_timeout(Some(Duration::from_millis(1000)))); - - let mut other_end = or_panic!(listener.accept()).0; - or_panic!(other_end.write_all(b"hello world")); - - let mut buf = [0; 11]; - or_panic!(stream.read(&mut buf)); - assert_eq!(b"hello world", &buf[..]); - - let kind = stream.read(&mut buf).err().expect("expected error").kind(); - assert!(kind == io::ErrorKind::WouldBlock || kind == io::ErrorKind::TimedOut); - } - - #[test] - fn test_unix_datagram() { - let dir = or_panic!(TempDir::new("unix_socket")); - let path1 = dir.path().join("sock1"); - let path2 = dir.path().join("sock2"); - - let sock1 = or_panic!(UnixDatagram::bind(&path1)); - let sock2 = or_panic!(UnixDatagram::bind(&path2)); - - let msg = b"hello world"; - or_panic!(sock1.send_to(msg, &path2)); - let mut buf = [0; 11]; - or_panic!(sock2.recv_from(&mut buf)); - assert_eq!(msg, &buf[..]); - } - - #[test] - fn test_unnamed_unix_datagram() { - let dir = or_panic!(TempDir::new("unix_socket")); - let path1 = dir.path().join("sock1"); - - let sock1 = or_panic!(UnixDatagram::bind(&path1)); - let sock2 = or_panic!(UnixDatagram::unbound()); - - let msg = b"hello world"; - or_panic!(sock2.send_to(msg, &path1)); - let mut buf = [0; 11]; - let (usize, addr) = or_panic!(sock1.recv_from(&mut buf)); - assert_eq!(usize, 11); - assert!(addr.is_unnamed()); - assert_eq!(msg, &buf[..]); - } - - #[test] - fn test_connect_unix_datagram() { - let dir = or_panic!(TempDir::new("unix_socket")); - let path1 = dir.path().join("sock1"); - let path2 = dir.path().join("sock2"); - - let bsock1 = or_panic!(UnixDatagram::bind(&path1)); - let bsock2 = or_panic!(UnixDatagram::bind(&path2)); - let sock = or_panic!(UnixDatagram::unbound()); - or_panic!(sock.connect(&path1)); - - // Check send() - let msg = b"hello there"; - or_panic!(sock.send(msg)); - let mut buf = [0; 11]; - let (usize, addr) = or_panic!(bsock1.recv_from(&mut buf)); - assert_eq!(usize, 11); - assert!(addr.is_unnamed()); - assert_eq!(msg, &buf[..]); - - // Changing default socket works too - or_panic!(sock.connect(&path2)); - or_panic!(sock.send(msg)); - or_panic!(bsock2.recv_from(&mut buf)); - } - - #[test] - fn test_unix_datagram_recv() { - let dir = or_panic!(TempDir::new("unix_socket")); - let path1 = dir.path().join("sock1"); - - let sock1 = or_panic!(UnixDatagram::bind(&path1)); - let sock2 = or_panic!(UnixDatagram::unbound()); - or_panic!(sock2.connect(&path1)); - - let msg = b"hello world"; - or_panic!(sock2.send(msg)); - let mut buf = [0; 11]; - let size = or_panic!(sock1.recv(&mut buf)); - assert_eq!(size, 11); - assert_eq!(msg, &buf[..]); - } - - #[test] - fn datagram_pair() { - let msg1 = b"hello"; - let msg2 = b"world!"; - - let (s1, s2) = or_panic!(UnixDatagram::pair()); - let thread = thread::spawn(move || { - // s1 must be moved in or the test will hang! - let mut buf = [0; 5]; - or_panic!(s1.recv(&mut buf)); - assert_eq!(&msg1[..], &buf[..]); - or_panic!(s1.send(msg2)); - }); - - or_panic!(s2.send(msg1)); - let mut buf = [0; 6]; - or_panic!(s2.recv(&mut buf)); - assert_eq!(&msg2[..], &buf[..]); - drop(s2); - - thread.join().unwrap(); - } -} diff -Nru distinst-0.1.0/vendor/unix_socket/.travis.yml distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/.travis.yml --- distinst-0.1.0/vendor/unix_socket/.travis.yml 2017-12-11 20:30:33.000000000 +0000 +++ distinst-0.2.0+1513882807+18.04~34a6ac4/vendor/unix_socket/.travis.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,7 +0,0 @@ -language: rust -rust: -- nightly -- beta -- 1.4.0 -script: -- cargo test