Skip to content

Commit

Permalink
aardvark: only use systemd-run when systemd is available
Browse files Browse the repository at this point in the history
According to sd_booted(3) checking if /run/systemd/system exists is good
enough to see if systemd is booted.
While this check is not perfect it will at least allow us to use it
inside a container where systemd binaries are installed but the
container is run without systemd, see
containers/podman#13533

Another option would be to use the systemd dbus API. I gave it a try but
couldn't figure out the exact format we have to send and also had
trouble connecting to the rootless session.

For now this should help to get aardvark working inside a container.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Mar 23, 2022
1 parent 7a2cec9 commit 60a7d1d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/dns/aardvark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use std::net::Ipv4Addr;
use std::path::Path;
use std::process::{Command, Stdio};

const SYSTEMD_CHECK_PATH: &str = "/run/systemd/system";
const SYSTEMD_RUN: &str = "systemd-run";

#[derive(Debug, Clone)]
pub struct AardvarkEntry {
pub network_name: String,
Expand Down Expand Up @@ -77,10 +80,10 @@ impl Aardvark {
log::debug!("Spawning aardvark server");

let mut aardvark_args = vec![];
let systemd_run = "systemd-run";
if Aardvark::is_executable_in_path(systemd_run) {
// only use systemd when it is booted, see sd_booted(3)
if Path::new(SYSTEMD_CHECK_PATH).exists() && Aardvark::is_executable_in_path(SYSTEMD_RUN) {
// TODO: This could be replaced by systemd-api.
aardvark_args = vec![systemd_run, "-q", "--scope"];
aardvark_args = vec![SYSTEMD_RUN, "-q", "--scope"];

if self.rootless {
aardvark_args.push("--user");
Expand Down

0 comments on commit 60a7d1d

Please sign in to comment.