4 author: José Bollo <jose.bollo@iot.bzh>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
27 #include <systemd/sd-bus.h>
28 #include <systemd/sd-bus-protocol.h>
30 #include "utils-systemd.h"
32 #if !defined(SYSTEMD_UNITS_ROOT)
33 # define SYSTEMD_UNITS_ROOT "/usr/local/lib/systemd"
36 static const char sdb_path[] = "/org/freedesktop/systemd1";
37 static const char sdb_destination[] = "org.freedesktop.systemd1";
38 static const char sdbi_manager[] = "org.freedesktop.systemd1.Manager";
39 static const char sdbm_reload[] = "Reload";
41 static struct sd_bus *sysbus;
42 static struct sd_bus *usrbus;
44 static int get_bus(int isuser, struct sd_bus **ret)
49 bus = isuser ? usrbus : sysbus;
54 rc = sd_bus_default_user(ret);
58 rc = sd_bus_default_system(ret);
65 int systemd_get_unit_path(char *path, size_t pathlen, int isuser, const char *unit, const char *uext)
67 int rc = snprintf(path, pathlen, "%s/%s/%s.%s",
69 isuser ? "user" : "system",
73 if (rc >= 0 && (size_t)rc >= pathlen) {
80 int systemd_get_wants_path(char *path, size_t pathlen, int isuser, const char *wanter, const char *unit, const char *uext)
82 int rc = snprintf(path, pathlen, "%s/%s/%s.wants/%s.%s",
84 isuser ? "user" : "system",
89 if (rc >= 0 && (size_t)rc >= pathlen) {
96 int systemd_get_wants_target(char *path, size_t pathlen, const char *unit, const char *uext)
98 int rc = snprintf(path, pathlen, "../%s.%s", unit, uext);
100 if (rc >= 0 && (size_t)rc >= pathlen) {
101 errno = ENAMETOOLONG;
107 int systemd_daemon_reload(int isuser)
112 rc = get_bus(isuser, &bus);
114 rc = sd_bus_call_method(bus, sdb_destination, sdb_path, sdbi_manager, sdbm_reload, NULL, NULL, NULL);