Skip to content

Commit

Permalink
removing client-socket feature
Browse files Browse the repository at this point in the history
  • Loading branch information
RishabhSaini committed Aug 3, 2023
1 parent 913e32a commit 4837241
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 107 deletions.
37 changes: 0 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tokio = { version = "1.28.2", features = ["time", "process", "rt", "net"] }
xmlrpc = "0.15.1"
termcolor = "1.1.3"
tokio-unix-ipc = { version = "0.2.0", features = ["serde"] }

[build-dependencies]
anyhow = "1.0"
Expand Down Expand Up @@ -126,8 +125,6 @@ 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
7 changes: 0 additions & 7 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ AC_ARG_ENABLE(featuresrs,
[Rust features, see Cargo.toml for more information]),,
[enable_featuresrs=])

AC_ARG_ENABLE(client-socket,
AS_HELP_STRING([--enable-client-socket],
[(default: no)]),,
[enable_client_socket=no])
AS_IF([test x$enable_client_socket = xyes], [enable_featuresrs="$enable_featuresrs client-socket"])
AM_CONDITIONAL(CLIENT_SOCKET, [echo $enable_featuresrs | grep -q 'client-socket'])

AC_SUBST([RUST_FEATURES], $enable_featuresrs)

# Initialize libtool
Expand Down
9 changes: 1 addition & 8 deletions packaging/rpm-ostree.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ BuildRequires: rust
%bcond_with rhsm
%endif

# https://bugzilla.redhat.com/show_bug.cgi?id=2110012
%if 0%{?fedora} >= 37
%bcond_without client_socket
%else
%bcond_with client_socket
%endif

# RHEL (8,9) doesn't ship zchunk today. Keep this in sync
# with libdnf: https://gitlab.com/redhat/centos-stream/rpms/libdnf/-/blob/762f631e36d1e42c63a794882269d26c156b68c1/libdnf.spec#L45
%if 0%{?rhel}
Expand Down Expand Up @@ -182,7 +175,7 @@ env NOCONFIGURE=1 ./autogen.sh
export RUSTFLAGS="%{build_rustflags}"
%endif
%configure --disable-silent-rules --enable-gtk-doc %{?rpmdb_default} %{?with_sanitizers:--enable-sanitizers} %{?with_bin_unit_tests:--enable-bin-unit-tests} \
%{?with_rhsm:--enable-featuresrs=rhsm} %{?with_client_socket:--enable-client-socket}
%{?with_rhsm:--enable-featuresrs=rhsm}

%make_build

Expand Down
52 changes: 1 addition & 51 deletions rust/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@ 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")]
fn start_daemon_via_socket() -> Result<()> {
use cap_std::io_lifetimes::IntoSocketlike;

let conn = tokio::net::UnixStream::connect("/run/rpm-ostree/client.sock")?;
let conn = tokio::net::UnixStream::connect("/run/rpm-ostree/client.sock");

let address = sockaddr()?;
let socket = rustix::net::socket(
Expand Down Expand Up @@ -197,62 +196,13 @@ pub(crate) fn sockaddr() -> Result<rustix::net::SocketAddrUnix> {
rustix::net::SocketAddrUnix::new("/run/rpm-ostree/client.sock").map_err(anyhow::Error::msg)
}

/// Explicitly ensure the daemon is started via systemd, if possible.
///
/// This works around bugs from DBus activation, see
/// https://github.com/coreos/rpm-ostree/pull/2932
///
/// Basically we load too much data before claiming the bus name,
/// and dbus doesn't give us a useful error. Instead, let's talk
/// to systemd directly and use its client tools to scrape errors.
///
/// What we really should do probably is use native socket activation.
#[cfg(not(feature = "client-socket"))]
fn start_daemon_via_systemctl() -> Result<()> {
use std::process::Command;

let service = "rpm-ostreed.service";
// Assume non-root can't use systemd right now.
if rustix::process::getuid().as_raw() != 0 {
return Ok(());
}

// Unfortunately, RHEL8 systemd will count "systemctl start"
// invocations against the restart limit, so query the status
// first.
let activeres = Command::new("systemctl")
.args(&["is-active", "rpm-ostreed"])
.output()?;
// Explicitly don't check the error return value, we don't want to
// hard fail on it.
if String::from_utf8_lossy(&activeres.stdout).starts_with("active") {
// It's active, we're done. Note that while this is a race
// condition, that's fine because it will be handled by DBus
// activation.
return Ok(());
}
let res = Command::new("systemctl")
.args(&["--no-ask-password", "start", service])
.status()?;
if !res.success() {
let _ = Command::new("systemctl")
.args(&["--no-pager", "status", service])
.status();
return Err(anyhow!("{}", res).into());
}
Ok(())
}

pub(crate) fn client_start_daemon() -> CxxResult<()> {
// systemctl and socket paths only work for root right now; in the future
// the socket may be opened up.
if rustix::process::getuid().as_raw() != 0 {
return Ok(());
}
#[cfg(feature = "client-socket")]
return start_daemon_via_socket().map_err(Into::into);
#[cfg(not(feature = "client-socket"))]
return start_daemon_via_systemctl().map_err(Into::into);
}

/// Convert the GVariant parameters from the DownloadProgress DBus API to a human-readable English string.
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/rpm-ostreed.socket
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ConditionKernelCommandLine=ostree

[Socket]
ListenStream=/run/rpm-ostree/client.sock
ListenSequentialPacket=/run/rpm-ostree/client.sock
SocketMode=0600

[Install]
Expand Down

0 comments on commit 4837241

Please sign in to comment.