mirror of
https://github.com/systemd/systemd.git
synced 2024-11-07 01:27:11 +03:00
dbus-path: add Paths= option to set path specs in transient path unit
This commit is contained in:
parent
dea700bffd
commit
f76e92af1c
@ -21,6 +21,7 @@
|
|||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "bus-util.h"
|
#include "bus-util.h"
|
||||||
#include "dbus-path.h"
|
#include "dbus-path.h"
|
||||||
|
#include "dbus-util.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "path-util.h"
|
#include "path-util.h"
|
||||||
@ -105,30 +106,38 @@ static int bus_path_set_transient_property(
|
|||||||
|
|
||||||
flags |= UNIT_PRIVATE;
|
flags |= UNIT_PRIVATE;
|
||||||
|
|
||||||
if (STR_IN_SET(name, "PathExists", "PathExistsGlob", "PathChanged", "PathModified", "DirectoryNotEmpty")) {
|
if (streq(name, "MakeDirectory"))
|
||||||
const char *str;
|
return bus_set_transient_bool(u, name, &p->make_directory, message, flags, error);
|
||||||
PathType b;
|
|
||||||
|
|
||||||
b = path_type_from_string(name);
|
if (streq(name, "DirectoryMode"))
|
||||||
if (b < 0)
|
return bus_set_transient_mode_t(u, name, &p->directory_mode, message, flags, error);
|
||||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown path type");
|
|
||||||
|
|
||||||
r = sd_bus_message_read(message, "s", &str);
|
if (streq(name, "Paths")) {
|
||||||
|
const char *type_name, *path;
|
||||||
|
bool empty = true;
|
||||||
|
|
||||||
|
r = sd_bus_message_enter_container(message, 'a', "(ss)");
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (!isempty(str) && !path_is_absolute(str))
|
while ((r = sd_bus_message_read(message, "(ss)", &type_name, &path)) > 0) {
|
||||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path is not absolute");
|
PathType t;
|
||||||
|
|
||||||
|
t = path_type_from_string(type_name);
|
||||||
|
if (t < 0)
|
||||||
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown path type: %s", type_name);
|
||||||
|
|
||||||
|
if (isempty(path))
|
||||||
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path in %s is empty", type_name);
|
||||||
|
|
||||||
|
if (!path_is_absolute(path))
|
||||||
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path in %s is not absolute: %s", type_name, path);
|
||||||
|
|
||||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||||
if (isempty(str)) {
|
|
||||||
path_free_specs(p);
|
|
||||||
unit_write_settingf(u, flags, name, "%s=", name);
|
|
||||||
} else {
|
|
||||||
_cleanup_free_ char *k;
|
_cleanup_free_ char *k;
|
||||||
PathSpec *s;
|
PathSpec *s;
|
||||||
|
|
||||||
k = strdup(str);
|
k = strdup(path);
|
||||||
if (!k)
|
if (!k)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -139,48 +148,29 @@ static int bus_path_set_transient_property(
|
|||||||
s->unit = u;
|
s->unit = u;
|
||||||
s->path = path_kill_slashes(k);
|
s->path = path_kill_slashes(k);
|
||||||
k = NULL;
|
k = NULL;
|
||||||
s->type = b;
|
s->type = t;
|
||||||
s->inotify_fd = -1;
|
s->inotify_fd = -1;
|
||||||
|
|
||||||
LIST_PREPEND(spec, p->specs, s);
|
LIST_PREPEND(spec, p->specs, s);
|
||||||
|
|
||||||
unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, str);
|
unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", type_name, path);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
empty = false;
|
||||||
|
}
|
||||||
} else if (streq(name, "MakeDirectory")) {
|
|
||||||
int b;
|
|
||||||
|
|
||||||
r = sd_bus_message_read(message, "b", &b);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
r = sd_bus_message_exit_container(message);
|
||||||
p->make_directory = b;
|
|
||||||
unit_write_settingf(u, flags, name, "%s=%s", name, yes_no(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
} else if (streq(name, "DirectoryMode")) {
|
|
||||||
mode_t m;
|
|
||||||
|
|
||||||
r = sd_bus_message_read(message, "u", &m);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
if (!UNIT_WRITE_FLAGS_NOOP(flags) && empty) {
|
||||||
p->directory_mode = m;
|
path_free_specs(p);
|
||||||
unit_write_settingf(u, flags, name, "%s=%040o", name, m);
|
unit_write_settingf(u, flags, name, "PathExists=");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
} else if (streq(name, "Unit")) {
|
|
||||||
/* not implemented yet */
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user