dbus-manager.c revision 123b964a537c21e9ebaf849acefb23f0f13db785
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/***
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2010 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering***/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#include <errno.h>
96aad8d15a324d0e956a4e5653a11a67b209b41aLennart Poettering#include <unistd.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
4ad7f2761da661853dcc29d542efb4727abb1101Nick Owens#include "dbus.h"
39d8db043b599a7382f94bfc904d5e108af438bdLennart Poettering#include "log.h"
51323288fc628a5cac50914df915545d685b793eLennart Poettering#include "dbus-manager.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "strv.h"
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering#include "bus-errors.h"
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering#include "build.h"
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering#include "dbus-common.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "install.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "selinux-access.h"
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering#include "watchdog.h"
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering#include "hwclock.h"
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering#include "path-util.h"
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering#include "dbus-unit.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "virt.h"
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering#include "env-util.h"
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
703e4f5e39c019da8c002ba10bd450ce378c0e91Lennart Poettering#define BUS_MANAGER_INTERFACE_BEGIN \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <interface name=\"org.freedesktop.systemd1.Manager\">\n"
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#define BUS_MANAGER_INTERFACE_METHODS \
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering " <method name=\"GetUnit\">\n" \
309e9d86f0e7f9c5f0a2a09227bdfdb3174d4436Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering " </method>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <method name=\"GetUnitByPID\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n" \
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " </method>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <method name=\"LoadUnit\">\n" \
818f766b12e025683cf4fed12b3da2a025bb0b31Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
818f766b12e025683cf4fed12b3da2a025bb0b31Lennart Poettering " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
818f766b12e025683cf4fed12b3da2a025bb0b31Lennart Poettering " </method>\n" \
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering " <method name=\"StartUnit\">\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
ac720200b7e5b80cc4985087e38f3452e5b3b080Lennart Poettering " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
ac720200b7e5b80cc4985087e38f3452e5b3b080Lennart Poettering " </method>\n" \
ac720200b7e5b80cc4985087e38f3452e5b3b080Lennart Poettering " <method name=\"StartUnitReplace\">\n" \
818f766b12e025683cf4fed12b3da2a025bb0b31Lennart Poettering " <arg name=\"old_unit\" type=\"s\" direction=\"in\"/>\n" \
818f766b12e025683cf4fed12b3da2a025bb0b31Lennart Poettering " <arg name=\"new_unit\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
a761c1ca851a9397b5a207ef600e077d0f7f4534Lennart Poettering " </method>\n" \
019036a47fcd10fcf0286800d144c706f3773e2fLennart Poettering " <method name=\"StopUnit\">\n" \
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
b2b796b8ab5565fbe60b544d2579e2bfca31bf6aLennart Poettering " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
b2b796b8ab5565fbe60b544d2579e2bfca31bf6aLennart Poettering " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
b2b796b8ab5565fbe60b544d2579e2bfca31bf6aLennart Poettering " </method>\n" \
3bbdc31df37a23b5134a115c01d15e7ff870b3ccLennart Poettering " <method name=\"ReloadUnit\">\n" \
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"RestartUnit\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"TryRestartUnit\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
63c372cb9df3bee01e3bf8cd7f96f336bddda846Lennart Poettering " <method name=\"ReloadOrRestartUnit\">\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"ReloadOrTryRestartUnit\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering " </method>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <method name=\"KillUnit\">\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"who\" type=\"s\" direction=\"in\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"signal\" type=\"i\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering " <method name=\"ResetFailedUnit\">\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " </method>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <method name=\"GetUnitControlGroupAttributes\">\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <arg name=\"attributes\" type=\"as\" direction=\"in\"/>\n" \
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering " <arg name=\"values\" type=\"as\" direction=\"out\"/>\n" \
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering " </method>\n" \
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering " <method name=\"SetUnitControlGroupAttributes\">\n" \
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering " <arg name=\"attributes\" type=\"a(sss)\" direction=\"in\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <arg name=\"mode\" type=\"s\" direction=\"in\"\n/>" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " </method>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <method name=\"UnsetUnitControlGroupAttributes\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering " <arg name=\"attributes\" type=\"a(ss)\" direction=\"in\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " </method>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <method name=\"SetUnitControlGroups\">\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"groups\" type=\"as\" direction=\"in\"/>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering " </method>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <method name=\"UnsetUnitControlGroups\">\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <arg name=\"groups\" type=\"as\" direction=\"in\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <arg name=\"mode\" type=\"s\" direction=\"in\"\n/>" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " </method>\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <method name=\"GetJob\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"id\" type=\"u\" direction=\"in\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " </method>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <method name=\"CancelJob\">\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <arg name=\"id\" type=\"u\" direction=\"in\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " </method>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <method name=\"ClearJobs\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <method name=\"ResetFailed\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <method name=\"ListUnits\">\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <arg name=\"units\" type=\"a(ssssssouso)\" direction=\"out\"/>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " </method>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <method name=\"ListJobs\">\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <arg name=\"jobs\" type=\"a(usssoo)\" direction=\"out\"/>\n" \
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering " </method>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <method name=\"Subscribe\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <method name=\"Unsubscribe\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"Dump\">\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"dump\" type=\"s\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering " <method name=\"CreateSnapshot\">\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"cleanup\" type=\"b\" direction=\"in\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <method name=\"RemoveSnapshot\">\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
703e4f5e39c019da8c002ba10bd450ce378c0e91Lennart Poettering " </method>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <method name=\"Reload\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <method name=\"Reexecute\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <method name=\"Exit\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <method name=\"Reboot\"/>\n" \
7588460aaf6bd33f6c9bd5645916cfd8a862e9c4Tom Gundersen " <method name=\"PowerOff\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <method name=\"Halt\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <method name=\"KExec\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <method name=\"SwitchRoot\">\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"new_root\" type=\"s\" direction=\"in\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"init\" type=\"s\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering " <method name=\"SetEnvironment\">\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <arg name=\"names\" type=\"as\" direction=\"in\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " </method>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <method name=\"UnsetEnvironment\">\n" \
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering " <arg name=\"names\" type=\"as\" direction=\"in\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " </method>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <method name=\"UnsetAndSetEnvironment\">\n" \
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering " <arg name=\"unset\" type=\"as\" direction=\"in\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <arg name=\"set\" type=\"as\" direction=\"in\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " </method>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <method name=\"ListUnitFiles\">\n" \
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering " <arg name=\"files\" type=\"a(ss)\" direction=\"out\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " </method>\n" \
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering " <method name=\"GetUnitFileState\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"file\" type=\"s\" direction=\"in\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <arg name=\"state\" type=\"s\" direction=\"out\"/>\n" \
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering " </method>\n" \
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering " <method name=\"EnableUnitFiles\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
309e9d86f0e7f9c5f0a2a09227bdfdb3174d4436Lennart Poettering " <arg name=\"carries_install_info\" type=\"b\" direction=\"out\"/>\n" \
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering " </method>\n" \
8ba9fd9cee0eef572f7b3ed7a8c3ed31160e93d3Lennart Poettering " <method name=\"DisableUnitFiles\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
703e4f5e39c019da8c002ba10bd450ce378c0e91Lennart Poettering " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " </method>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <method name=\"ReenableUnitFiles\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"carries_install_info\" type=\"b\" direction=\"out\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " </method>\n" \
309e9d86f0e7f9c5f0a2a09227bdfdb3174d4436Lennart Poettering " <method name=\"LinkUnitFiles\">\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
931851e8e492a4d2715e22dcde50a5e7ccef4b49Lennart Poettering " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
309e9d86f0e7f9c5f0a2a09227bdfdb3174d4436Lennart Poettering " </method>\n" \
309e9d86f0e7f9c5f0a2a09227bdfdb3174d4436Lennart Poettering " <method name=\"PresetUnitFiles\">\n" \
309e9d86f0e7f9c5f0a2a09227bdfdb3174d4436Lennart Poettering " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"carries_install_info\" type=\"b\" direction=\"out\"/>\n" \
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt " </method>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <method name=\"MaskUnitFiles\">\n" \
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </method>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <method name=\"UnmaskUnitFiles\">\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " </method>\n"
51323288fc628a5cac50914df915545d685b793eLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering#define BUS_MANAGER_INTERFACE_SIGNALS \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <signal name=\"UnitNew\">\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <arg name=\"id\" type=\"s\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <arg name=\"unit\" type=\"o\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " </signal>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <signal name=\"UnitRemoved\">\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <arg name=\"id\" type=\"s\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <arg name=\"unit\" type=\"o\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " </signal>\n" \
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering " <signal name=\"JobNew\">\n" \
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering " <arg name=\"id\" type=\"u\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"job\" type=\"o\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"unit\" type=\"s\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " </signal>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <signal name=\"JobRemoved\">\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"id\" type=\"u\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"job\" type=\"o\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"unit\" type=\"s\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"result\" type=\"s\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </signal>" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <signal name=\"StartupFinished\">\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <arg name=\"firmware\" type=\"t\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <arg name=\"loader\" type=\"t\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <arg name=\"kernel\" type=\"t\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"initrd\" type=\"t\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"userspace\" type=\"t\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <arg name=\"total\" type=\"t\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </signal>" \
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering " <signal name=\"UnitFilesChanged\"/>\n"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering#define BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL \
7b9f7afcc04e80b77a2567b0750aa2cd03c1a1cdLennart Poettering " <property name=\"Version\" type=\"s\" access=\"read\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <property name=\"Features\" type=\"s\" access=\"read\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <property name=\"Tainted\" type=\"s\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"FirmwareTimestamp\" type=\"t\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"FirmwareTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering " <property name=\"LoaderTimestamp\" type=\"t\" access=\"read\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <property name=\"LoaderTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <property name=\"KernelTimestamp\" type=\"t\" access=\"read\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <property name=\"KernelTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <property name=\"InitRDTimestamp\" type=\"t\" access=\"read\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <property name=\"InitRDTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <property name=\"UserspaceTimestamp\" type=\"t\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"UserspaceTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
51323288fc628a5cac50914df915545d685b793eLennart Poettering " <property name=\"FinishTimestamp\" type=\"t\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"FinishTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"LogLevel\" type=\"s\" access=\"readwrite\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"LogTarget\" type=\"s\" access=\"readwrite\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"NNames\" type=\"u\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"NJobs\" type=\"u\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"NInstalledJobs\" type=\"u\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"NFailedJobs\" type=\"u\" access=\"read\"/>\n" \
966c66e34940001a40806142ecebaae61b478444Lennart Poettering " <property name=\"Progress\" type=\"d\" access=\"read\"/>\n" \
82bd6dddc4a363a9c3c6f41eb46eb171a80dca27Lennart Poettering " <property name=\"Environment\" type=\"as\" access=\"read\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <property name=\"ConfirmSpawn\" type=\"b\" access=\"read\"/>\n" \
82bd6dddc4a363a9c3c6f41eb46eb171a80dca27Lennart Poettering " <property name=\"ShowStatus\" type=\"b\" access=\"read\"/>\n" \
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering " <property name=\"UnitPath\" type=\"as\" access=\"read\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <property name=\"DefaultControllers\" type=\"as\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"DefaultStandardOutput\" type=\"s\" access=\"read\"/>\n" \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " <property name=\"DefaultStandardError\" type=\"s\" access=\"read\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <property name=\"RuntimeWatchdogUSec\" type=\"s\" access=\"readwrite\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <property name=\"ShutdownWatchdogUSec\" type=\"s\" access=\"readwrite\"/>\n" \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering " <property name=\"Virtualization\" type=\"s\" access=\"read\"/>\n"
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#define BUS_MANAGER_INTERFACE_END \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " </interface>\n"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering#define BUS_MANAGER_INTERFACE \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering BUS_MANAGER_INTERFACE_BEGIN \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering BUS_MANAGER_INTERFACE_METHODS \
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering BUS_MANAGER_INTERFACE_SIGNALS \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering BUS_MANAGER_INTERFACE_END
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering#define INTROSPECTION_BEGIN \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering "<node>\n" \
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering BUS_MANAGER_INTERFACE \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering BUS_PROPERTIES_INTERFACE \
95d46fcaa4f27bc5e675e8de39ab3acc4732e39bTom Gundersen BUS_PEER_INTERFACE \
95d46fcaa4f27bc5e675e8de39ab3acc4732e39bTom Gundersen BUS_INTROSPECTABLE_INTERFACE
039a8725fdff1d71e9efd28f27741601c5b4235cLennart Poettering
95d46fcaa4f27bc5e675e8de39ab3acc4732e39bTom Gundersen#define INTROSPECTION_END \
95d46fcaa4f27bc5e675e8de39ab3acc4732e39bTom Gundersen "</node>\n"
95d46fcaa4f27bc5e675e8de39ab3acc4732e39bTom Gundersen
95d46fcaa4f27bc5e675e8de39ab3acc4732e39bTom Gundersen#define INTERFACES_LIST \
7588460aaf6bd33f6c9bd5645916cfd8a862e9c4Tom Gundersen BUS_GENERIC_INTERFACES_LIST \
95d46fcaa4f27bc5e675e8de39ab3acc4732e39bTom Gundersen "org.freedesktop.systemd1.Manager\0"
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
ad867662936a4c7ab2c7116d804c272338801231Lennart Poetteringconst char bus_manager_interface[] _introspect_("Manager") = BUS_MANAGER_INTERFACE;
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering
ad867662936a4c7ab2c7116d804c272338801231Lennart Poetteringstatic DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_exec_output, exec_output, ExecOutput);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poetteringstatic int bus_manager_append_tainted(DBusMessageIter *i, const char *property, void *data) {
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering const char *t;
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering Manager *m = data;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char buf[LINE_MAX] = "", *e = buf, *p = NULL;
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering assert(i);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(property);
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering assert(m);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering if (m->taint_usr)
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering e = stpcpy(e, "split-usr:");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (readlink_malloc("/etc/mtab", &p) < 0)
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering e = stpcpy(e, "mtab-not-symlink:");
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering else
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(p);
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering
3339cb71d44c5198f9546f113674f06dc7b01a6fLennart Poettering if (access("/proc/cgroups", F_OK) < 0)
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering e = stpcpy(e, "cgroups-missing:");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (hwclock_is_localtime() > 0)
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering e = stpcpy(e, "local-hwclock:");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering /* remove the last ':' */
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (e != buf)
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering e[-1] = 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering t = buf;
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering return -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
931851e8e492a4d2715e22dcde50a5e7ccef4b49Lennart Poettering return 0;
51323288fc628a5cac50914df915545d685b793eLennart Poettering}
51323288fc628a5cac50914df915545d685b793eLennart Poettering
51323288fc628a5cac50914df915545d685b793eLennart Poetteringstatic int bus_manager_append_log_target(DBusMessageIter *i, const char *property, void *data) {
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering const char *t;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(i);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert(property);
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering t = log_target_to_string(log_get_target());
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return 0;
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int bus_manager_set_log_target(DBusMessageIter *i, const char *property, void *data) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering const char *t;
51323288fc628a5cac50914df915545d685b793eLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(i);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(property);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_message_iter_get_basic(i, &t);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return log_set_target_from_string(t);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poetteringstatic int bus_manager_append_log_level(DBusMessageIter *i, const char *property, void *data) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering char *t;
51323288fc628a5cac50914df915545d685b793eLennart Poettering int r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(i);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(property);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering r = log_level_to_string_alloc(log_get_max_level(), &t);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (r < 0)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = -ENOMEM;
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(t);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return r;
51323288fc628a5cac50914df915545d685b793eLennart Poettering}
51323288fc628a5cac50914df915545d685b793eLennart Poettering
51323288fc628a5cac50914df915545d685b793eLennart Poetteringstatic int bus_manager_set_log_level(DBusMessageIter *i, const char *property, void *data) {
51323288fc628a5cac50914df915545d685b793eLennart Poettering const char *t;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(i);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(property);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_message_iter_get_basic(i, &t);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return log_set_max_level_from_string(t);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int bus_manager_append_n_names(DBusMessageIter *i, const char *property, void *data) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Manager *m = data;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering uint32_t u;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(i);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(property);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(m);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
966c66e34940001a40806142ecebaae61b478444Lennart Poettering u = hashmap_size(m->units);
82bd6dddc4a363a9c3c6f41eb46eb171a80dca27Lennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
82bd6dddc4a363a9c3c6f41eb46eb171a80dca27Lennart Poettering return -ENOMEM;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return 0;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int bus_manager_append_n_jobs(DBusMessageIter *i, const char *property, void *data) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Manager *m = data;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering uint32_t u;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering assert(i);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering assert(property);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering assert(m);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering u = hashmap_size(m->jobs);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return -ENOMEM;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return 0;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering}
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poetteringstatic int bus_manager_append_progress(DBusMessageIter *i, const char *property, void *data) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering double d;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Manager *m = data;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering assert(i);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering assert(property);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering assert(m);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
4e2d538f33df8a425487aaa4facc23065a9bdaf7Lennart Poettering if (dual_timestamp_is_set(&m->finish_timestamp))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering d = 1.0;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering else
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering d = 1.0 - ((double) hashmap_size(m->jobs) / (double) m->n_installed_jobs);
4e2d538f33df8a425487aaa4facc23065a9bdaf7Lennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_DOUBLE, &d))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return -ENOMEM;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringstatic int bus_manager_append_virt(DBusMessageIter *i, const char *property, void *data) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering Manager *m = data;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *id = "";
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert(i);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert(property);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert(m);
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering detect_virtualization(&id);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &id))
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return 0;
703e4f5e39c019da8c002ba10bd450ce378c0e91Lennart Poettering}
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poetteringstatic DBusMessage *message_from_file_changes(
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBusMessage *m,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering UnitFileChange *changes,
7588460aaf6bd33f6c9bd5645916cfd8a862e9c4Tom Gundersen unsigned n_changes,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering int carries_install_info) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering DBusMessageIter iter, sub, sub2;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering DBusMessage *reply;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering unsigned i;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering reply = dbus_message_new_method_return(m);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!reply)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering dbus_message_iter_init_append(reply, &iter);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (carries_install_info >= 0) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering dbus_bool_t b;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering b = !!carries_install_info;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &b))
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(sss)", &sub))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering for (i = 0; i < n_changes; i++) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering const char *type, *path, *source;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering type = unit_file_change_type_to_string(changes[i].type);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering path = strempty(changes[i].path);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering source = strempty(changes[i].source);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
703e4f5e39c019da8c002ba10bd450ce378c0e91Lennart Poettering if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &type) ||
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &path) ||
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &source) ||
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering !dbus_message_iter_close_container(&sub, &sub2))
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
931851e8e492a4d2715e22dcde50a5e7ccef4b49Lennart Poettering if (!dbus_message_iter_close_container(&iter, &sub))
51323288fc628a5cac50914df915545d685b793eLennart Poettering goto oom;
51323288fc628a5cac50914df915545d685b793eLennart Poettering
51323288fc628a5cac50914df915545d685b793eLennart Poettering return reply;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringoom:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering dbus_message_unref(reply);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return NULL;
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt}
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringstatic int bus_manager_send_unit_files_changed(Manager *m) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering DBusMessage *s;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering int r;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering s = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering if (!s)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = bus_broadcast(m, s);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering dbus_message_unref(s);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
51323288fc628a5cac50914df915545d685b793eLennart Poettering return r;
51323288fc628a5cac50914df915545d685b793eLennart Poettering}
51323288fc628a5cac50914df915545d685b793eLennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringstatic int bus_manager_set_runtime_watchdog_usec(DBusMessageIter *i, const char *property, void *data) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering uint64_t *t = data;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert(i);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering assert(property);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
51323288fc628a5cac50914df915545d685b793eLennart Poettering dbus_message_iter_get_basic(i, t);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return watchdog_set_timeout(t);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering}
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
7b9f7afcc04e80b77a2567b0750aa2cd03c1a1cdLennart Poetteringstatic const char systemd_property_string[] =
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering PACKAGE_STRING "\0"
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SYSTEMD_FEATURES;
7b9f7afcc04e80b77a2567b0750aa2cd03c1a1cdLennart Poettering
7b9f7afcc04e80b77a2567b0750aa2cd03c1a1cdLennart Poetteringstatic const BusProperty bus_systemd_properties[] = {
c463eb783e5ad999d400180c69b912c54fa07ee1Lennart Poettering { "Version", bus_property_append_string, "s", 0 },
c463eb783e5ad999d400180c69b912c54fa07ee1Lennart Poettering { "Features", bus_property_append_string, "s", sizeof(PACKAGE_STRING) },
c463eb783e5ad999d400180c69b912c54fa07ee1Lennart Poettering { NULL, }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering};
51323288fc628a5cac50914df915545d685b793eLennart Poettering
51323288fc628a5cac50914df915545d685b793eLennart Poetteringstatic const BusProperty bus_manager_properties[] = {
51323288fc628a5cac50914df915545d685b793eLennart Poettering { "Tainted", bus_manager_append_tainted, "s", 0 },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "FirmwareTimestamp", bus_property_append_uint64, "t", offsetof(Manager, firmware_timestamp.realtime) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "FirmwareTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, firmware_timestamp.monotonic) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "LoaderTimestamp", bus_property_append_uint64, "t", offsetof(Manager, loader_timestamp.realtime) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "LoaderTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, loader_timestamp.monotonic) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "KernelTimestamp", bus_property_append_uint64, "t", offsetof(Manager, kernel_timestamp.realtime) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "KernelTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, kernel_timestamp.monotonic) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "InitRDTimestamp", bus_property_append_uint64, "t", offsetof(Manager, initrd_timestamp.realtime) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "InitRDTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, initrd_timestamp.monotonic) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "UserspaceTimestamp", bus_property_append_uint64, "t", offsetof(Manager, userspace_timestamp.realtime) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "UserspaceTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, userspace_timestamp.monotonic) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "FinishTimestamp", bus_property_append_uint64, "t", offsetof(Manager, finish_timestamp.realtime) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "FinishTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, finish_timestamp.monotonic) },
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering { "LogLevel", bus_manager_append_log_level, "s", 0, false, bus_manager_set_log_level },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "LogTarget", bus_manager_append_log_target, "s", 0, false, bus_manager_set_log_target },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "NNames", bus_manager_append_n_names, "u", 0 },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "NJobs", bus_manager_append_n_jobs, "u", 0 },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "NInstalledJobs", bus_property_append_uint32, "u", offsetof(Manager, n_installed_jobs) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "NFailedJobs", bus_property_append_uint32, "u", offsetof(Manager, n_failed_jobs) },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "Progress", bus_manager_append_progress, "d", 0 },
966c66e34940001a40806142ecebaae61b478444Lennart Poettering { "Environment", bus_property_append_strv, "as", offsetof(Manager, environment), true },
82bd6dddc4a363a9c3c6f41eb46eb171a80dca27Lennart Poettering { "ConfirmSpawn", bus_property_append_bool, "b", offsetof(Manager, confirm_spawn) },
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering { "ShowStatus", bus_property_append_bool, "b", offsetof(Manager, show_status) },
82bd6dddc4a363a9c3c6f41eb46eb171a80dca27Lennart Poettering { "UnitPath", bus_property_append_strv, "as", offsetof(Manager, lookup_paths.unit_path), true },
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering { "ControlGroupHierarchy", bus_property_append_string, "s", offsetof(Manager, cgroup_hierarchy), true },
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering { "DefaultControllers", bus_property_append_strv, "as", offsetof(Manager, default_controllers), true },
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering { "DefaultStandardOutput", bus_manager_append_exec_output, "s", offsetof(Manager, default_std_output) },
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering { "DefaultStandardError", bus_manager_append_exec_output, "s", offsetof(Manager, default_std_error) },
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering { "RuntimeWatchdogUSec", bus_property_append_usec, "t", offsetof(Manager, runtime_watchdog), false, bus_manager_set_runtime_watchdog_usec },
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering { "ShutdownWatchdogUSec", bus_property_append_usec, "t", offsetof(Manager, shutdown_watchdog), false, bus_property_set_usec },
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering { "Virtualization", bus_manager_append_virt, "s", 0, },
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering { NULL, }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering};
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poetteringstatic DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering _cleanup_free_ char * path = NULL;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Manager *m = data;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering int r;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBusError error;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering JobType job_type = _JOB_TYPE_INVALID;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering bool reload_if_possible = false;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *member;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering assert(connection);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering assert(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering assert(m);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_error_init(&error);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering member = dbus_message_get_member(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnit")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *name;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Unit *u;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_get_args(
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering message,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering &error,
703e4f5e39c019da8c002ba10bd450ce378c0e91Lennart Poettering DBUS_TYPE_STRING, &name,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_INVALID))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering u = manager_get_unit(m, name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!u) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "status");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering path = unit_dbus_path(u);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!path)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_append_args(
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_OBJECT_PATH, &path,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_INVALID))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitByPID")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Unit *u;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering uint32_t pid;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_get_args(
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering message,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering &error,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_UINT32, &pid,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_INVALID))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering u = cgroup_unit_by_pid(m, (pid_t) pid);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!u) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "No unit for PID %lu is loaded.", (unsigned long) pid);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "status");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering path = unit_dbus_path(u);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!path)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
703e4f5e39c019da8c002ba10bd450ce378c0e91Lennart Poettering if (!dbus_message_append_args(
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_OBJECT_PATH, &path,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_INVALID))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "LoadUnit")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *name;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Unit *u;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_get_args(
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering message,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering &error,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_STRING, &name,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_INVALID))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering r = manager_load_unit(m, name, NULL, &error, &u);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (r < 0)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, r);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "status");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering path = unit_dbus_path(u);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!path)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_append_args(
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_OBJECT_PATH, &path,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_INVALID))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnit"))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering job_type = JOB_START;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnitReplace"))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering job_type = JOB_START;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StopUnit"))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering job_type = JOB_STOP;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadUnit"))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering job_type = JOB_RELOAD;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "RestartUnit"))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering job_type = JOB_RESTART;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "TryRestartUnit"))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering job_type = JOB_TRY_RESTART;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrRestartUnit")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reload_if_possible = true;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering job_type = JOB_RESTART;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrTryRestartUnit")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reload_if_possible = true;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering job_type = JOB_TRY_RESTART;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KillUnit")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *name, *swho;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering int32_t signo;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Unit *u;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering KillWho who;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_get_args(
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering message,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering &error,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_STRING, &name,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_STRING, &swho,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_INT32, &signo,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_INVALID))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (isempty(swho))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering who = KILL_ALL;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering else {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering who = kill_who_from_string(swho);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (who < 0)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (signo <= 0 || signo >= _NSIG)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering u = manager_get_unit(m, name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!u) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "stop");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering r = unit_kill(u, who, signo, &error);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (r < 0)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, r);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetJob")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering uint32_t id;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Job *j;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_get_args(
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering message,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering &error,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_UINT32, &id,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_INVALID))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering j = manager_get_job(m, id);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!j) {
703e4f5e39c019da8c002ba10bd450ce378c0e91Lennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_UNIT_ACCESS_CHECK(j->unit, connection, message, "status");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering path = job_dbus_path(j);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!path)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_append_args(
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_OBJECT_PATH, &path,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_INVALID))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "CancelJob")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering uint32_t id;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Job *j;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_get_args(
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering message,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering &error,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_UINT32, &id,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_INVALID))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering j = manager_get_job(m, id);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!j) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_UNIT_ACCESS_CHECK(j->unit, connection, message, "stop");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering job_finish_and_invalidate(j, JOB_CANCELED, true);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ClearJobs")) {
703e4f5e39c019da8c002ba10bd450ce378c0e91Lennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_ACCESS_CHECK(connection, message, "reboot");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering manager_clear_jobs(m);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailed")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_ACCESS_CHECK(connection, message, "reload");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering manager_reset_failed(m);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailedUnit")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *name;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Unit *u;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_get_args(
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering message,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering &error,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_STRING, &name,
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBUS_TYPE_INVALID))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering u = manager_get_unit(m, name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!u) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "reload");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering unit_reset_failed(u);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
931851e8e492a4d2715e22dcde50a5e7ccef4b49Lennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetUnitControlGroups")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *name;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Unit *u;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBusMessageIter iter;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_init(message, &iter))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering r = bus_iter_get_basic_and_next(&iter, DBUS_TYPE_STRING, &name, true);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (r < 0)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering u = manager_get_unit(m, name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!u) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "start");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering r = bus_unit_cgroup_set(u, &iter);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (r < 0)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
7588460aaf6bd33f6c9bd5645916cfd8a862e9c4Tom Gundersen if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetUnitControlGroups")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *name;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Unit *u;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBusMessageIter iter;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_init(message, &iter))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering r = bus_iter_get_basic_and_next(&iter, DBUS_TYPE_STRING, &name, true);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (r < 0)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering u = manager_get_unit(m, name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!u) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "stop");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering r = bus_unit_cgroup_unset(u, &iter);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (r < 0)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetUnitControlGroupAttributes")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *name;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Unit *u;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBusMessageIter iter;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_init(message, &iter))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering r = bus_iter_get_basic_and_next(&iter, DBUS_TYPE_STRING, &name, true);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (r < 0)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering u = manager_get_unit(m, name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!u) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "start");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering r = bus_unit_cgroup_attribute_set(u, &iter);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (r < 0)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetUnitControlGroupAttributes")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *name;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Unit *u;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBusMessageIter iter;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_init(message, &iter))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering r = bus_iter_get_basic_and_next(&iter, DBUS_TYPE_STRING, &name, true);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (r < 0)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering u = manager_get_unit(m, name);
703e4f5e39c019da8c002ba10bd450ce378c0e91Lennart Poettering if (!u) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
7588460aaf6bd33f6c9bd5645916cfd8a862e9c4Tom Gundersen SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "stop");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering r = bus_unit_cgroup_attribute_unset(u, &iter);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (r < 0)
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitControlGroupAttributes")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *name;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Unit *u;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBusMessageIter iter;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering _cleanup_strv_free_ char **list = NULL;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_init(message, &iter))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering r = bus_iter_get_basic_and_next(&iter, DBUS_TYPE_STRING, &name, true);
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering if (r < 0)
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering u = manager_get_unit(m, name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!u) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "status");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering r = bus_unit_cgroup_attribute_get(u, &iter, &list);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (r < 0)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering reply = dbus_message_new_method_return(message);
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering if (!reply)
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering goto oom;
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering dbus_message_iter_init_append(reply, &iter);
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering if (bus_append_strv_iter(&iter, list) < 0)
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering goto oom;
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListUnits")) {
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering DBusMessageIter iter, sub;
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering Iterator i;
9a1f0c283bac56eb26a2fa02d62e0e9ece82f25aLennart Poettering Unit *u;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *k;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_ACCESS_CHECK(connection, message, "status");
703e4f5e39c019da8c002ba10bd450ce378c0e91Lennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_message_iter_init_append(reply, &iter);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ssssssouso)", &sub))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering HASHMAP_FOREACH_KEY(u, k, m->units, i) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering char *u_path, *j_path;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *description, *load_state, *active_state, *sub_state, *sjob_type, *following;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBusMessageIter sub2;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering uint32_t job_id;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Unit *f;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (k != u->id)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering continue;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering description = unit_description(u);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering load_state = unit_load_state_to_string(u->load_state);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering active_state = unit_active_state_to_string(unit_active_state(u));
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering sub_state = unit_sub_state_to_string(u);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering f = unit_following(u);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering following = f ? f->id : "";
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering u_path = unit_dbus_path(u);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!u_path)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (u->job) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering job_id = (uint32_t) u->job->id;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!(j_path = job_dbus_path(u->job))) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering free(u_path);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering sjob_type = job_type_to_string(u->job->type);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering } else {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering job_id = 0;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering j_path = u_path;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering sjob_type = "";
7e8131e9c6c150732503899a092206578fdc13deLennart Poettering }
7e8131e9c6c150732503899a092206578fdc13deLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &u->id) ||
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &description) ||
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &load_state) ||
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &active_state) ||
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sub_state) ||
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &following) ||
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path) ||
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &job_id) ||
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sjob_type) ||
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path)) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering free(u_path);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (u->job)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering free(j_path);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering free(u_path);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (u->job)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering free(j_path);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_close_container(&sub, &sub2))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering }
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_close_container(&iter, &sub))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListJobs")) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBusMessageIter iter, sub;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering Iterator i;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering Job *j;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering SELINUX_ACCESS_CHECK(connection, message, "status");
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering reply = dbus_message_new_method_return(message);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!reply)
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering dbus_message_iter_init_append(reply, &iter);
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(usssoo)", &sub))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering HASHMAP_FOREACH(j, m->jobs, i) {
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering char *u_path, *j_path;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering const char *state, *type;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering uint32_t id;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering DBusMessageIter sub2;
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering goto oom;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering id = (uint32_t) j->id;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering state = job_state_to_string(j->state);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering type = job_type_to_string(j->type);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering j_path = job_dbus_path(j);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!j_path)
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering u_path = unit_dbus_path(j->unit);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!u_path) {
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering free(j_path);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering }
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &id) ||
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &j->unit->id) ||
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &type) ||
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &state) ||
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path) ||
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path)) {
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering free(j_path);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering free(u_path);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering }
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering free(j_path);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering free(u_path);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!dbus_message_iter_close_container(&sub, &sub2))
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering }
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!dbus_message_iter_close_container(&iter, &sub))
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Subscribe")) {
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering char *client;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering Set *s;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering SELINUX_ACCESS_CHECK(connection, message, "status");
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering s = BUS_CONNECTION_SUBSCRIBED(m, connection);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!s) {
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering s = set_new(string_hash_func, string_compare_func);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!s)
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!dbus_connection_set_data(connection, m->subscribed_data_slot, s, NULL)) {
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering set_free(s);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering }
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering }
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering client = strdup(bus_message_get_sender_with_fallback(message));
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!client)
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering r = set_put(s, client);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (r < 0) {
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering free(client);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering return bus_send_error_reply(connection, message, NULL, r);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering }
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering reply = dbus_message_new_method_return(message);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!reply)
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Unsubscribe")) {
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering char *client;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering SELINUX_ACCESS_CHECK(connection, message, "status");
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) bus_message_get_sender_with_fallback(message));
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!client) {
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering dbus_set_error(&error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering }
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering free(client);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering reply = dbus_message_new_method_return(message);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!reply)
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Dump")) {
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering FILE *f;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering char *dump = NULL;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering size_t size;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering SELINUX_ACCESS_CHECK(connection, message, "status");
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering reply = dbus_message_new_method_return(message);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!reply)
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering f = open_memstream(&dump, &size);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!f)
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering manager_dump_units(m, f, NULL);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering manager_dump_jobs(m, f, NULL);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (ferror(f)) {
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering fclose(f);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering free(dump);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering }
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering fclose(f);
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &dump, DBUS_TYPE_INVALID)) {
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering free(dump);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering goto oom;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering }
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering free(dump);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "CreateSnapshot")) {
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering const char *name;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering dbus_bool_t cleanup;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering Snapshot *s;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering SELINUX_ACCESS_CHECK(connection, message, "start");
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering if (!dbus_message_get_args(
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering message,
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering &error,
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering DBUS_TYPE_STRING, &name,
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering DBUS_TYPE_BOOLEAN, &cleanup,
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering DBUS_TYPE_INVALID))
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering if (isempty(name))
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering name = NULL;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering r = snapshot_create(m, name, cleanup, &error, &s);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering if (r < 0)
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering return bus_send_error_reply(connection, message, &error, r);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering reply = dbus_message_new_method_return(message);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering if (!reply)
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering goto oom;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering path = unit_dbus_path(UNIT(s));
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering if (!path)
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering goto oom;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering if (!dbus_message_append_args(
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering reply,
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering DBUS_TYPE_OBJECT_PATH, &path,
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering DBUS_TYPE_INVALID))
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering goto oom;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "RemoveSnapshot")) {
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering const char *name;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering Unit *u;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering if (!dbus_message_get_args(
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering message,
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering &error,
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering DBUS_TYPE_STRING, &name,
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering DBUS_TYPE_INVALID))
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering u = manager_get_unit(m, name);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering if (!u) {
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s does not exist.", name);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering }
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering if (u->type != UNIT_SNAPSHOT) {
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not a snapshot.", name);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering return bus_send_error_reply(connection, message, &error, -ENOENT);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering }
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "stop");
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering snapshot_remove(SNAPSHOT(u));
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering reply = dbus_message_new_method_return(message);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering if (!reply)
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering goto oom;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering char *introspection = NULL;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering FILE *f;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering Iterator i;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering Unit *u;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering Job *j;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering const char *k;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering size_t size;
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering SELINUX_ACCESS_CHECK(connection, message, "status");
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering reply = dbus_message_new_method_return(message);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!reply)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering /* We roll our own introspection code here, instead of
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering * relying on bus_default_message_handler() because we
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering * need to generate our introspection string
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering * dynamically. */
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
7f220d94a938a99c77400fa0ca30485e269bae7cLennart Poettering f = open_memstream(&introspection, &size);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (!f)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering goto oom;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
45ec7efb6c2560c80dfa752bc9d3733749dc52cbLennart Poettering fputs(INTROSPECTION_BEGIN, f);
a150ff5e4e2481eb28d6ed6e0d3e176623e25f5aLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering HASHMAP_FOREACH_KEY(u, k, m->units, i) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char *p;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (k != u->id)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering continue;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering p = bus_path_escape(k);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!p) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering fclose(f);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(introspection);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering fprintf(f, "<node name=\"unit/%s\"/>", p);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(p);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering }
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering HASHMAP_FOREACH(j, m->jobs, i)
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering fprintf(f, "<node name=\"job/%lu\"/>", (unsigned long) j->id);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering fputs(INTROSPECTION_END, f);
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering if (ferror(f)) {
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering fclose(f);
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt free(introspection);
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering goto oom;
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering }
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering fclose(f);
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering if (!introspection)
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering goto oom;
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID)) {
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering free(introspection);
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering goto oom;
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(introspection);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reload")) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering SELINUX_ACCESS_CHECK(connection, message, "reload");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(!m->queued_message);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Instead of sending the reply back right away, we
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * just remember that we need to and then send it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * after the reload is finished. That way the caller
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * knows when the reload finished. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt m->queued_message = dbus_message_new_method_return(message);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!m->queued_message)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering goto oom;
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt m->queued_message_connection = connection;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering m->exit_code = MANAGER_RELOAD;
aa4a9deb7d3db95ffb1fd18791be66f58d06a69eLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reexecute")) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering SELINUX_ACCESS_CHECK(connection, message, "reload");
4d1cf1e229c9bdbc44778c0863eaad918f5724e7Lennart Poettering
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt /* We don't send a reply back here, the client should
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt * just wait for us disconnecting. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering m->exit_code = MANAGER_REEXECUTE;
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering SELINUX_ACCESS_CHECK(connection, message, "halt");
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt if (m->running_as == SYSTEMD_SYSTEM) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering return bus_send_error_reply(connection, message, &error, -ENOTSUP);
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering }
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering reply = dbus_message_new_method_return(message);
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering if (!reply)
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering goto oom;
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering m->exit_code = MANAGER_EXIT;
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reboot")) {
902bb5d8abb2a7d258741828d212ca549ab16950Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering SELINUX_ACCESS_CHECK(connection, message, "reboot");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
if (m->running_as != SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
m->exit_code = MANAGER_REBOOT;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "PowerOff")) {
SELINUX_ACCESS_CHECK(connection, message, "halt");
if (m->running_as != SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
m->exit_code = MANAGER_POWEROFF;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Halt")) {
SELINUX_ACCESS_CHECK(connection, message, "halt");
if (m->running_as != SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Halting is only supported for system managers.");
return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
m->exit_code = MANAGER_HALT;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KExec")) {
SELINUX_ACCESS_CHECK(connection, message, "reboot");
if (m->running_as != SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "kexec is only supported for system managers.");
return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
m->exit_code = MANAGER_KEXEC;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SwitchRoot")) {
const char *switch_root, *switch_root_init;
char *u, *v;
int k;
SELINUX_ACCESS_CHECK(connection, message, "reboot");
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &switch_root,
DBUS_TYPE_STRING, &switch_root_init,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
if (path_equal(switch_root, "/") || !path_is_absolute(switch_root))
return bus_send_error_reply(connection, message, NULL, -EINVAL);
if (!isempty(switch_root_init) && !path_is_absolute(switch_root_init))
return bus_send_error_reply(connection, message, NULL, -EINVAL);
if (m->running_as != SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Switching root is only supported for system managers.");
return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
/* Safety check */
if (isempty(switch_root_init))
k = access(switch_root, F_OK);
else {
char *p;
p = strjoin(switch_root, "/", switch_root_init, NULL);
if (!p)
goto oom;
k = access(p, X_OK);
free(p);
}
if (k < 0)
return bus_send_error_reply(connection, message, NULL, -errno);
u = strdup(switch_root);
if (!u)
goto oom;
if (!isempty(switch_root_init)) {
v = strdup(switch_root_init);
if (!v) {
free(u);
goto oom;
}
} else
v = NULL;
free(m->switch_root);
free(m->switch_root_init);
m->switch_root = u;
m->switch_root_init = v;
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
m->exit_code = MANAGER_SWITCH_ROOT;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetEnvironment")) {
_cleanup_strv_free_ char **l = NULL;
char **e = NULL;
SELINUX_ACCESS_CHECK(connection, message, "reboot");
r = bus_parse_strv(message, &l);
if (r == -ENOMEM)
goto oom;
if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
if (!strv_env_is_valid(l))
return bus_send_error_reply(connection, message, NULL, -EINVAL);
e = strv_env_merge(2, m->environment, l);
if (!e)
goto oom;
reply = dbus_message_new_method_return(message);
if (!reply) {
strv_free(e);
goto oom;
}
strv_free(m->environment);
m->environment = e;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetEnvironment")) {
_cleanup_strv_free_ char **l = NULL;
char **e = NULL;
SELINUX_ACCESS_CHECK(connection, message, "reboot");
r = bus_parse_strv(message, &l);
if (r == -ENOMEM)
goto oom;
if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
if (!strv_env_name_or_assignment_is_valid(l))
return bus_send_error_reply(connection, message, NULL, -EINVAL);
e = strv_env_delete(m->environment, 1, l);
if (!e)
goto oom;
reply = dbus_message_new_method_return(message);
if (!reply) {
strv_free(e);
goto oom;
}
strv_free(m->environment);
m->environment = e;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetAndSetEnvironment")) {
_cleanup_strv_free_ char **l_set = NULL, **l_unset = NULL, **e = NULL;
char **f = NULL;
DBusMessageIter iter;
SELINUX_ACCESS_CHECK(connection, message, "reboot");
if (!dbus_message_iter_init(message, &iter))
goto oom;
r = bus_parse_strv_iter(&iter, &l_unset);
if (r == -ENOMEM)
goto oom;
if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
if (!strv_env_name_or_assignment_is_valid(l_unset))
return bus_send_error_reply(connection, message, NULL, -EINVAL);
if (!dbus_message_iter_next(&iter))
return bus_send_error_reply(connection, message, NULL, -EINVAL);
r = bus_parse_strv_iter(&iter, &l_set);
if (r == -ENOMEM)
goto oom;
if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
if (!strv_env_is_valid(l_set))
return bus_send_error_reply(connection, message, NULL, -EINVAL);
e = strv_env_delete(m->environment, 1, l_unset);
if (!e)
goto oom;
f = strv_env_merge(2, e, l_set);
if (!f)
goto oom;
reply = dbus_message_new_method_return(message);
if (!reply) {
strv_free(f);
goto oom;
}
strv_free(m->environment);
m->environment = f;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListUnitFiles")) {
DBusMessageIter iter, sub, sub2;
Hashmap *h;
Iterator i;
UnitFileList *item;
SELINUX_ACCESS_CHECK(connection, message, "status");
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
h = hashmap_new(string_hash_func, string_compare_func);
if (!h)
goto oom;
r = unit_file_get_list(m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);
if (r < 0) {
unit_file_list_free(h);
return bus_send_error_reply(connection, message, NULL, r);
}
dbus_message_iter_init_append(reply, &iter);
if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ss)", &sub)) {
unit_file_list_free(h);
goto oom;
}
HASHMAP_FOREACH(item, h, i) {
const char *state;
state = unit_file_state_to_string(item->state);
assert(state);
if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &item->path) ||
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &state) ||
!dbus_message_iter_close_container(&sub, &sub2)) {
unit_file_list_free(h);
goto oom;
}
}
unit_file_list_free(h);
if (!dbus_message_iter_close_container(&iter, &sub))
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitFileState")) {
const char *name;
UnitFileState state;
const char *s;
SELINUX_ACCESS_CHECK(connection, message, "status");
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
state = unit_file_get_state(m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, name);
if (state < 0)
return bus_send_error_reply(connection, message, NULL, state);
s = unit_file_state_to_string(state);
assert(s);
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
if (!dbus_message_append_args(
reply,
DBUS_TYPE_STRING, &s,
DBUS_TYPE_INVALID))
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "EnableUnitFiles") ||
dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReenableUnitFiles") ||
dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "LinkUnitFiles") ||
dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "PresetUnitFiles") ||
dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "MaskUnitFiles")) {
char **l = NULL;
DBusMessageIter iter;
UnitFileScope scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
UnitFileChange *changes = NULL;
unsigned n_changes = 0;
dbus_bool_t runtime, force;
int carries_install_info = -1;
SELINUX_ACCESS_CHECK(connection, message, streq(member, "MaskUnitFiles") ? "disable" : "enable");
if (!dbus_message_iter_init(message, &iter))
goto oom;
r = bus_parse_strv_iter(&iter, &l);
if (r < 0) {
if (r == -ENOMEM)
goto oom;
return bus_send_error_reply(connection, message, NULL, r);
}
if (!dbus_message_iter_next(&iter) ||
bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &runtime, true) < 0 ||
bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &force, false) < 0) {
strv_free(l);
return bus_send_error_reply(connection, message, NULL, -EIO);
}
if (streq(member, "EnableUnitFiles")) {
r = unit_file_enable(scope, runtime, NULL, l, force, &changes, &n_changes);
carries_install_info = r;
} else if (streq(member, "ReenableUnitFiles")) {
r = unit_file_reenable(scope, runtime, NULL, l, force, &changes, &n_changes);
carries_install_info = r;
} else if (streq(member, "LinkUnitFiles"))
r = unit_file_link(scope, runtime, NULL, l, force, &changes, &n_changes);
else if (streq(member, "PresetUnitFiles")) {
r = unit_file_preset(scope, runtime, NULL, l, force, &changes, &n_changes);
carries_install_info = r;
} else if (streq(member, "MaskUnitFiles"))
r = unit_file_mask(scope, runtime, NULL, l, force, &changes, &n_changes);
else
assert_not_reached("Uh? Wrong method");
strv_free(l);
bus_manager_send_unit_files_changed(m);
if (r < 0) {
unit_file_changes_free(changes, n_changes);
return bus_send_error_reply(connection, message, NULL, r);
}
reply = message_from_file_changes(message, changes, n_changes, carries_install_info);
unit_file_changes_free(changes, n_changes);
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "DisableUnitFiles") ||
dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnmaskUnitFiles")) {
char **l = NULL;
DBusMessageIter iter;
UnitFileScope scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
UnitFileChange *changes = NULL;
unsigned n_changes = 0;
dbus_bool_t runtime;
SELINUX_ACCESS_CHECK(connection, message, streq(member, "UnmaskUnitFiles") ? "enable" : "disable");
if (!dbus_message_iter_init(message, &iter))
goto oom;
r = bus_parse_strv_iter(&iter, &l);
if (r < 0) {
if (r == -ENOMEM)
goto oom;
return bus_send_error_reply(connection, message, NULL, r);
}
if (!dbus_message_iter_next(&iter) ||
bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &runtime, false) < 0) {
strv_free(l);
return bus_send_error_reply(connection, message, NULL, -EIO);
}
if (streq(member, "DisableUnitFiles"))
r = unit_file_disable(scope, runtime, NULL, l, &changes, &n_changes);
else if (streq(member, "UnmaskUnitFiles"))
r = unit_file_unmask(scope, runtime, NULL, l, &changes, &n_changes);
else
assert_not_reached("Uh? Wrong method");
strv_free(l);
bus_manager_send_unit_files_changed(m);
if (r < 0) {
unit_file_changes_free(changes, n_changes);
return bus_send_error_reply(connection, message, NULL, r);
}
reply = message_from_file_changes(message, changes, n_changes, -1);
unit_file_changes_free(changes, n_changes);
if (!reply)
goto oom;
} else {
const BusBoundProperties bps[] = {
{ "org.freedesktop.systemd1.Manager", bus_systemd_properties, systemd_property_string },
{ "org.freedesktop.systemd1.Manager", bus_manager_properties, m },
{ NULL, }
};
SELINUX_ACCESS_CHECK(connection, message, "status");
return bus_default_message_handler(connection, message, NULL, INTERFACES_LIST, bps);
}
if (job_type != _JOB_TYPE_INVALID) {
const char *name, *smode, *old_name = NULL;
JobMode mode;
Unit *u;
dbus_bool_t b;
if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnitReplace"))
b = dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &old_name,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INVALID);
else
b = dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INVALID);
if (!b)
return bus_send_error_reply(connection, message, &error, -EINVAL);
if (old_name) {
u = manager_get_unit(m, old_name);
if (!u || !u->job || u->job->type != JOB_START) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
return bus_send_error_reply(connection, message, &error, -ENOENT);
}
}
mode = job_mode_from_string(smode);
if (mode < 0) {
dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
return bus_send_error_reply(connection, message, &error, -EINVAL);
}
r = manager_load_unit(m, name, NULL, &error, &u);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
return bus_unit_queue_job(connection, message, u, job_type, mode, reload_if_possible);
}
if (reply)
if (!dbus_connection_send(connection, reply, NULL))
goto oom;
return DBUS_HANDLER_RESULT_HANDLED;
oom:
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
const DBusObjectPathVTable bus_manager_vtable = {
.message_function = bus_manager_message_handler
};