diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 13db518..8751337 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,124 +10,80 @@ name: build jobs: check: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@beta with: - profile: minimal - toolchain: beta - override: true components: rustfmt, clippy - - - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v1 - + - uses: Swatinem/rust-cache@v2 - name: apt-get update run: sudo apt-get -o Acquire::Retries=3 update - name: Install libsystemd-dev run: sudo apt-get -o Acquire::Retries=3 install libsystemd-dev + - run: cargo fmt --all -- --check + - run: cargo clippy --all --all-targets --features serde,default,bus,systemd_v245,journal -- -D warnings - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings features: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: beta - override: true - - - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v1 - + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@beta + - uses: Swatinem/rust-cache@v2 + - uses: taiki-e/install-action@cargo-hack - name: apt-get update run: sudo apt-get -o Acquire::Retries=3 update - name: Install libsystemd-dev run: sudo apt-get -o Acquire::Retries=3 install libsystemd-dev - - - name: Install cargo-hack - uses: actions-rs/cargo@v1 - with: - command: install - args: cargo-hack - - name: Check with all variants - uses: actions-rs/cargo@v1 - with: - command: hack - args: --feature-powerset --skip unstable-doc-cfg check --workspace --all-targets + run: cargo hack --feature-powerset --skip unstable-doc-cfg check --workspace --all-targets test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: matrix: rust: - stable - beta - nightly - - 1.47.0 steps: - - uses: actions/checkout@v2 - - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: ${{ matrix.rust }} - override: true - - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v1 - + uses: Swatinem/rust-cache@v2 - name: apt-get update run: sudo apt-get -o Acquire::Retries=3 update - name: Install libsystemd-dev run: sudo apt-get -o Acquire::Retries=3 install libsystemd-dev - - - name: Install cargo-hack - uses: actions-rs/cargo@v1 - with: - command: install - args: cargo-hack - + - uses: taiki-e/install-action@cargo-hack - name: Build everything - uses: actions-rs/cargo@v1 - if: ${{matrix.rust != 'nightly' }} - with: - command: hack - args: --feature-powerset --skip unstable-doc-cfg build --all --all-targets + run: cargo hack --feature-powerset --skip unstable-doc-cfg build --all --all-targets + if: matrix.rust != 'nightly' - name: Run all tests - uses: actions-rs/cargo@v1 - if: ${{matrix.rust != 'nightly' }} - with: - command: hack - args: --feature-powerset --skip unstable-doc-cfg test --all + run: cargo hack --feature-powerset --skip unstable-doc-cfg test --all + if: matrix.rust != 'nightly' - name: Build everything - uses: actions-rs/cargo@v1 - if: ${{matrix.rust == 'nightly' }} - with: - command: hack - args: --feature-powerset build --all --all-targets + run: cargo hack --feature-powerset build --all --all-targets + if: matrix.rust == 'nightly' - name: Run all tests - uses: actions-rs/cargo@v1 - if: ${{matrix.rust == 'nightly' }} - with: - command: hack - args: --feature-powerset test --all + run: cargo hack --feature-powerset test --all + if: matrix.rust == 'nightly' +# msrv: +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v4 +# - name: apt-get update +# run: sudo apt-get -o Acquire::Retries=3 update +# - name: Install libsystemd-dev +# run: sudo apt-get -o Acquire::Retries=3 install libsystemd-dev +# - uses: taiki-e/install-action@cargo-hack +# - uses: Swatinem/rust-cache@v2 +# - run: cargo hack check --rust-version --workspace --all-targets --ignore-private diff --git a/Cargo.lock b/Cargo.lock index 99ccb0e..0946d79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,11 +2,20 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "bitflags" -version = "1.3.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "build-env" @@ -36,6 +45,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "foreign-types" version = "0.5.0" @@ -48,9 +63,9 @@ dependencies = [ [[package]] name = "foreign-types-macros" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63f713f8b2aa9e24fec85b0e290c56caee12e3b6ae0aeeda238a75b28251afd6" +checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", @@ -59,93 +74,99 @@ dependencies = [ [[package]] name = "foreign-types-shared" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7684cf33bb7f28497939e8c7cf17e3e4e3b8d9a0080ffa4f8ae2f515442ee855" +checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" [[package]] name = "form_urlencoded" -version = "1.0.1" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ - "matches", "percent-encoding", ] +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + [[package]] name = "idna" -version = "0.2.3" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "matches", "unicode-bidi", "unicode-normalization", ] +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "libc" -version = "0.2.112" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "libsystemd-sys" version = "0.9.3" dependencies = [ "build-env", + "cfg-if", "libc", "pkg-config", ] [[package]] name = "log" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "matches" -version = "0.1.9" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" -version = "2.4.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pkg-config" -version = "0.3.24" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "proc-macro2" -version = "1.0.33" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb37d2df5df740e582f28f8560cf425f52bb267d872fe58358eadb554909f07a" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "pulldown-cmark" -version = "0.8.0" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" +checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b" dependencies = [ "bitflags", "memchr", @@ -154,49 +175,86 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.10" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] [[package]] name = "regex" -version = "1.5.4" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] -name = "semver-parser" -version = "0.9.0" +name = "semver" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b46e1121e8180c12ff69a742aabc4f310542b6ccb69f1691689ac17fdf8618aa" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "serde" -version = "1.0.131" +version = "1.0.200" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.200" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ad69dfbd3e45369132cc64e6748c2d65cdfb001a2b1c232d128b4ad60561c1" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] [[package]] name = "syn" -version = "1.0.82" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -217,67 +275,91 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" dependencies = [ "tinyvec_macros", ] [[package]] name = "tinyvec_macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "toml" -version = "0.5.8" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "unicase" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" dependencies = [ "version_check", ] [[package]] name = "unicode-bidi" -version = "0.3.7" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.19" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - [[package]] name = "url" -version = "2.2.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", "idna", - "matches", "percent-encoding", ] @@ -289,14 +371,14 @@ checksum = "55bcbb425141152b10d5693095950b51c3745d019363fc2929ffd8f61449b628" [[package]] name = "version-sync" -version = "0.9.3" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a3e43f07cfb6ad1a7f6fedaf1144e59750b728c04a24a053035379b2e4584d" +checksum = "835169da0173ea373ddf5987632aac1f918967fbbe58195e304342282efa6089" dependencies = [ "proc-macro2", "pulldown-cmark", "regex", - "semver-parser", + "semver", "syn", "toml", "url", @@ -304,6 +386,15 @@ dependencies = [ [[package]] name = "version_check" -version = "0.9.3" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "winnow" +version = "0.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml index f18b4da..58f42eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.10.0" authors = ["Cody P Schafer "] license = "LGPL-2.1-or-later WITH GCC-exception-2.0" description = "A rust interface to libsystemd/libelogind provided APIs" -repository = "https://github.com/jmesmon/rust-systemd" +repository = "https://github.com/codyps/rust-systemd" documentation = "https://docs.rs/crate/systemd" include = ["Cargo.toml", "src/**/*.rs", "COPYING", "README.md"] readme = "README.md" @@ -21,7 +21,7 @@ unstable-doc-cfg = [] [dependencies] log = "~0.4" libc = "~0.2" -memchr = "2.4.0" +memchr = "2" utf8-cstr = "~0.1" cstr-argument = "~0.1" foreign-types = "0.5.0" diff --git a/README.md b/README.md index e003e91..3dd4a5b 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,12 @@ rust-systemd ============ [crate docs (systemd)](http://docs.rs/crate/systemd) + [crate docs (libsystemd-sys)](http://docs.rs/crate/libsystemd-sys) -[![Crates.io](https://img.shields.io/crates/v/systemd.svg?maxAge=2592000)](https://crates.io/crates/systemd) -[![Build Status](https://travis-ci.org/jmesmon/rust-systemd.svg?branch=master)](https://travis-ci.org/jmesmon/rust-systemd) + +[systemd![Crates.io](https://img.shields.io/crates/v/systemd.svg?maxAge=2592000)](https://crates.io/crates/systemd) + +[libsystemd-sys![Crates.io](https://img.shields.io/crates/v/libsystemd-sys.svg?maxAge=2592000)](https://crates.io/crates/libsystemd-sys) In `Cargo.toml`: diff --git a/bors.toml b/bors.toml deleted file mode 100644 index 6d67764..0000000 --- a/bors.toml +++ /dev/null @@ -1,9 +0,0 @@ -status = [ - "test (stable)", - "test (beta)", - "test (1.47.0)", - "check", - "features", -] -cut_body_after = "---" -delete_merged_branches = true diff --git a/examples/systemd-start-service.rs b/examples/systemd-start-service.rs index 953073d..b8a70a1 100644 --- a/examples/systemd-start-service.rs +++ b/examples/systemd-start-service.rs @@ -2,11 +2,11 @@ // WARNING: you may want to use a more tested/complete dbus library, or one that is pure rust. // `zbus` may be a reasonable choice, and there are others too -use utf8_cstr::Utf8CStr; // approximately this command: // busctl --system call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager StartUnit "ss" "foo.service" "fail" #[cfg(feature = "bus")] fn main() { + use utf8_cstr::Utf8CStr; let mut bus = systemd::bus::Bus::default_system().unwrap(); let mut method_call = bus diff --git a/libsystemd-sys/Cargo.toml b/libsystemd-sys/Cargo.toml index fcefbc0..39640e3 100644 --- a/libsystemd-sys/Cargo.toml +++ b/libsystemd-sys/Cargo.toml @@ -4,14 +4,12 @@ version = "0.9.3" authors = ["Cody P Schafer "] license = "LGPL-2.1-or-later WITH GCC-exception-2.0" description = "FFI bindings to libsystemd and libelogind" -repository = "https://github.com/jmesmon/rust-systemd" +repository = "https://github.com/codyps/rust-systemd" include = ["Cargo.toml", "**/*.rs", "build.rs", "COPYING", "README.md"] readme = "README.md" documentation = "https://docs.rs/crates/libsystemd-sys" edition = "2018" -build = "build.rs" - [features] default = ["bus", "journal"] @@ -20,6 +18,7 @@ journal = [] systemd_v245 = [] [dependencies] +cfg-if = "1.0.0" libc = "0.2.76" [build-dependencies] diff --git a/libsystemd-sys/src/bus/vtable.rs b/libsystemd-sys/src/bus/vtable.rs index c03977a..e986fae 100644 --- a/libsystemd-sys/src/bus/vtable.rs +++ b/libsystemd-sys/src/bus/vtable.rs @@ -1,7 +1,6 @@ use super::super::{c_char, size_t}; use super::{sd_bus_message_handler_t, sd_bus_property_get_t, sd_bus_property_set_t}; -use std::default::Default; -use std::mem::{transmute, zeroed}; +use cfg_if::cfg_if; // XXX: check this repr, might vary based on platform type sizes #[derive(Clone, Copy, Debug)] @@ -30,7 +29,7 @@ pub enum SdBusVtableFlag { CapabilityMask = 0xFFFF << 40, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] #[repr(C)] pub struct sd_bus_vtable { type_and_flags: u64, @@ -38,53 +37,55 @@ pub struct sd_bus_vtable { union_data: [usize; 5], } -impl Default for sd_bus_vtable { - fn default() -> Self { - unsafe { zeroed() } - } -} - +// FIXME: all this nasty `target_endian` stuff is because we don't have an abstraction for +// bitfields. `c2rust-bitfields` only supports little endian. None of the other bitfield crates +// claim compatibility with C (which is what we require here). impl sd_bus_vtable { - pub fn type_and_flags(typ: u32, flags: u64) -> u64 { - let mut val = [0u8; 8]; - assert!(typ <= ((1 << 8) - 1)); + pub fn type_and_flags(typ: u8, flags: u64) -> u64 { assert!(flags <= ((1 << 56) - 1)); - val[0] = typ as u8; - let flags_raw = flags.to_ne_bytes(); - val[1..(7 + 1)].clone_from_slice(&flags_raw[..7]); - - unsafe { transmute(val) } + cfg_if! { + if #[cfg(target_endian = "little")] { + (flags << 8) | typ as u64 + } else if #[cfg(target_endian = "big")] { + (typ as u64) | (flags << 8) + } else { + compile_error!("unsupported target_endian") + } + } } - // type & flags are stored in a bit field, the ordering of which might change depending on the - // platform. - // - pub fn typ(&self) -> u32 { - unsafe { - let raw: *const u8 = &self.type_and_flags as *const _ as *const u8; - *raw as u32 + pub fn typ(&self) -> u8 { + cfg_if! { + if #[cfg(target_endian = "little")] { + (self.type_and_flags & 0xFF) as u8 + } else if #[cfg(target_endian = "big")] { + (self.type_and_flags >> 56) as u8 + } else { + compile_error!("unsupported target_endian") + } } } pub fn flags(&self) -> u64 { - // treat the first byte as 0 and the next 7 as their actual values - let mut val = [0u8; 8]; - unsafe { - let raw: *const u8 = transmute(&self.type_and_flags); - for i in 1..8 { - val[i - 1] = *raw.add(i); + cfg_if! { + if #[cfg(target_endian = "little")] { + self.type_and_flags >> 8 + } else if #[cfg(target_endian = "big")] { + self.type_and_flags & 0xFFFFFFFFFFFFFF + } else { + compile_error!("unsupported target_endian") } - transmute(val) } } } #[test] fn vtable_bitfield() { - let mut b: sd_bus_vtable = Default::default(); - - b.type_and_flags = sd_bus_vtable::type_and_flags(0xAA, 0xBBCCBB); + let b: sd_bus_vtable = sd_bus_vtable { + type_and_flags: sd_bus_vtable::type_and_flags(0xAA, 0xBBCCBB), + ..Default::default() + }; assert_eq!(b.typ(), 0xAA); assert_eq!(b.flags(), 0xBBCCBB); diff --git a/src/bus/mod.rs b/src/bus/mod.rs index f0e14e0..6165f21 100644 --- a/src/bus/mod.rs +++ b/src/bus/mod.rs @@ -814,7 +814,7 @@ impl fmt::Display for RawError { fn t_raw_error() { let name = Utf8CStr::from_bytes(b"name\0").unwrap(); let message = Utf8CStr::from_bytes(b"error\0").unwrap(); - let _raw = RawError::new().set(name, Some(message)); + RawError::new().set(name, Some(message)) } /* XXX: fixme: return code does have meaning! */ @@ -861,6 +861,9 @@ foreign_type! { } impl Bus { + // TODO: consider renaming all these methods so we don't have this one named `default()`, which + // confuses things with std::default::Default::default. + #[allow(clippy::should_implement_trait)] #[inline] pub fn default() -> crate::Result { let mut b = MaybeUninit::uninit(); @@ -1022,7 +1025,7 @@ impl BusRef { pub fn wait(&mut self, timeout: Option) -> super::Result { Ok(sd_try!(ffi::bus::sd_bus_wait( self.as_ptr(), - timeout.map(usec_from_duration).unwrap_or(std::u64::MAX) + timeout.map(usec_from_duration).unwrap_or(u64::MAX) )) > 0) } @@ -1153,10 +1156,10 @@ impl BusRef { sd_try!(ffi::bus::sd_bus_message_new_method_call( self.as_ptr(), m.as_mut_ptr(), - &*dest as *const _ as *const _, - &*path as *const _ as *const _, - &*interface as *const _ as *const _, - &*member as *const _ as *const _ + dest as *const _ as *const _, + path as *const _ as *const _, + interface as *const _ as *const _, + member as *const _ as *const _ )); let m = unsafe { m.assume_init() }; Ok(unsafe { Message::from_ptr(m) }) @@ -1175,7 +1178,7 @@ impl BusRef { pub fn request_name(&mut self, name: &BusName, flags: u64) -> super::Result<()> { sd_try!(ffi::bus::sd_bus_request_name( self.as_ptr(), - &*name as *const _ as *const _, + name as *const _ as *const _, flags )); Ok(()) @@ -1203,7 +1206,7 @@ impl BusRef { crate::ffi_result(ffi::bus::sd_bus_request_name_async( self.as_ptr(), &mut slot, - &*name as *const _ as *const _, + name as *const _ as *const _, flags, Some(f), b as *mut c_void, @@ -1211,7 +1214,7 @@ impl BusRef { } { Err(e) => { // try not to leak - unsafe { Box::from_raw(b) }; + let _ = unsafe { Box::from_raw(b) }; Err(e) } Ok(_) => { @@ -1230,7 +1233,7 @@ impl BusRef { pub fn release_name(&self, name: &BusName) -> super::Result<()> { sd_try!(ffi::bus::sd_bus_release_name( self.as_ptr(), - &*name as *const _ as *const _ + name as *const _ as *const _ )); Ok(()) } @@ -1255,13 +1258,13 @@ impl BusRef { ffi::bus::sd_bus_add_object( self.as_ptr(), &mut slot, - &*path as *const _ as *const _, + path as *const _ as *const _, Some(f), b as *mut c_void, ) }) { Err(e) => { - unsafe { Box::from_raw(b) }; + let _ = unsafe { Box::from_raw(b) }; Err(e) } Ok(_) => { @@ -1279,7 +1282,7 @@ impl BusRef { sd_try!(ffi::bus::sd_bus_add_object_manager( self.as_ptr(), ptr::null_mut(), - &*path as *const _ as *const _ + path as *const _ as *const _ )); Ok(()) } @@ -1402,7 +1405,7 @@ impl MessageRef { pub fn set_destination(&mut self, dest: &BusName) -> super::Result<()> { sd_try!(ffi::bus::sd_bus_message_set_destination( self.as_ptr(), - &*dest as *const _ as *const _ + dest as *const _ as *const _ )); Ok(()) } @@ -1641,7 +1644,7 @@ impl MessageRef { sd_try!(ffi::bus::sd_bus_send_to( ptr::null_mut(), self.as_ptr(), - &*dest as *const _ as *const _, + dest as *const _ as *const _, c.as_mut_ptr() )); let c = unsafe { c.assume_init() }; @@ -1661,7 +1664,7 @@ impl MessageRef { sd_try!(ffi::bus::sd_bus_send_to( ptr::null_mut(), self.as_ptr(), - &*dest as *const _ as *const _, + dest as *const _ as *const _, ptr::null_mut() )); Ok(()) @@ -1731,7 +1734,7 @@ impl MessageRef { }) { Err(e) => { // try not to leak - unsafe { Box::from_raw(b) }; + let _ = unsafe { Box::from_raw(b) }; Err(e) } Ok(_) => { diff --git a/src/daemon.rs b/src/daemon.rs index 2f0b8e1..588a1c9 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -204,7 +204,7 @@ pub fn is_socket_inet( let c_family = family.unwrap_or(0) as c_int; let c_socktype = get_c_socktype(socktype); let c_listening = get_c_listening(listening); - let c_port = port.unwrap_or(0) as u16; + let c_port = port.unwrap_or(0); let result = sd_try!(ffi::sd_is_socket_inet( fd, @@ -289,7 +289,7 @@ where { let mut state_vec = Vec::new(); for (key, value) in state { - state_vec.push(vec![key.as_ref(), value.as_ref()].join("=")); + state_vec.push([key.as_ref(), value.as_ref()].join("=")); } let state_str = state_vec.join("\n"); ::std::ffi::CString::new(state_str.as_bytes()).unwrap() diff --git a/src/journal.rs b/src/journal.rs index e984eca..aa4835e 100644 --- a/src/journal.rs +++ b/src/journal.rs @@ -408,7 +408,7 @@ impl OpenOptions { /// /// `sd_journal_open()`: https://www.freedesktop.org/software/systemd/man/sd_journal_open.html pub fn open(&self) -> Result { - Journal::open_with_opts::<&std::ffi::CStr>(self) + Journal::open_with_opts(self) } /// Open the log journal for reading in the given namespace. Entries included are dependent on @@ -522,7 +522,7 @@ impl OpenFilesOptions { } impl Journal { - fn open_with_opts(opts: &OpenOptions) -> Result { + fn open_with_opts(opts: &OpenOptions) -> Result { let mut flags = opts.extra_raw_flags; if opts.current_user { flags |= ffi::SD_JOURNAL_CURRENT_USER; diff --git a/tests/journal.rs b/tests/journal.rs index 272db5a..7139784 100644 --- a/tests/journal.rs +++ b/tests/journal.rs @@ -55,7 +55,7 @@ fn ts() { } let mut j = journal::OpenOptions::default().open().unwrap(); - log!(log::Level::Info, "rust-systemd test_seek entry"); + log!(log::Level::Info, "rust-systemd ts entry"); j.seek(journal::JournalSeek::Head).unwrap(); j.next().unwrap(); let _s = j.timestamp().unwrap(); @@ -81,13 +81,16 @@ fn test_seek() { let c1 = j.cursor().unwrap(); let c2 = j.cursor().unwrap(); assert_eq!(c1, c2); + j.seek(journal::JournalSeek::Tail).unwrap(); + // NOTE: depending on the libsystemd version we may or may not be able to read an entry + // following the "Tail", so ignore it. j.next_entry().unwrap(); - let c3 = j.cursor().unwrap(); - let valid_cursor = journal::JournalSeek::Cursor { cursor: c3 }; + + let valid_cursor = journal::JournalSeek::Cursor { cursor: c1 }; j.seek(valid_cursor).unwrap(); let invalid_cursor = journal::JournalSeek::Cursor { - cursor: "".to_string(), + cursor: "invalid".to_string(), }; assert!(j.seek(invalid_cursor).is_err()); } @@ -107,8 +110,10 @@ fn test_simple_match() { // seek tail j.seek(journal::JournalSeek::Tail).unwrap(); - journal::send(&[&filter, msg]); + j.previous().unwrap(); j.match_add(key, value).unwrap(); + + journal::send(&[&filter, msg]); let mut waits = 0; loop { if j.next().unwrap() == 0 { @@ -134,6 +139,7 @@ fn test_simple_match() { // check for negative matches j.seek(journal::JournalSeek::Tail).unwrap(); + j.previous().unwrap(); j.match_flush() .unwrap() .match_add("NOKEY", "NOVALUE")