libsystemd-0.2.1/.cargo_vcs_info.json0000644000000001121365254474300133200ustar00{ "git": { "sha1": "4955069b24c24c3dbadafbbb978299007ede5edf" } } libsystemd-0.2.1/COPYRIGHT010064400017500001750000000003501356354244600134170ustar0000000000000000Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: libsystemd Source: https://www.github.com/lucab/libsystemd-rs Files: * Copyright: 2017-2019, Project contributors License: MIT or Apache-2.0 libsystemd-0.2.1/Cargo.lock0000644000000434771365254474300113200ustar00# This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] name = "aho-corasick" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "block-buffer" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "block-padding" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "byte-tools" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "c2-chacha" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cc" version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "crypto-mac" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "digest" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "env_logger" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "error-chain" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "fake-simd" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "generic-array" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "getrandom" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "hmac" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "lazy_static" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libsystemd" version = "0.2.1" dependencies = [ "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", "quickcheck 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "memchr" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "nix" version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "opaque-debug" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "ppv-lite86" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro2" version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "quickcheck" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "quote" version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_chacha" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_core" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_hc" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex" version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex-syntax" version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde" version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde_derive 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "sha2" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "subtle" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" version = "0.15.34" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "thread_local" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "typenum" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "ucd-util" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "unicode-xid" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "utf8-ranges" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "uuid" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "version_check" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "void" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasi" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" "checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" "checksum cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a0c56216487bb80eec9c4516337b2588a4f2a2290d72a1416d930e4dcdb0c90d" "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" "checksum env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" "checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" "checksum hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f127a908633569f208325f86f71255d3363c79721d7f9fe31cd5569908819771" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" "checksum nix 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363" "checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409" "checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum quickcheck 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5ca504a2fdaa08d3517f442fbbba91ac24d1ec4c51ea68688a038765e3b2662" "checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" "checksum rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412" "checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" "checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" "checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" "checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" "checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" "checksum serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)" = "a72e9b96fa45ce22a4bc23da3858dfccfd60acd28a25bcd328a98fdd6bea43fd" "checksum serde_derive 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)" = "101b495b109a3e3ca8c4cbe44cf62391527cdfb6ba15821c5ce80bcd5ea23f9f" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" "checksum uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" libsystemd-0.2.1/Cargo.toml0000644000000031241365254474300113240ustar00# 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] edition = "2018" name = "libsystemd" version = "0.2.1" authors = ["Luca Bruno "] exclude = [".gitignore", ".travis.yml"] description = "A pure-Rust client library to interact with systemd" documentation = "https://docs.rs/libsystemd" readme = "README.md" keywords = ["systemd", "linux"] categories = ["api-bindings", "os::unix-apis"] license = "MIT/Apache-2.0" repository = "https://github.com/lucab/libsystemd-rs" [package.metadata.release] disable-publish = true disable-push = true post-release-commit-message = "cargo: development version bump" pre-release-commit-message = "cargo: libsystemd release {{version}}" sign-commit = true tag-message = "libsystemd {{version}}" [dependencies.error-chain] version = "^0.12.1" default-features = false [dependencies.hmac] version = "0.7" [dependencies.libc] version = "0.2" [dependencies.nix] version = "0.17" [dependencies.serde] version = "^1.0.91" features = ["derive"] [dependencies.sha2] version = "0.8" [dependencies.uuid] version = "^0.8.1" features = ["serde"] [dev-dependencies.quickcheck] version = "0.9" libsystemd-0.2.1/Cargo.toml.orig010064400017500001750000000017321365254473500150220ustar0000000000000000[package] name = "libsystemd" version = "0.2.1" authors = ["Luca Bruno "] license = "MIT/Apache-2.0" repository = "https://github.com/lucab/libsystemd-rs" documentation = "https://docs.rs/libsystemd" description = "A pure-Rust client library to interact with systemd" keywords = ["systemd", "linux"] categories = ["api-bindings", "os::unix-apis"] readme = "README.md" exclude = [ ".gitignore", ".travis.yml", ] edition = "2018" [dependencies] error-chain = { version = "^0.12.1", default-features = false } hmac = "0.7" libc = "0.2" nix = "0.17" serde = { version = "^1.0.91", features = ["derive"] } sha2 = "0.8" uuid = { version = "^0.8.1", features = ["serde"] } [dev-dependencies] quickcheck = "0.9" [package.metadata.release] sign-commit = true disable-publish = true disable-push = true pre-release-commit-message = "cargo: libsystemd release {{version}}" post-release-commit-message = "cargo: development version bump" tag-message = "libsystemd {{version}}" libsystemd-0.2.1/LICENSE-APACHE-2.0010064400017500001750000000261361356354244600143570ustar0000000000000000 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. libsystemd-0.2.1/LICENSE-MIT010064400017500001750000000017771356354244600135760ustar0000000000000000Permission 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. libsystemd-0.2.1/README.md010064400017500001750000000026541365224020600134000ustar0000000000000000# libsystemd [![Build Status](https://travis-ci.com/lucab/libsystemd-rs.svg?branch=master)](https://travis-ci.com/lucab/libsystemd-rs) [![crates.io](https://img.shields.io/crates/v/libsystemd.svg)](https://crates.io/crates/libsystemd) [![LoC](https://tokei.rs/b1/github/lucab/libsystemd-rs?category=code)](https://github.com/lucab/libsystemd-rs) [![Documentation](https://docs.rs/libsystemd/badge.svg)](https://docs.rs/libsystemd) A pure-Rust client library to work with systemd. It provides support to interact with systemd components available on modern Linux systems. This crate is entirely implemented in Rust, and does not require the libsystemd C library. NB: this crate is not yet features-complete. If you don't care about C dependency, check [rust-systemd](https://github.com/jmesmon/rust-systemd) instead. ## Example ```rust extern crate libsystemd; use libsystemd::daemon::{self, NotifyState}; fn main() { if !daemon::booted() { panic!("Not running systemd, early exit."); }; let sent = daemon::notify(true, &[NotifyState::Ready]).expect("notify failed"); if !sent { panic!("Notification not sent, early exit."); }; std::thread::park(); } ``` Some more examples are available under [examples](examples). ## License Licensed under either of * MIT license - * Apache License, Version 2.0 - at your option. libsystemd-0.2.1/examples/notify.rs010064400017500001750000000011611346610160600156100ustar0000000000000000extern crate libsystemd; use libsystemd::daemon::{self, NotifyState}; use std::{env, thread}; /* cargo build --example notify systemd-run --user --wait -p Type=notify ./target/debug/examples/notify [CUSTOM_STATUS] */ fn main() { if !daemon::booted() { println!("Not running systemd, early exit."); return; }; let state = match env::args().nth(1) { Some(s) => NotifyState::Status(s), None => NotifyState::Ready, }; let sent = daemon::notify(true, &[state]).expect("notify failed"); if !sent { println!("Notification not sent!"); } thread::park(); } libsystemd-0.2.1/examples/watchdog.rs010064400017500001750000000013701346610160600161020ustar0000000000000000extern crate libsystemd; use libsystemd::daemon::{self, NotifyState}; use std::thread; /* ``` [Service] WatchdogSec=1s ExecStart=/home/user/libsystemd-rs/target/debug/examples/watchdog ``` cargo build --example watchdog ; systemctl start --wait --user watchdog; systemctl status --user watchdog */ fn main() { if !daemon::booted() { println!("Not running systemd, early exit."); return; }; let timeout = daemon::watchdog_enabled(true).expect("watchdog disabled"); for i in 0..20 { let _sent = daemon::notify(false, &[NotifyState::Watchdog]).expect("notify failed"); println!("Notification #{} sent...", i); thread::sleep(timeout / 2); } println!("Blocking forever!"); thread::park(); } libsystemd-0.2.1/src/activation.rs010064400017500001750000000157371365250732100154310ustar0000000000000000use nix::mqueue::mq_getattr; use nix::sys::socket::getsockname; use nix::sys::socket::SockAddr; use nix::sys::stat::fstat; use std::convert::TryFrom; use std::env; use std::os::unix::io::{IntoRawFd, RawFd}; use std::process; use crate::errors::*; /// Minimum FD number used by systemd for passing sockets. const SD_LISTEN_FDS_START: RawFd = 3; /// Trait for checking the type of a file descriptor. pub trait IsType { /// Returns true if a file descriptor is a FIFO. fn is_fifo(&self) -> bool; /// Returns true if a file descriptor is a special file. fn is_special(&self) -> bool; /// Returns true if a file descriptor is a `PF_INET` socket. fn is_inet(&self) -> bool; /// Returns true if a file descriptor is a `PF_UNIX` socket. fn is_unix(&self) -> bool; /// Returns true if a file descriptor is a POSIX message queue descriptor. fn is_mq(&self) -> bool; } /// File descriptor passed by systemd to socket-activated services. /// /// See https://www.freedesktop.org/software/systemd/man/systemd.socket.html. #[derive(Debug, Clone)] pub struct FileDescriptor(SocketFd); /// Possible types of sockets. #[derive(Debug, Clone)] enum SocketFd { /// A FIFO named pipe (see `man 7 fifo`) Fifo(RawFd), /// A special file, such as character device nodes or special files in /// `/proc` and `/sys`. Special(RawFd), /// A `PF_INET` socket, such as UDP/TCP sockets. Inet(RawFd), /// A `PF_UNIX` socket (see `man 7 unix`). Unix(RawFd), /// A POSIX message queue (see `man 7 mq_overview`). Mq(RawFd), } impl IsType for FileDescriptor { fn is_fifo(&self) -> bool { match self.0 { SocketFd::Fifo(_) => true, _ => false, } } fn is_special(&self) -> bool { match self.0 { SocketFd::Special(_) => true, _ => false, } } fn is_unix(&self) -> bool { match self.0 { SocketFd::Unix(_) => true, _ => false, } } fn is_inet(&self) -> bool { match self.0 { SocketFd::Inet(_) => true, _ => false, } } fn is_mq(&self) -> bool { match self.0 { SocketFd::Mq(_) => true, _ => false, } } } /// Check for file descriptors passed by systemd. /// /// Invoked by socket activated daemons to check for file descriptors needed by the service. /// If `unset_env` is true, the environment variables used by systemd will be cleared. pub fn receive_descriptors(unset_env: bool) -> Result> { let pid = env::var("LISTEN_PID"); let fds = env::var("LISTEN_FDS"); if unset_env { env::remove_var("LISTEN_PID"); env::remove_var("LISTEN_FDS"); env::remove_var("LISTEN_FDNAMES"); } let pid = pid?.parse::()?; let fds = fds?.parse::()?; if process::id() != pid { return Err("PID mismatch".into()); } socks_from_fds(fds) } /// Check for named file descriptors passed by systemd. /// /// Like `sd_listen_fds`, but this will also return a vector of names associated with each file /// descriptor. pub fn receive_descriptors_with_names(unset_env: bool) -> Result> { let pid = env::var("LISTEN_PID"); let fds = env::var("LISTEN_FDS"); let names = env::var("LISTEN_FDNAMES"); if unset_env { env::remove_var("LISTEN_PID"); env::remove_var("LISTEN_FDS"); env::remove_var("LISTEN_FDNAMES"); } let pid = pid?.parse::()?; let fds = fds?.parse::()?; if process::id() != pid { return Err("PID mismatch".into()); } let names: Vec = names?.split(':').map(String::from).collect(); let vec = socks_from_fds(fds)?; let out = vec.into_iter().zip(names.into_iter()).collect(); Ok(out) } fn socks_from_fds(num_fds: usize) -> Result> { use error_chain::bail; let mut descriptors = Vec::with_capacity(num_fds); for fd_offset in 0..num_fds { let fd = SD_LISTEN_FDS_START + (fd_offset as i32); match FileDescriptor::try_from(fd) { Ok(sock) => descriptors.push(sock), Err(e) => bail!("failed to receive file descriptor {}: {}", fd_offset, e), }; } Ok(descriptors) } impl IsType for RawFd { fn is_fifo(&self) -> bool { match fstat(*self) { Ok(stat) => (stat.st_mode & 0o0_170_000) == 0o010_000, Err(_) => false, } } fn is_special(&self) -> bool { match fstat(*self) { Ok(stat) => (stat.st_mode & 0o0_170_000) == 0o100_000, Err(_) => false, } } fn is_inet(&self) -> bool { match getsockname(*self) { Ok(addr) => { if let SockAddr::Inet(_) = addr { true } else { false } } Err(_) => false, } } fn is_unix(&self) -> bool { match getsockname(*self) { Ok(addr) => { if let SockAddr::Unix(_) = addr { true } else { false } } Err(_) => false, } } fn is_mq(&self) -> bool { mq_getattr(*self).is_ok() } } impl TryFrom for FileDescriptor { type Error = Error; fn try_from(value: RawFd) -> Result { if value.is_fifo() { return Ok(FileDescriptor(SocketFd::Fifo(value))); } else if value.is_special() { return Ok(FileDescriptor(SocketFd::Special(value))); } else if value.is_inet() { return Ok(FileDescriptor(SocketFd::Inet(value))); } else if value.is_unix() { return Ok(FileDescriptor(SocketFd::Unix(value))); } else if value.is_mq() { return Ok(FileDescriptor(SocketFd::Mq(value))); } Err("invalid file descriptor".into()) } } impl IntoRawFd for FileDescriptor { fn into_raw_fd(self) -> RawFd { match self.0 { SocketFd::Fifo(fd) => fd, SocketFd::Special(fd) => fd, SocketFd::Inet(fd) => fd, SocketFd::Unix(fd) => fd, SocketFd::Mq(fd) => fd, } } } #[cfg(test)] mod tests { use super::*; #[test] fn test_socketype_is_unix() { let sock = FileDescriptor(SocketFd::Unix(0i32)); assert!(sock.is_unix()); } #[test] fn test_socketype_is_special() { let sock = FileDescriptor(SocketFd::Special(0i32)); assert!(sock.is_special()); } #[test] fn test_socketype_is_inet() { let sock = FileDescriptor(SocketFd::Inet(0i32)); assert!(sock.is_inet()); } #[test] fn test_socketype_is_fifo() { let sock = FileDescriptor(SocketFd::Fifo(0i32)); assert!(sock.is_fifo()); } #[test] fn test_socketype_is_mq() { let sock = FileDescriptor(SocketFd::Mq(0i32)); assert!(sock.is_mq()); } } libsystemd-0.2.1/src/daemon.rs010064400017500001750000000105031364605767200145310ustar0000000000000000use error_chain::bail; use libc::pid_t; use nix::unistd; use std::os::unix::net::UnixDatagram; use std::{env, fmt, fs, path, time}; use crate::errors::*; /// Check for systemd presence at runtime. /// /// Return true if the system was booted with systemd. /// This check is based on the presence of the systemd /// runtime directory. pub fn booted() -> bool { fs::symlink_metadata("/run/systemd/system") .map(|p| p.is_dir()) .unwrap_or(false) } /// Check for watchdog support at runtime. /// /// Return a timeout before which the watchdog expects a /// response from the process, or `None` if watchdog support is /// not enabled. If `unset_env` is true, environment will be cleared. pub fn watchdog_enabled(unset_env: bool) -> Option { let env_usec = env::var("WATCHDOG_USEC").ok(); let env_pid = env::var("WATCHDOG_PID").ok(); if unset_env { env::remove_var("WATCHDOG_USEC"); env::remove_var("WATCHDOG_PID"); }; let timeout = { if let Some(usec) = env_usec.and_then(|usec_str| usec_str.parse::().ok()) { time::Duration::from_millis(usec / 1_000) } else { return None; } }; let pid = { if let Some(pid_str) = env_pid { if let Ok(p) = pid_str.parse::() { unistd::Pid::from_raw(p) } else { return None; } } else { return Some(timeout); } }; if unistd::getpid() == pid { Some(timeout) } else { None } } /// Notify service manager about status changes. /// /// Send a notification to the manager about service status changes. /// The returned boolean show whether notifications are supported for /// this service. If `unset_env` is true, environment will be cleared /// and no further notifications are possible. pub fn notify(unset_env: bool, state: &[NotifyState]) -> Result { let env_sock = env::var("NOTIFY_SOCKET").ok(); if unset_env { env::remove_var("NOTIFY_SOCKET"); }; let path = { if let Some(p) = env_sock.map(path::PathBuf::from) { p } else { return Ok(false); } }; let sock = UnixDatagram::unbound()?; let msg = state .iter() .fold(String::new(), |res, s| res + &format!("{}\n", s)); let msg_len = msg.len(); let sent_len = sock.send_to(msg.as_bytes(), path)?; if sent_len != msg_len { bail!("incomplete write, sent {} out of {}", sent_len, msg_len); } Ok(true) } #[derive(Clone, Debug, PartialEq, Eq, Hash)] /// Status changes, see `sd_notify(3)`. pub enum NotifyState { /// D-Bus error-style error code. Buserror(String), /// errno-style error code. Errno(u8), /// A name for the submitted file descriptors. Fdname(String), /// Stores additional file descriptors in the service manager. Fdstore, /// The main process ID of the service, in case of forking applications. Mainpid(unistd::Pid), /// Custom state change, as a `KEY=VALUE` string. Other(String), /// Service startup is finished. Ready, /// Service is reloading. Reloading, /// Custom status change. Status(String), /// Service is beginning to shutdown. Stopping, /// Tell the service manager to update the watchdog timestamp. Watchdog, /// Reset watchdog timeout value during runtime. WatchdogUsec(u64), } impl fmt::Display for NotifyState { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { NotifyState::Buserror(ref s) => write!(f, "BUSERROR={}", s), NotifyState::Errno(e) => write!(f, "ERRNO={}", e), NotifyState::Fdname(ref s) => write!(f, "FDNAME={}", s), NotifyState::Fdstore => write!(f, "FDSTORE=1"), NotifyState::Mainpid(ref p) => write!(f, "MAINPID={}", p), NotifyState::Other(ref s) => write!(f, "{}", s), NotifyState::Ready => write!(f, "READY=1"), NotifyState::Reloading => write!(f, "RELOADING=1"), NotifyState::Status(ref s) => write!(f, "STATUS={}", s), NotifyState::Stopping => write!(f, "STOPPING=1"), NotifyState::Watchdog => write!(f, "WATCHDOG=1"), NotifyState::WatchdogUsec(u) => write!(f, "WATCHDOG_USEC={}", u), } } } libsystemd-0.2.1/src/errors.rs010064400017500001750000000003661364607671500146070ustar0000000000000000#![allow(deprecated)] error_chain::error_chain! { foreign_links { Io(::std::io::Error); Env(::std::env::VarError); Ffi(::std::ffi::NulError); Nix(nix::Error); Parse(::std::num::ParseIntError); } } libsystemd-0.2.1/src/id128.rs010064400017500001750000000106461356477227100141230ustar0000000000000000use crate::errors::*; use error_chain::ensure; use serde::{Deserialize, Serialize}; use std::io::Read; use std::{fmt, fs}; use uuid::Uuid; /// A 128-bits ID. #[derive(Clone, Eq, PartialEq, Deserialize, Serialize)] #[serde(transparent)] pub struct Id128 { #[serde(flatten, serialize_with = "Id128::ser_uuid")] uuid_v4: Uuid, } impl Id128 { /// Build an `Id128` from a slice of bytes. pub fn try_from_slice(bytes: &[u8]) -> Result { let uuid_v4 = Uuid::from_slice(bytes) .map_err(|e| format!("failed to parse ID from bytes slice: {}", e))?; // TODO(lucab): check for v4. Ok(Self { uuid_v4 }) } /// Parse an `Id128` from string. pub fn parse_str(input: S) -> Result where S: AsRef, { let uuid_v4 = Uuid::parse_str(input.as_ref()) .map_err(|e| format!("failed to parse ID from string: {}", e))?; // TODO(lucab): check for v4. Ok(Self { uuid_v4 }) } /// Hash this ID with an application-specific ID. pub fn app_specific(&self, app: &Self) -> Result { use hmac::{Hmac, Mac}; use sha2::Sha256; let mut mac = Hmac::::new_varkey(self.uuid_v4.as_bytes()) .map_err(|_| "failed to prepare HMAC")?; mac.input(app.uuid_v4.as_bytes()); let mut hashed = mac.result().code(); ensure!(hashed.len() == 32, "short hash"); // Set version to 4. hashed[6] = (hashed[6] & 0x0F) | 0x40; // Set variant to DCE. hashed[8] = (hashed[8] & 0x3F) | 0x80; Self::try_from_slice(&hashed[..16]) } /// Return this ID as a lowercase hexadecimal string, without dashes. pub fn lower_hex(&self) -> String { let mut hex = String::new(); for byte in self.uuid_v4.as_bytes() { hex.push_str(&format!("{:02x}", byte)); } hex } /// Return this ID as a lowercase hexadecimal string, with dashes. pub fn dashed_hex(&self) -> String { format!("{}", self.uuid_v4.to_hyphenated_ref()) } /// Custom serialization (lower hex). fn ser_uuid(field: &Uuid, s: S) -> ::std::result::Result where S: ::serde::Serializer, { let mut hex = String::new(); for byte in field.as_bytes() { hex.push_str(&format!("{:02x}", byte)); } s.serialize_str(&hex) } } impl fmt::Debug for Id128 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.dashed_hex()) } } /// Return this machine unique ID. pub fn get_machine() -> Result { let mut buf = String::new(); let mut fd = fs::File::open("/etc/machine-id")?; fd.read_to_string(&mut buf)?; Id128::parse_str(buf.trim_end()) } /// Return this machine unique ID, hashed with an application-specific ID. pub fn get_machine_app_specific(app_id: &Id128) -> Result { let machine_id = get_machine()?; machine_id.app_specific(app_id) } #[cfg(test)] mod test { use super::*; #[test] fn basic_parse_str() { let input = "2e074e9b299c41a59923c51ae16f279b"; let id = Id128::parse_str(input).unwrap(); assert_eq!(id.lower_hex(), input); Id128::parse_str("").unwrap_err(); } #[test] fn basic_keyed_hash() { let input = "2e074e9b299c41a59923c51ae16f279b"; let machine_id = Id128::parse_str(input).unwrap(); assert_eq!(input, machine_id.lower_hex()); let key = "033b1b9b264441fcaa173e9e5bf35c5a"; let app_id = Id128::parse_str(key).unwrap(); assert_eq!(key, app_id.lower_hex()); let expected = "4d4a86c9c6644a479560ded5d19a30c5"; let hashed_id = Id128::parse_str(expected).unwrap(); let output = machine_id.app_specific(&app_id).unwrap(); assert_eq!(output, hashed_id); } #[test] fn basic_from_slice() { let input_str = "d86a4e9e4dca45c5bcd9846409bfa1ae"; let input = [ 0xd8, 0x6a, 0x4e, 0x9e, 0x4d, 0xca, 0x45, 0xc5, 0xbc, 0xd9, 0x84, 0x64, 0x09, 0xbf, 0xa1, 0xae, ]; let id = Id128::try_from_slice(&input).unwrap(); assert_eq!(input_str, id.lower_hex()); Id128::try_from_slice(&[]).unwrap_err(); } #[test] fn basic_debug() { let input = "0b37f793-aeb9-4d67-99e1-6e678d86781f"; let id = Id128::parse_str(input).unwrap(); assert_eq!(id.dashed_hex(), input); } } libsystemd-0.2.1/src/lib.rs010064400017500001750000000020041356601267100140200ustar0000000000000000//! A pure-Rust client library to work with systemd. //! //! It provides support to interact with systemd components available //! on modern Linux systems. This crate is entirely implemented //! in Rust, and does not require an external libsystemd dynamic library. //! //! ```rust //! use libsystemd::daemon::{self, NotifyState}; //! //! fn notify_ready() -> bool { //! if !daemon::booted() { //! println!("Not running systemd, early exit."); //! return false; //! }; //! //! let sent = daemon::notify(true, &[NotifyState::Ready]).expect("notify failed"); //! if !sent { //! println!("Notification not sent!"); //! }; //! sent //! } //! ``` /// Interfaces for socket-activated services. pub mod activation; /// Interfaces for systemd-aware daemons. pub mod daemon; /// Error handling. pub mod errors; /// Helpers for logging to systemd-journald. pub mod logging; /// Helpers for working with systemd units. pub mod unit; /// APIs for processing 128-bits IDs. pub mod id128; libsystemd-0.2.1/src/logging.rs010064400017500001750000000160411365223513200147010ustar0000000000000000use nix::fcntl::*; use nix::sys::memfd::memfd_create; use nix::sys::memfd::MemFdCreateFlag; use nix::sys::socket::{sendmsg, ControlMessage, MsgFlags, SockAddr}; use std::collections::HashMap; use std::ffi::CString; use std::fs::File; use std::io::Write; use std::os::unix::io::FromRawFd; use std::os::unix::io::{AsRawFd, IntoRawFd}; use std::os::unix::net::UnixDatagram; use crate::errors::*; /// Default path of the systemd-journald `AF_UNIX` datagram socket. pub static SD_JOURNAL_SOCK_PATH: &str = "/run/systemd/journal/socket"; /// Log priority values. /// /// See `man 3 syslog`. #[derive(Debug)] #[repr(u8)] pub enum Priority { /// System is unusable. Emergency = 0, /// Action must be taken immediately. Alert, /// Critical condition, Critical, /// Error condition. Error, /// Warning condition. Warning, /// Normal, but significant, condition. Notice, /// Informational message. Info, /// Debug message. Debug, } impl std::convert::From for u8 { fn from(p: Priority) -> Self { match p { Priority::Emergency => 0, Priority::Alert => 1, Priority::Critical => 2, Priority::Error => 3, Priority::Warning => 4, Priority::Notice => 5, Priority::Info => 6, Priority::Debug => 7, } } } #[inline(always)] fn is_valid_char(c: char) -> bool { c.is_uppercase() || c.is_numeric() || c == '_' } /// The variable name must be in uppercase and consist only of characters, /// numbers and underscores, and may not begin with an underscore. fn is_valid_field(input: &str) -> bool { if input.is_empty() { return false; } if !input.chars().all(is_valid_char) { return false; } if input.starts_with('_') { return false; } true } fn add_field_and_payload(data: &mut String, field: &str, payload: &str) { if is_valid_field(field) { let field_payload = format!("{}={}\n", field, payload); data.push_str(&field_payload); } } /// Send a message with structured properties to the journal. /// /// The PRIORITY or MESSAGE fields from the vars iterator are always ignored in favour of the priority and message arguments. pub fn journal_send( priority: Priority, msg: &str, vars: impl Iterator, ) -> Result<()> where K: AsRef, V: AsRef, { let sock = UnixDatagram::unbound()?; let mut data = String::new(); add_field_and_payload(&mut data, "PRIORITY", &(u8::from(priority)).to_string()); add_field_and_payload(&mut data, "MESSAGE", msg); for (ref k, ref v) in vars { if k.as_ref() != "PRIORITY" && k.as_ref() != "MESSAGE" { add_field_and_payload(&mut data, k.as_ref(), v.as_ref()) } } // Message sending logic: // * fast path: data within datagram body. // * slow path: data in a sealed memfd, which is sent as an FD in ancillary data. // // Maximum data size is system dependent, thus this always tries the fast path and // falls back to the slow path if the former fails with `EMSGSIZE`. let fast_res = sock.send_to(data.as_bytes(), SD_JOURNAL_SOCK_PATH); let res = match fast_res { // `EMSGSIZE` (errno code 90) means the message was too long for a UNIX socket, Err(ref err) if err.raw_os_error() == Some(90) => send_memfd_payload(sock, data.as_bytes()), r => r.map_err(|err| err.into()), }; res.chain_err(|| format!("failed to print to journal at '{}'", SD_JOURNAL_SOCK_PATH))?; Ok(()) } /// Print a message to the journal with the given priority. pub fn journal_print(priority: Priority, msg: &str) -> Result<()> { let map: HashMap<&str, &str> = HashMap::new(); journal_send(priority, msg, map.iter()) } /// Send an overlarge payload to systemd-journald socket. /// /// This is a slow-path for sending a large payload that could not otherwise fit /// in a UNIX datagram. Payload is thus written to a memfd, which is sent as ancillary /// data. fn send_memfd_payload(sock: UnixDatagram, data: &[u8]) -> Result { let memfd = { let tmpfd = memfd_create( &CString::new("libsystemd-rs-logging")?, MemFdCreateFlag::MFD_ALLOW_SEALING, )?; // SAFETY: `memfd_create` just returned this FD. let mut file = unsafe { File::from_raw_fd(tmpfd) }; file.write_all(data)?; file.into_raw_fd() }; // Seal the memfd, so that journald knows it can safely mmap/read it. fcntl(memfd, FcntlArg::F_ADD_SEALS(SealFlag::all()))?; let fds = &[memfd]; let ancillary = [ControlMessage::ScmRights(fds)]; let path = SockAddr::new_unix(SD_JOURNAL_SOCK_PATH)?; sendmsg( sock.as_raw_fd(), &[], &ancillary, MsgFlags::empty(), Some(&path), )?; Ok(data.len()) } #[cfg(test)] mod tests { use super::*; fn ensure_journald_socket() -> bool { match std::fs::metadata(SD_JOURNAL_SOCK_PATH) { Ok(_) => true, Err(_) => { eprintln!( "skipped, journald socket not found at '{}'", SD_JOURNAL_SOCK_PATH ); false } } } #[test] fn test_journal_print_simple() { if !ensure_journald_socket() { return; } journal_print(Priority::Info, "TEST LOG!").unwrap(); } #[test] fn test_journal_print_large_buffer() { if !ensure_journald_socket() { return; } let data = "A".repeat(212995); journal_print(Priority::Debug, &data).unwrap(); } #[test] fn test_journal_send_simple() { if !ensure_journald_socket() { return; } let mut map: HashMap<&str, &str> = HashMap::new(); map.insert("TEST_JOURNALD_LOG1", "foo"); map.insert("TEST_JOURNALD_LOG2", "bar"); journal_send(Priority::Info, "Test Journald Log", map.iter()).unwrap() } #[test] fn test_journal_skip_fields() { if !ensure_journald_socket() { return; } let mut map: HashMap<&str, &str> = HashMap::new(); let priority = format!("{}", u8::from(Priority::Warning)); map.insert("TEST_JOURNALD_LOG3", "result"); map.insert("PRIORITY", &priority); map.insert("MESSAGE", "Duplicate value"); journal_send(Priority::Info, "Test Skip Fields", map.iter()).unwrap() } #[test] fn test_is_valid_field_lowercase_invalid() { let field = "test"; assert_eq!(is_valid_field(&field), false); } #[test] fn test_is_valid_field_uppercase_valid() { let field = "TEST"; assert_eq!(is_valid_field(&field), true); } #[test] fn test_is_valid_field_uppercase_non_alpha_invalid() { let field = "TE!ST"; assert_eq!(is_valid_field(&field), false); } #[test] fn test_is_valid_field_uppercase_leading_underscore_invalid() { let field = "_TEST"; assert_eq!(is_valid_field(&field), false); } } libsystemd-0.2.1/src/unit.rs010064400017500001750000000072031364607671500142470ustar0000000000000000/// Unit name escaping, like `systemd-escape`. pub fn escape_name(name: &str) -> String { if name.is_empty() { return "".to_string(); } let parts: Vec = name .bytes() .enumerate() .map(|(n, b)| escape_byte(b, n)) .collect(); parts.join("") } /// Path escaping, like `systemd-escape --path`. pub fn escape_path(name: &str) -> String { let trimmed = name.trim_matches('/'); if trimmed.is_empty() { return "-".to_string(); } let mut slash_seq = false; let parts: Vec = trimmed .bytes() .filter(|b| { let is_slash = *b == b'/'; let res = !(is_slash && slash_seq); slash_seq = is_slash; res }) .enumerate() .map(|(n, b)| escape_byte(b, n)) .collect(); parts.join("") } fn escape_byte(b: u8, index: usize) -> String { let c = char::from(b); match c { '/' => '-'.to_string(), ':' | '_' | '0'..='9' | 'a'..='z' | 'A'..='Z' => c.to_string(), '.' if index > 0 => c.to_string(), _ => format!(r#"\x{:02x}"#, b), } } #[cfg(test)] mod test { use crate::unit::*; use quickcheck::quickcheck; quickcheck! { fn test_byte_escape_length(xs: u8, n: usize) -> bool { let out = escape_byte(xs, n); out.len() == 1 || out.len() == 4 } } #[test] fn test_name_escape() { let cases = vec![ // leave empty string empty (r#""#, r#""#), // escape leading dot (r#".foo/.bar"#, r#"\x2efoo-.bar"#), // escape disallowed (r#"///..\-!#??///"#, r#"---..\x5c\x2d\x21\x23\x3f\x3f---"#), // escape real-world example ( r#"user-cloudinit@/var/lib/coreos/vagrant/vagrantfile-user-data.service"#, r#"user\x2dcloudinit\x40-var-lib-coreos-vagrant-vagrantfile\x2duser\x2ddata.service"#, ), ]; for t in cases { let res = escape_name(t.0); assert_eq!(res, t.1.to_string()); } } #[test] fn test_path_escape() { let cases = vec![ // turn empty string path into escaped / (r#""#, r#"-"#), // turn redundant ////s into single escaped / (r#"/////////"#, r#"-"#), // remove all redundant ////s (r#"///foo////bar/////tail//////"#, r#"foo-bar-tail"#), // escape leading dot (r#"."#, r#"\x2e"#), (r#"/."#, r#"\x2e"#), (r#"/////////.///////////////"#, r#"\x2e"#), (r#"....."#, r#"\x2e...."#), (r#"/.foo/.bar"#, r#"\x2efoo-.bar"#), (r#".foo/.bar"#, r#"\x2efoo-.bar"#), // escape disallowed (r#"///..\-!#??///"#, r#"\x2e.\x5c\x2d\x21\x23\x3f\x3f"#), ]; for t in cases { let res = escape_path(t.0); assert_eq!(res, t.1.to_string()); } } quickcheck! { fn test_path_escape_nonempty(xs: String) -> bool { let out = escape_path(&xs); !out.is_empty() } } quickcheck! { fn test_path_escape_no_slash(xs: String) -> bool { let out = escape_path(&xs); !out.contains('/') } } quickcheck! { fn test_path_escape_no_dash_runs(xs: String) -> bool { let out = escape_path(&xs); !out.contains("--") } } quickcheck! { fn test_path_escape_no_leading_dot(xs: String) -> bool { let out = escape_path(&xs); !out.starts_with('.') } } }