-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
243: systemd/bus: provide an example and mark some Message fields optional r=jmesmon a=jmesmon Resolves #242 Co-authored-by: Cody P Schafer <[email protected]>
- Loading branch information
Showing
3 changed files
with
59 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#![warn(rust_2018_idioms)] | ||
// 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() { | ||
let mut bus = systemd::bus::Bus::default_system().unwrap(); | ||
|
||
let mut method_call = bus | ||
.new_method_call( | ||
systemd::bus::BusName::from_bytes(b"org.freedesktop.systemd1\0").unwrap(), | ||
systemd::bus::ObjectPath::from_bytes(b"/org/freedesktop/systemd1\0").unwrap(), | ||
systemd::bus::InterfaceName::from_bytes(b"org.freedesktop.systemd1.Manager\0").unwrap(), | ||
systemd::bus::MemberName::from_bytes(b"StartUnit\0").unwrap(), | ||
) | ||
.unwrap(); | ||
|
||
// args | ||
method_call | ||
.append(Utf8CStr::from_bytes(b"foo.service\0").unwrap()) | ||
.unwrap(); | ||
method_call | ||
.append(Utf8CStr::from_bytes(b"fail\0").unwrap()) | ||
.unwrap(); | ||
|
||
let res = method_call.call(0).unwrap(); | ||
|
||
eprintln!("done, result={:?}", *res); | ||
} | ||
|
||
#[cfg(not(feature = "bus"))] | ||
fn main() { | ||
println!("bus disabled"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters