/*
- Copyright 2017 IoT.bzh
+ Copyright (C) 2017-2019 IoT.bzh
author: José Bollo <jose.bollo@iot.bzh>
struct sd_bus;
struct sd_bus_message;
typedef struct { const char *name; const char *message; } sd_bus_error;
+# define sd_bus_unref(...) ((void)0)
# define sd_bus_default_user(p) ((*(p)=NULL),(-ENOTSUP))
# define sd_bus_default_system(p) ((*(p)=NULL),(-ENOTSUP))
# define sd_bus_call_method(...) (-ENOTSUP)
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);
}