dbus-scope.c revision a911bb9ab27ac0eb3bbf4e8b4109e5da9b88eee3
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "unit.h"
#include "scope.h"
#include "dbus-unit.h"
#include "dbus-cgroup.h"
#include "dbus-kill.h"
#include "dbus-scope.h"
#include "bus-util.h"
#include "bus-internal.h"
static int bus_scope_abandon(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
assert(s);
return scope_abandon(s);
}
const sd_bus_vtable bus_scope_vtable[] = {
SD_BUS_PROPERTY("Controller", "s", NULL, offsetof(Scope, controller), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Scope, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Scope, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
};
static int bus_scope_set_transient_property(
Scope *s,
const char *name,
sd_bus_error *error) {
int r;
assert(s);
unsigned n = 0;
if (r < 0)
return r;
if (pid <= 1)
return -EINVAL;
if (mode != UNIT_CHECK) {
if (r < 0 && r != -EEXIST)
return r;
}
n++;
}
if (r < 0)
return r;
if (r < 0)
return r;
if (n <= 0)
return -EINVAL;
return 1;
const char *controller;
char *c;
if (r < 0)
return r;
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Controller '%s' is not a valid bus name.", controller);
if (mode != UNIT_CHECK) {
if (isempty(controller))
c = NULL;
else {
c = strdup(controller);
if (!c)
return -ENOMEM;
}
free(s->controller);
s->controller = c;
}
return 1;
if (mode != UNIT_CHECK) {
if (r < 0)
return r;
unit_write_drop_in_format(UNIT(s), mode, name, "[Scope]\nTimeoutStopSec=%lluus\n", (unsigned long long) s->timeout_stop_usec);
} else {
if (r < 0)
return r;
}
return 1;
}
return 0;
}
Unit *u,
const char *name,
sd_bus_error *error) {
int r;
assert(s);
if (r != 0)
return r;
if (u->load_state == UNIT_STUB) {
/* While we are created we still accept PIDs */
if (r != 0)
return r;
if (r != 0)
return r;
}
return 0;
}
int bus_scope_commit_properties(Unit *u) {
assert(u);
return 0;
}
int bus_scope_send_request_stop(Scope *s) {
_cleanup_free_ char *p = NULL;
int r;
assert(s);
if (!s->controller)
return 0;
p = unit_dbus_path(UNIT(s));
if (!p)
return -ENOMEM;
p,
"org.freedesktop.systemd1.Scope",
"RequestStop",
&m);
if (r < 0)
return r;
}