@@ -159,11 +159,13 @@ pub(crate) fn client_handle_fd_argument(
159159/// Connect to the client socket and ensure the daemon is initialized;
160160/// this avoids DBus and ensures that we get any early startup errors
161161/// returned cleanly.
162- #[ cfg( feature = "client-socket" ) ]
163162fn start_daemon_via_socket ( ) -> Result < ( ) > {
164163 use cap_std:: io_lifetimes:: IntoSocketlike ;
165164
166- let conn = tokio:: net:: UnixStream :: connect ( "/run/rpm-ostree/client.sock" ) ?;
165+ futures:: executor:: block_on ( async {
166+ let c = tokio:: net:: UnixStream :: connect ( "/run/rpm-ostree/client.sock" ) . await ?;
167+ Ok :: < _ , anyhow:: Error > ( c)
168+ } ) ?;
167169
168170 let address = sockaddr ( ) ?;
169171 let socket = rustix:: net:: socket (
@@ -197,62 +199,13 @@ pub(crate) fn sockaddr() -> Result<rustix::net::SocketAddrUnix> {
197199 rustix:: net:: SocketAddrUnix :: new ( "/run/rpm-ostree/client.sock" ) . map_err ( anyhow:: Error :: msg)
198200}
199201
200- /// Explicitly ensure the daemon is started via systemd, if possible.
201- ///
202- /// This works around bugs from DBus activation, see
203- /// https://github.com/coreos/rpm-ostree/pull/2932
204- ///
205- /// Basically we load too much data before claiming the bus name,
206- /// and dbus doesn't give us a useful error. Instead, let's talk
207- /// to systemd directly and use its client tools to scrape errors.
208- ///
209- /// What we really should do probably is use native socket activation.
210- #[ cfg( not( feature = "client-socket" ) ) ]
211- fn start_daemon_via_systemctl ( ) -> Result < ( ) > {
212- use std:: process:: Command ;
213-
214- let service = "rpm-ostreed.service" ;
215- // Assume non-root can't use systemd right now.
216- if rustix:: process:: getuid ( ) . as_raw ( ) != 0 {
217- return Ok ( ( ) ) ;
218- }
219-
220- // Unfortunately, RHEL8 systemd will count "systemctl start"
221- // invocations against the restart limit, so query the status
222- // first.
223- let activeres = Command :: new ( "systemctl" )
224- . args ( & [ "is-active" , "rpm-ostreed" ] )
225- . output ( ) ?;
226- // Explicitly don't check the error return value, we don't want to
227- // hard fail on it.
228- if String :: from_utf8_lossy ( & activeres. stdout ) . starts_with ( "active" ) {
229- // It's active, we're done. Note that while this is a race
230- // condition, that's fine because it will be handled by DBus
231- // activation.
232- return Ok ( ( ) ) ;
233- }
234- let res = Command :: new ( "systemctl" )
235- . args ( & [ "--no-ask-password" , "start" , service] )
236- . status ( ) ?;
237- if !res. success ( ) {
238- let _ = Command :: new ( "systemctl" )
239- . args ( & [ "--no-pager" , "status" , service] )
240- . status ( ) ;
241- return Err ( anyhow ! ( "{}" , res) . into ( ) ) ;
242- }
243- Ok ( ( ) )
244- }
245-
246202pub ( crate ) fn client_start_daemon ( ) -> CxxResult < ( ) > {
247203 // systemctl and socket paths only work for root right now; in the future
248204 // the socket may be opened up.
249205 if rustix:: process:: getuid ( ) . as_raw ( ) != 0 {
250206 return Ok ( ( ) ) ;
251207 }
252- #[ cfg( feature = "client-socket" ) ]
253208 return start_daemon_via_socket ( ) . map_err ( Into :: into) ;
254- #[ cfg( not( feature = "client-socket" ) ) ]
255- return start_daemon_via_systemctl ( ) . map_err ( Into :: into) ;
256209}
257210
258211/// Convert the GVariant parameters from the DownloadProgress DBus API to a human-readable English string.
0 commit comments