Skip to content

Commit

Permalink
Make client-socket into a feature
Browse files Browse the repository at this point in the history
So we can use it on F37+ builds.
  • Loading branch information
cgwalters committed Jul 27, 2022
1 parent d8997f3 commit 9d0f220
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ lto = "thin"
# Note: If you add a feature here, you also probably want to update utils.rs:get_features()
fedora-integration = []
rhsm = ["libdnf-sys/rhsm"]
# Enable hard requirement on `rpm-ostreed.socket`; requires https://bugzilla.redhat.com/show_bug.cgi?id=2110012
client-socket = []
bin-unit-tests = []
# ASAN+UBSAN
sanitizers = []
Expand Down
26 changes: 26 additions & 0 deletions rust/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ pub(crate) fn client_handle_fd_argument(
}
}

/// Connect to the client socket and ensure the daemon is initialized;
/// this avoids DBus and ensures that we get any early startup errors
/// returned cleanly.
#[cfg(feature = "client-socket")]
pub(crate) fn start_daemon_via_socket() -> Result<()> {
let address = "/run/rpm-ostree/client.sock";
tracing::debug!("Starting daemon via {address}");
let s = std::os::unix::net::UnixStream::connect(address)
.with_context(|| anyhow!("Failed to connect to {}", address))?;
let mut s = std::io::BufReader::new(s);
let mut r = String::new();
s.read_to_string(&mut r)
.context("Reading from client socket")?;
if r.is_empty() {
Ok(())
} else {
Err(anyhow!("{r}").into())
}
}

/// Explicitly ensure the daemon is started via systemd, if possible.
///
/// This works around bugs from DBus activation, see
Expand All @@ -170,6 +190,12 @@ pub(crate) fn client_start_daemon() -> CxxResult<()> {
if rustix::process::getuid().as_raw() != 0 {
return Ok(());
}

#[cfg(feature = "client-socket")]
{
start_daemon_via_socket()?;
return Ok(());
}
// Unfortunately, RHEL8 systemd will count "systemctl start"
// invocations against the restart limit, so query the status
// first.
Expand Down
21 changes: 1 addition & 20 deletions rust/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::cxxrsutil::*;
use crate::ffi::{
OverrideReplacementSource, OverrideReplacementType, ParsedRevision, ParsedRevisionKind,
};
use anyhow::{anyhow, format_err, Context, Result};
use anyhow::{anyhow, format_err, Result};
use cap_std::fs::Dir;
use cap_std_ext::dirext::CapStdExtDirExt;
use cap_std_ext::{cap_std, rustix};
Expand Down Expand Up @@ -135,25 +135,6 @@ fn deployment_populate_variant_origin(
Ok(())
}

/// Connect to the client socket and ensure the daemon is initialized;
/// this avoids DBus and ensures that we get any early startup errors
/// returned cleanly.
pub(crate) fn start_daemon_via_socket() -> CxxResult<()> {
let address = "/run/rpm-ostree/client.sock";
tracing::debug!("Starting daemon via {address}");
let s = std::os::unix::net::UnixStream::connect(address)
.with_context(|| anyhow!("Failed to connect to {}", address))?;
let mut s = std::io::BufReader::new(s);
let mut r = String::new();
s.read_to_string(&mut r)
.context("Reading from client socket")?;
if r.is_empty() {
Ok(())
} else {
Err(anyhow!("{r}").into())
}
}

async fn send_ok_result_to_client(_client: UnixStream) {
// On success we close the stream without writing anything,
// which acknowledges successful startup to the client.
Expand Down
1 change: 0 additions & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ pub mod ffi {
// daemon.rs
extern "Rust" {
fn daemon_main(debug: bool) -> Result<()>;
fn start_daemon_via_socket() -> Result<()>;
fn daemon_terminate();
fn daemon_sanitycheck_environment(sysroot: &OstreeSysroot) -> Result<()>;
fn deployment_generate_id(deployment: &OstreeDeployment) -> String;
Expand Down
2 changes: 0 additions & 2 deletions src/app/libmain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ rpmostree_option_context_parse (GOptionContext *context, const GOptionEntry *mai
return rpmostreecxx::client_throw_non_ostree_host_error (error);
}

CXX_TRY (rpmostreecxx::start_daemon_via_socket (), error);

/* root never needs to auth */
if (getuid () != 0)
/* ignore errors; we print out a warning if we fail to spawn pkttyagent */
Expand Down

0 comments on commit 9d0f220

Please sign in to comment.