if (r < 0) {
/* systemd might have dropped off momentarily, let's
* not make this an error */
- if (sd_bus_error_has_names(&error, SD_BUS_ERROR_NO_REPLY,
- SD_BUS_ERROR_DISCONNECTED))
+ if (bus_error_is_connection(&error))
return true;
/* If the unit is already unloaded then it's not
&reply,
"s");
if (r < 0) {
- if (sd_bus_error_has_names(&error, SD_BUS_ERROR_NO_REPLY,
- SD_BUS_ERROR_DISCONNECTED))
+ if (bus_error_is_connection(&error))
return true;
if (sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_OBJECT))
&reply,
"s");
if (r < 0) {
- if (sd_bus_error_has_names(&error, SD_BUS_ERROR_NO_REPLY,
- SD_BUS_ERROR_DISCONNECTED))
+ if (bus_error_is_connection(&error))
return true;
if (sd_bus_error_has_names(&error, BUS_ERROR_NO_SUCH_UNIT,
&reply,
"s");
if (r < 0) {
- if (sd_bus_error_has_names(&error, SD_BUS_ERROR_NO_REPLY,
- SD_BUS_ERROR_DISCONNECTED))
+ if (bus_error_is_connection(&error))
return true;
if (sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_OBJECT))
/* reply = */ NULL, NULL);
if (r < 0) {
/* Hmm, the service manager probably hasn't finished reexecution just yet? Try again later. */
- if (sd_bus_error_has_names(&error,
- SD_BUS_ERROR_NO_REPLY,
- SD_BUS_ERROR_DISCONNECTED,
- SD_BUS_ERROR_TIMED_OUT,
- SD_BUS_ERROR_SERVICE_UNKNOWN,
- SD_BUS_ERROR_NAME_HAS_NO_OWNER))
+ if (bus_error_is_connection(&error) || bus_error_is_unknown_service(&error))
goto retry_timer;
if (sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_OBJECT))
if (r < 0) {
/* If this is a connection error, then try to reconnect. This might be because the service
* manager is being restarted. Handle this gracefully. */
- if (sd_bus_error_has_names(
- &error,
- SD_BUS_ERROR_NO_REPLY,
- SD_BUS_ERROR_DISCONNECTED,
- SD_BUS_ERROR_TIMED_OUT,
- SD_BUS_ERROR_SERVICE_UNKNOWN,
- SD_BUS_ERROR_NAME_HAS_NO_OWNER)) {
-
+ if (bus_error_is_connection(&error) || bus_error_is_unknown_service(&error)) {
log_info_errno(r, "Bus call failed due to connection problems. Trying to reconnect...");
/* Not propagating error, because we handled it already, by reconnecting. */
return run_context_reconnect(c);
BUS_ERROR_NO_SUCH_UNIT);
}
+bool bus_error_is_connection(const sd_bus_error *error) {
+ return sd_bus_error_has_names(error,
+ SD_BUS_ERROR_NO_REPLY,
+ SD_BUS_ERROR_DISCONNECTED,
+ SD_BUS_ERROR_TIMED_OUT);
+}
+
int bus_check_peercred(sd_bus *c) {
struct ucred ucred;
int fd, r;
int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t timeout, check_idle_t check_idle, void *userdata);
int bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error);
+
bool bus_error_is_unknown_service(const sd_bus_error *error);
+bool bus_error_is_connection(const sd_bus_error *error);
int bus_check_peercred(sd_bus *c);
"ActiveState",
&error,
&state);
- if ((r == -ENOTCONN ||
- sd_bus_error_has_names(&error,
- SD_BUS_ERROR_NO_REPLY,
- SD_BUS_ERROR_DISCONNECTED)) &&
+ if ((r == -ENOTCONN || bus_error_is_connection(&error)) &&
n_attempts < MAX_ATTEMPTS) {
log_debug_errno(r, "Failed to get state of %s, retrying after a slight delay: %s",
e->special, bus_error_message(&error, r));