From 67a86af4d6df83666896889af8b19fc09228e947 Mon Sep 17 00:00:00 2001 From: Adam Schwalm Date: Thu, 11 Jan 2024 17:03:23 -0600 Subject: [PATCH 01/26] Fix journal cursor test failures In order to create a cursor, the journal must be at a valid entry. As the docs say: Note that sd_journal_get_cursor() will not work before sd_journal_next(3) (or related call) has been called at least once, in order to position the read pointer at a valid entry. The existing tests do this, but at least on recent versions of systemd (255), calling sd_journal_next after a seek to tail does not meet this requirement. If the journal is at the tail, subsequent nexts will always stay a the abstract 'tail' position (analogous to EOF), not at a valid entry. This causes cursor creation to fail. A similar issue exists in the 'match' test. It seeks to tail and then attempts to 'next' in a loop, but this will always be 'tail', so it never sees the matching entry. In both cases, the fix is to 'previous' after the seek to tail. --- tests/journal.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/journal.rs b/tests/journal.rs index 272db5a..a9a7c86 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,14 @@ fn test_seek() { let c1 = j.cursor().unwrap(); let c2 = j.cursor().unwrap(); assert_eq!(c1, c2); + j.seek(journal::JournalSeek::Tail).unwrap(); - j.next_entry().unwrap(); - let c3 = j.cursor().unwrap(); - let valid_cursor = journal::JournalSeek::Cursor { cursor: c3 }; + assert!(j.next_entry().unwrap().is_none()); + + 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 +108,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 +137,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") From 6bcbff3ecb02f5cf185c32bbec1fe2a3722c009a Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Sun, 28 Apr 2024 02:45:48 -0400 Subject: [PATCH 02/26] Update URLs & readme --- Cargo.toml | 2 +- README.md | 7 +++++-- libsystemd-sys/Cargo.toml | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f18b4da..2267ded 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" 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/libsystemd-sys/Cargo.toml b/libsystemd-sys/Cargo.toml index fcefbc0..eb6a0ba 100644 --- a/libsystemd-sys/Cargo.toml +++ b/libsystemd-sys/Cargo.toml @@ -4,7 +4,7 @@ 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" From 51833d44b1b698bff7a665263f21cde888471628 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:03:18 -0400 Subject: [PATCH 03/26] cargo update --- Cargo.lock | 243 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 167 insertions(+), 76 deletions(-) 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", +] From c398445b416e49ae6d204778cd477e4d18eecff0 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:03:41 -0400 Subject: [PATCH 04/26] fix warnings about unused returns from Box::from_raw() that we want to drop --- src/bus/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bus/mod.rs b/src/bus/mod.rs index f0e14e0..c0c81b0 100644 --- a/src/bus/mod.rs +++ b/src/bus/mod.rs @@ -1211,7 +1211,7 @@ impl BusRef { } { Err(e) => { // try not to leak - unsafe { Box::from_raw(b) }; + let _ = unsafe { Box::from_raw(b) }; Err(e) } Ok(_) => { @@ -1261,7 +1261,7 @@ impl BusRef { ) }) { Err(e) => { - unsafe { Box::from_raw(b) }; + let _ = unsafe { Box::from_raw(b) }; Err(e) } Ok(_) => { @@ -1731,7 +1731,7 @@ impl MessageRef { }) { Err(e) => { // try not to leak - unsafe { Box::from_raw(b) }; + let _ = unsafe { Box::from_raw(b) }; Err(e) } Ok(_) => { From 12735f4f26d8c2e5ec158d42013e608bcd153aaa Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:05:15 -0400 Subject: [PATCH 05/26] libsystemd-sys: remove unsafe code for handling bitfield, use endian specific cfg_if --- libsystemd-sys/Cargo.toml | 1 + libsystemd-sys/src/bus/vtable.rs | 62 ++++++++++++++++---------------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/libsystemd-sys/Cargo.toml b/libsystemd-sys/Cargo.toml index eb6a0ba..911ee5a 100644 --- a/libsystemd-sys/Cargo.toml +++ b/libsystemd-sys/Cargo.toml @@ -20,6 +20,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..81e2c76 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,44 +37,45 @@ 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) } } } From f0b2b139987b33dc40e225831284ae46c716ef9a Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:09:45 -0400 Subject: [PATCH 06/26] fix: remove unused let --- src/bus/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bus/mod.rs b/src/bus/mod.rs index c0c81b0..f228389 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! */ From ab9f7cc5d38aba8346b262045a796ede360a60e6 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:12:53 -0400 Subject: [PATCH 07/26] fix: remove unused generic --- src/journal.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; From b6f1f50b41bce89eb6ccbcdd180a1006826ab066 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:13:25 -0400 Subject: [PATCH 08/26] cargo clippy --fix --- src/bus/mod.rs | 24 ++++++++++++------------ src/daemon.rs | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/bus/mod.rs b/src/bus/mod.rs index f228389..f3b3c9d 100644 --- a/src/bus/mod.rs +++ b/src/bus/mod.rs @@ -1153,10 +1153,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 +1175,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 +1203,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, @@ -1230,7 +1230,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,7 +1255,7 @@ 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, ) @@ -1279,7 +1279,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 +1402,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 +1641,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 +1661,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(()) 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() From 3e8b4bb695ae152d9703d8ef905fb8a9e3d0f632 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:15:31 -0400 Subject: [PATCH 09/26] fix: suppress and fix clippy warnings --- src/bus/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bus/mod.rs b/src/bus/mod.rs index f3b3c9d..6165f21 100644 --- a/src/bus/mod.rs +++ b/src/bus/mod.rs @@ -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) } From 4246968bce2d478ad2cd802e02002e25e86e0212 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:37:42 -0400 Subject: [PATCH 10/26] bors-ng is dead, remove config --- bors.toml | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 bors.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 From 75b7806fe818e6efad7d937a60ede8c6911bf35c Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:38:03 -0400 Subject: [PATCH 11/26] Cargo.toml: loosen memchr dep --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2267ded..58f42eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" From a0b08ffee3713746a5c48fb65b5bc7131fc661a9 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:40:23 -0400 Subject: [PATCH 12/26] add rust-version/msrv and check in github --- .github/workflows/build.yml | 6 ++++++ Cargo.toml | 2 ++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 13db518..e911801 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -131,3 +131,9 @@ jobs: with: command: hack args: --feature-powerset test --all + msrv: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: taiki-e/install-action@cargo-hack + - run: cargo hack check --rust-version --workspace --all-targets --ignore-private diff --git a/Cargo.toml b/Cargo.toml index 58f42eb..409415f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ documentation = "https://docs.rs/crate/systemd" include = ["Cargo.toml", "src/**/*.rs", "COPYING", "README.md"] readme = "README.md" edition = "2018" +# Note: will require careful dependency choice to work, 1.61.0 is easier +rust-version = "1.60.0" [features] default = ["bus", "journal"] From 3115705d9a77876623c37bde112ff4b59b931976 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:43:39 -0400 Subject: [PATCH 13/26] github actions: use rust-cache@v2 --- .github/workflows/build.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e911801..c2aa6b0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: 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 @@ -52,7 +52,7 @@ jobs: 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 @@ -91,7 +91,7 @@ jobs: 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 @@ -136,4 +136,5 @@ jobs: steps: - uses: actions/checkout@v4 - uses: taiki-e/install-action@cargo-hack + - uses: Swatinem/rust-cache@v2 - run: cargo hack check --rust-version --workspace --all-targets --ignore-private From a040a756244c8528d675c03ddd618138b346f0cd Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:51:05 -0400 Subject: [PATCH 14/26] github actions: remove all actions-rs --- .github/workflows/build.yml | 86 ++++++------------------------------- 1 file changed, 14 insertions(+), 72 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c2aa6b0..91b600b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,62 +14,29 @@ jobs: steps: - uses: actions/checkout@v2 - - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: beta - override: true - components: rustfmt, clippy - - - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v2 - + - uses: dtolnay/rust-toolchain@beta + - 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 --all-features -- -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 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@v2 - + - 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 @@ -83,54 +50,29 @@ jobs: steps: - uses: actions/checkout@v2 - - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - override: true - + - uses: dtolnay/rust-toolchain@${{ matrix.rust }} - name: Cache Rust dependencies 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 + run: cargo hack --feature-powerset --skip unstable-doc-cfg build --all --all-targets if: ${{matrix.rust != 'nightly' }} - with: - command: hack - args: --feature-powerset --skip unstable-doc-cfg build --all --all-targets - name: Run all tests - uses: actions-rs/cargo@v1 + run: cargo hack --feature-powerset --skip unstable-doc-cfg test --all if: ${{matrix.rust != 'nightly' }} - with: - command: hack - args: --feature-powerset --skip unstable-doc-cfg test --all - name: Build everything - uses: actions-rs/cargo@v1 + run: cargo hack --feature-powerset build --all --all-targets if: ${{matrix.rust == 'nightly' }} - with: - command: hack - args: --feature-powerset build --all --all-targets - name: Run all tests - uses: actions-rs/cargo@v1 + run: cargo hack --feature-powerset test --all if: ${{matrix.rust == 'nightly' }} - with: - command: hack - args: --feature-powerset test --all msrv: runs-on: ubuntu-latest steps: From 908c339b01613478750506cb934f26504a977141 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:52:42 -0400 Subject: [PATCH 15/26] github actions: update ubuntu, update actions/checkout@v2 to v4 --- .github/workflows/build.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 91b600b..698253e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,10 +10,10 @@ name: build jobs: check: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@beta - uses: Swatinem/rust-cache@v2 - name: apt-get update @@ -24,10 +24,10 @@ jobs: - run: cargo clippy --all --all-targets --all-features -- -D warnings features: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@beta - uses: Swatinem/rust-cache@v2 - uses: taiki-e/install-action@cargo-hack @@ -39,7 +39,7 @@ jobs: 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: @@ -49,7 +49,7 @@ jobs: - 1.47.0 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@${{ matrix.rust }} - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 From 2ac83401f70b6599529fc7afabcc7897f2cb3eea Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 01:59:09 -0400 Subject: [PATCH 16/26] github actions: fix indent, simplify if --- .github/workflows/build.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 698253e..20fe265 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -60,23 +60,23 @@ jobs: - uses: taiki-e/install-action@cargo-hack - name: Build everything run: cargo hack --feature-powerset --skip unstable-doc-cfg build --all --all-targets - if: ${{matrix.rust != 'nightly' }} + if: matrix.rust != 'nightly' - name: Run all tests run: cargo hack --feature-powerset --skip unstable-doc-cfg test --all - if: ${{matrix.rust != 'nightly' }} + if: matrix.rust != 'nightly' - name: Build everything run: cargo hack --feature-powerset build --all --all-targets - if: ${{matrix.rust == 'nightly' }} + if: matrix.rust == 'nightly' - name: Run all tests run: cargo hack --feature-powerset test --all - if: ${{matrix.rust == 'nightly' }} + if: matrix.rust == 'nightly' msrv: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: taiki-e/install-action@cargo-hack - - uses: Swatinem/rust-cache@v2 - - run: cargo hack check --rust-version --workspace --all-targets --ignore-private + - uses: actions/checkout@v4 + - uses: taiki-e/install-action@cargo-hack + - uses: Swatinem/rust-cache@v2 + - run: cargo hack check --rust-version --workspace --all-targets --ignore-private From 2065eb983b925ce2c663be46fbefb03307a72fa5 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 02:01:25 -0400 Subject: [PATCH 17/26] github actions: ${{}} in uses referencing the matrix makes gha unhappy --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 20fe265..92d44dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,7 +50,9 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@${{ matrix.rust }} + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 - name: apt-get update From cc9eb4b9cc7e87d66b2812933a3646a091d60ef3 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 02:03:49 -0400 Subject: [PATCH 18/26] libsystemd-sys: add rust-version --- libsystemd-sys/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/libsystemd-sys/Cargo.toml b/libsystemd-sys/Cargo.toml index 911ee5a..8122c5c 100644 --- a/libsystemd-sys/Cargo.toml +++ b/libsystemd-sys/Cargo.toml @@ -9,6 +9,7 @@ include = ["Cargo.toml", "**/*.rs", "build.rs", "COPYING", "README.md"] readme = "README.md" documentation = "https://docs.rs/crates/libsystemd-sys" edition = "2018" +rust-version = "1.60.0" build = "build.rs" From 320908778962cf1e0de6ddf440836776afb5fc20 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 02:04:51 -0400 Subject: [PATCH 19/26] example: avoid warning when disabled --- examples/systemd-start-service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 96dddb6c7688ef68ec26147e43c2e856f5adff49 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 02:07:09 -0400 Subject: [PATCH 20/26] github actions: add clippy & rustfmt to check --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 92d44dd..a5faa28 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,6 +15,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@beta + with: + components: rustfmt, clippy - uses: Swatinem/rust-cache@v2 - name: apt-get update run: sudo apt-get -o Acquire::Retries=3 update From d3bee7dbcffe130ff02be04b476e2d09bfa6d877 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 02:10:14 -0400 Subject: [PATCH 21/26] fix journal test: do not rely on version specific behavior --- tests/journal.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/journal.rs b/tests/journal.rs index a9a7c86..7139784 100644 --- a/tests/journal.rs +++ b/tests/journal.rs @@ -83,7 +83,9 @@ fn test_seek() { assert_eq!(c1, c2); j.seek(journal::JournalSeek::Tail).unwrap(); - assert!(j.next_entry().unwrap().is_none()); + // 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 valid_cursor = journal::JournalSeek::Cursor { cursor: c1 }; j.seek(valid_cursor).unwrap(); From c66e0ee86347ac22c3b82b6d51b17e60faaf353d Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 02:12:27 -0400 Subject: [PATCH 22/26] fix: clippy --- libsystemd-sys/src/bus/vtable.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libsystemd-sys/src/bus/vtable.rs b/libsystemd-sys/src/bus/vtable.rs index 81e2c76..e986fae 100644 --- a/libsystemd-sys/src/bus/vtable.rs +++ b/libsystemd-sys/src/bus/vtable.rs @@ -82,9 +82,10 @@ impl sd_bus_vtable { #[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); From bd59cc3507dcdb470a3f90777621c792e854b910 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 02:13:09 -0400 Subject: [PATCH 23/26] remove old 1.47.0 target --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a5faa28..e8a2e7d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,7 +48,6 @@ jobs: - stable - beta - nightly - - 1.47.0 steps: - uses: actions/checkout@v4 From f121152fd91b8a1e252b5e8008915720db2f9182 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 02:13:59 -0400 Subject: [PATCH 24/26] github actions: install systemd for msrv --- .github/workflows/build.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e8a2e7d..e0670e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -80,6 +80,10 @@ jobs: 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 From eac5aca21866ee29d8410a062743c85be683b4f0 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 02:17:37 -0400 Subject: [PATCH 25/26] github actions: remove unstable_doc_cfg from beta build --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e0670e3..70bb407 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: - 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 --all-features -- -D warnings + - run: cargo clippy --all --all-targets --features serde,default,bus,systemd_v245,journal -- -D warnings features: runs-on: ubuntu-latest From cf790341ed73525505b64f09bf2a907a41827055 Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Thu, 2 May 2024 02:20:03 -0400 Subject: [PATCH 26/26] remove msrv, unclear we've got it right, so avoid setting --- .github/workflows/build.yml | 22 +++++++++++----------- Cargo.toml | 2 -- libsystemd-sys/Cargo.toml | 3 --- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 70bb407..8751337 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -76,14 +76,14 @@ jobs: - name: Run all tests 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 +# 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.toml b/Cargo.toml index 409415f..58f42eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,6 @@ documentation = "https://docs.rs/crate/systemd" include = ["Cargo.toml", "src/**/*.rs", "COPYING", "README.md"] readme = "README.md" edition = "2018" -# Note: will require careful dependency choice to work, 1.61.0 is easier -rust-version = "1.60.0" [features] default = ["bus", "journal"] diff --git a/libsystemd-sys/Cargo.toml b/libsystemd-sys/Cargo.toml index 8122c5c..39640e3 100644 --- a/libsystemd-sys/Cargo.toml +++ b/libsystemd-sys/Cargo.toml @@ -9,9 +9,6 @@ include = ["Cargo.toml", "**/*.rs", "build.rs", "COPYING", "README.md"] readme = "README.md" documentation = "https://docs.rs/crates/libsystemd-sys" edition = "2018" -rust-version = "1.60.0" - -build = "build.rs" [features] default = ["bus", "journal"]