return rc < 0 ? -errno : rc;
}
-/* Returns in 'ret' either the system bus (if isuser==0)
+/*
+ * Returns in 'ret' either the system bus (if isuser==0)
* or the user bus (if isuser!=0).
* Returns 0 in case of success or -1 in case of error
*/
-static int get_bus(int isuser, struct sd_bus **ret)
+int systemd_get_bus(int isuser, struct sd_bus **ret)
{
int rc;
struct sd_bus *bus;
return sderr2errno(rc);
}
+void systemd_set_bus(int isuser, struct sd_bus *bus)
+{
+ struct sd_bus **target = isuser ? &usrbus : &sysbus;
+ if (*target)
+ sd_bus_unref(*target);
+ *target = bus;
+}
+
#if 0
/********************************************************************
* routines for escaping unit names to compute dbus path of units
struct sd_bus_message *ret = NULL;
sd_bus_error err = SD_BUS_ERROR_NULL;
- rc = get_bus(isuser, &bus);
+ rc = systemd_get_bus(isuser, &bus);
if (rc >= 0) {
/* TODO: asynchronous bind... */
/* TODO: more diagnostic... */
{
struct sd_bus *bus;
- return get_bus(isuser, &bus) < 0 ? NULL : get_unit_dpath(bus, name, load);
+ return systemd_get_bus(isuser, &bus) < 0 ? NULL : get_unit_dpath(bus, name, load);
}
char *systemd_unit_dpath_by_pid(int isuser, unsigned pid)
{
struct sd_bus *bus;
- return get_bus(isuser, &bus) < 0 ? NULL : get_unit_dpath_by_pid(bus, pid);
+ return systemd_get_bus(isuser, &bus) < 0 ? NULL : get_unit_dpath_by_pid(bus, pid);
}
int systemd_unit_start_dpath(int isuser, const char *dpath)
int rc;
struct sd_bus *bus;
- rc = get_bus(isuser, &bus);
+ rc = systemd_get_bus(isuser, &bus);
return rc < 0 ? rc : unit_start(bus, dpath);
}
int rc;
struct sd_bus *bus;
- rc = get_bus(isuser, &bus);
+ rc = systemd_get_bus(isuser, &bus);
return rc < 0 ? rc : unit_restart(bus, dpath);
}
int rc;
struct sd_bus *bus;
- rc = get_bus(isuser, &bus);
+ rc = systemd_get_bus(isuser, &bus);
return rc < 0 ? rc : unit_stop(bus, dpath);
}
int rc;
struct sd_bus *bus;
- rc = get_bus(isuser, &bus);
+ rc = systemd_get_bus(isuser, &bus);
if (rc >= 0)
rc = unit_start_name(bus, name);
return rc;
int rc;
struct sd_bus *bus;
- rc = get_bus(isuser, &bus);
+ rc = systemd_get_bus(isuser, &bus);
if (rc >= 0)
rc = unit_restart_name(bus, name);
return rc;
int rc;
struct sd_bus *bus;
- rc = get_bus(isuser, &bus);
+ rc = systemd_get_bus(isuser, &bus);
if (rc >= 0)
rc = unit_stop_name(bus, name);
return rc;
struct sd_bus *bus;
char *dpath;
- rc = get_bus(isuser, &bus);
+ rc = systemd_get_bus(isuser, &bus);
if (rc >= 0) {
dpath = get_unit_dpath_by_pid(bus, pid);
if (!dpath)
int rc;
struct sd_bus *bus;
- rc = get_bus(isuser, &bus);
+ rc = systemd_get_bus(isuser, &bus);
return rc < 0 ? rc : unit_pid(bus, dpath);
}
int rc;
struct sd_bus *bus;
- rc = get_bus(isuser, &bus);
+ rc = systemd_get_bus(isuser, &bus);
return rc < 0 ? NULL : unit_state(bus, dpath);
}
extern const char SysD_State_Reloading[];
extern const char SysD_State_Failed[];
+struct sd_bus;
+extern int systemd_get_bus(int isuser, struct sd_bus **ret);
+extern void systemd_set_bus(int isuser, struct sd_bus *bus);
+
extern int systemd_get_units_dir(char *path, size_t pathlen, int isuser);
extern int systemd_get_unit_path(char *path, size_t pathlen, int isuser, const char *unit, const char *uext);
extern int systemd_get_wants_path(char *path, size_t pathlen, int isuser, const char *wanter, const char *unit, const char *uext);