Skip to content

Commit 9d0f220

Browse files
committed
Make client-socket into a feature
So we can use it on F37+ builds.
1 parent d8997f3 commit 9d0f220

File tree

5 files changed

+29
-23
lines changed

5 files changed

+29
-23
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ lto = "thin"
123123
# Note: If you add a feature here, you also probably want to update utils.rs:get_features()
124124
fedora-integration = []
125125
rhsm = ["libdnf-sys/rhsm"]
126+
# Enable hard requirement on `rpm-ostreed.socket`; requires https://bugzilla.redhat.com/show_bug.cgi?id=2110012
127+
client-socket = []
126128
bin-unit-tests = []
127129
# ASAN+UBSAN
128130
sanitizers = []

rust/src/client.rs

+26
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ pub(crate) fn client_handle_fd_argument(
154154
}
155155
}
156156

157+
/// Connect to the client socket and ensure the daemon is initialized;
158+
/// this avoids DBus and ensures that we get any early startup errors
159+
/// returned cleanly.
160+
#[cfg(feature = "client-socket")]
161+
pub(crate) fn start_daemon_via_socket() -> Result<()> {
162+
let address = "/run/rpm-ostree/client.sock";
163+
tracing::debug!("Starting daemon via {address}");
164+
let s = std::os::unix::net::UnixStream::connect(address)
165+
.with_context(|| anyhow!("Failed to connect to {}", address))?;
166+
let mut s = std::io::BufReader::new(s);
167+
let mut r = String::new();
168+
s.read_to_string(&mut r)
169+
.context("Reading from client socket")?;
170+
if r.is_empty() {
171+
Ok(())
172+
} else {
173+
Err(anyhow!("{r}").into())
174+
}
175+
}
176+
157177
/// Explicitly ensure the daemon is started via systemd, if possible.
158178
///
159179
/// This works around bugs from DBus activation, see
@@ -170,6 +190,12 @@ pub(crate) fn client_start_daemon() -> CxxResult<()> {
170190
if rustix::process::getuid().as_raw() != 0 {
171191
return Ok(());
172192
}
193+
194+
#[cfg(feature = "client-socket")]
195+
{
196+
start_daemon_via_socket()?;
197+
return Ok(());
198+
}
173199
// Unfortunately, RHEL8 systemd will count "systemctl start"
174200
// invocations against the restart limit, so query the status
175201
// first.

rust/src/daemon.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::cxxrsutil::*;
88
use crate::ffi::{
99
OverrideReplacementSource, OverrideReplacementType, ParsedRevision, ParsedRevisionKind,
1010
};
11-
use anyhow::{anyhow, format_err, Context, Result};
11+
use anyhow::{anyhow, format_err, Result};
1212
use cap_std::fs::Dir;
1313
use cap_std_ext::dirext::CapStdExtDirExt;
1414
use cap_std_ext::{cap_std, rustix};
@@ -135,25 +135,6 @@ fn deployment_populate_variant_origin(
135135
Ok(())
136136
}
137137

138-
/// Connect to the client socket and ensure the daemon is initialized;
139-
/// this avoids DBus and ensures that we get any early startup errors
140-
/// returned cleanly.
141-
pub(crate) fn start_daemon_via_socket() -> CxxResult<()> {
142-
let address = "/run/rpm-ostree/client.sock";
143-
tracing::debug!("Starting daemon via {address}");
144-
let s = std::os::unix::net::UnixStream::connect(address)
145-
.with_context(|| anyhow!("Failed to connect to {}", address))?;
146-
let mut s = std::io::BufReader::new(s);
147-
let mut r = String::new();
148-
s.read_to_string(&mut r)
149-
.context("Reading from client socket")?;
150-
if r.is_empty() {
151-
Ok(())
152-
} else {
153-
Err(anyhow!("{r}").into())
154-
}
155-
}
156-
157138
async fn send_ok_result_to_client(_client: UnixStream) {
158139
// On success we close the stream without writing anything,
159140
// which acknowledges successful startup to the client.

rust/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ pub mod ffi {
300300
// daemon.rs
301301
extern "Rust" {
302302
fn daemon_main(debug: bool) -> Result<()>;
303-
fn start_daemon_via_socket() -> Result<()>;
304303
fn daemon_terminate();
305304
fn daemon_sanitycheck_environment(sysroot: &OstreeSysroot) -> Result<()>;
306305
fn deployment_generate_id(deployment: &OstreeDeployment) -> String;

src/app/libmain.cxx

-2
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@ rpmostree_option_context_parse (GOptionContext *context, const GOptionEntry *mai
281281
return rpmostreecxx::client_throw_non_ostree_host_error (error);
282282
}
283283

284-
CXX_TRY (rpmostreecxx::start_daemon_via_socket (), error);
285-
286284
/* root never needs to auth */
287285
if (getuid () != 0)
288286
/* ignore errors; we print out a warning if we fail to spawn pkttyagent */

0 commit comments

Comments
 (0)