+ sd_bus_message_unref(msg);
+ return result;
+}
+
+static char *get_unit_dpath(struct sd_bus *bus, const char *unit, int load)
+{
+ int rc;
+ struct sd_bus_message *ret = NULL;
+ sd_bus_error err = SD_BUS_ERROR_NULL;
+
+ rc = sd_bus_call_method(bus, sdb_destination, sdb_path, sdbi_manager, load ? sdbm_load_unit : sdbm_get_unit, &err, &ret, "s", unit);
+ if (rc < 0)
+ goto error;
+
+ return get_dpath(ret);
+error:
+ sd_bus_message_unref(ret);
+ return NULL;
+}
+
+static char *get_unit_dpath_by_pid(struct sd_bus *bus, unsigned pid)
+{
+ int rc;
+ struct sd_bus_message *ret = NULL;
+ sd_bus_error err = SD_BUS_ERROR_NULL;
+
+ rc = sd_bus_call_method(bus, sdb_destination, sdb_path, sdbi_manager, sdbm_get_unit_by_pid, &err, &ret, "u", pid);
+ if (rc < 0)
+ goto error;
+
+ return get_dpath(ret);
+error:
+ sd_bus_message_unref(ret);
+ return NULL;
+}
+
+static int unit_pid(struct sd_bus *bus, const char *dpath)
+{
+ int rc;
+ unsigned u = 0;
+ sd_bus_error err = SD_BUS_ERROR_NULL;
+
+ rc = sd_bus_get_property_trivial(bus, sdb_destination, dpath, sdbi_service, sdbp_exec_main_pid, &err, 'u', &u);
+ return rc < 0 ? rc : (int)u;
+}
+
+static const char *unit_state(struct sd_bus *bus, const char *dpath)
+{
+ int rc;
+ char *st;
+ const char *resu;
+ sd_bus_error err = SD_BUS_ERROR_NULL;
+
+ rc = sd_bus_get_property_string(bus, sdb_destination, dpath, sdbi_unit, sdbp_active_state, &err, &st);
+ if (rc < 0) {
+ errno = -rc;
+ resu = NULL;
+ } else {
+ if (!strcmp(st, SysD_State_Active))
+ resu = SysD_State_Active;
+ else if (!strcmp(st, SysD_State_Reloading))
+ resu = SysD_State_Reloading;
+ else if (!strcmp(st, SysD_State_Inactive))
+ resu = SysD_State_Inactive;
+ else if (!strcmp(st, SysD_State_Failed))
+ resu = SysD_State_Failed;
+ else if (!strcmp(st, SysD_State_Activating))
+ resu = SysD_State_Activating;
+ else if (!strcmp(st, SysD_State_Deactivating))
+ resu = SysD_State_Deactivating;
+ else {
+ errno = EBADMSG;
+ resu = NULL;
+ }
+ free(st);
+ }
+ return resu;
+}
+
+static int unit_start(struct sd_bus *bus, const char *dpath)
+{
+ int rc;
+ struct sd_bus_message *ret = NULL;
+ sd_bus_error err = SD_BUS_ERROR_NULL;
+
+ rc = sd_bus_call_method(bus, sdb_destination, dpath, sdbi_unit, sdbm_start, &err, &ret, "s", "replace");
+ sd_bus_message_unref(ret);