dbus-execute.c revision 8600c525cb1420570e7670c963abd19c5696b683
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering This file is part of systemd.
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering Copyright 2010 Lennart Poettering
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering systemd is free software; you can redistribute it and/or modify it
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering under the terms of the GNU Lesser General Public License as published by
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering (at your option) any later version.
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering systemd is distributed in the hope that it will be useful, but
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering Lesser General Public License for more details.
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering You should have received a copy of the GNU Lesser General Public License
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart PoetteringDEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_kill_mode, kill_mode, KillMode);
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart PoetteringDEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_input, exec_input, ExecInput);
b1d4f8e154bf61b5de1b27461ef8e9c8c5e838a1Lennart PoetteringDEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_output, exec_output, ExecOutput);
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poetteringint bus_execute_append_env_files(DBusMessageIter *i, const char *property, void *data) {
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "(sb)", &sub))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &fn) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_BOOLEAN, &b) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_close_container(&sub, &sub2))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_close_container(i, &sub))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poetteringint bus_execute_append_oom_score_adjust(DBusMessageIter *i, const char *property, void *data) {
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (read_one_line_file("/proc/self/oom_score_adj", &t) >= 0) {
03976f7b4a84b8b1492a549a3470b2bba8f37008Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n))
634af5665fda8776d22624d947c8de830e30a874Lennart Poetteringint bus_execute_append_nice(DBusMessageIter *i, const char *property, void *data) {
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poetteringint bus_execute_append_ioprio(DBusMessageIter *i, const char *property, void *data) {
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poetteringint bus_execute_append_cpu_sched_policy(DBusMessageIter *i, const char *property, void *data) {
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poetteringint bus_execute_append_cpu_sched_priority(DBusMessageIter *i, const char *property, void *data) {
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (sched_getparam(0, &p) >= 0)
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &n))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poetteringint bus_execute_append_affinity(DBusMessageIter *i, const char *property, void *data) {
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "y", &sub))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering b = dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &c->cpuset, CPU_ALLOC_SIZE(c->cpuset_ncpus));
634af5665fda8776d22624d947c8de830e30a874Lennart Poettering b = dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &c->cpuset, 0);
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_close_container(i, &sub))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poetteringint bus_execute_append_timer_slack_nsec(DBusMessageIter *i, const char *property, void *data) {
e70df46b9721a3d025e7a0b4ffb5893cbde5e55dLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poetteringint bus_execute_append_capability_bs(DBusMessageIter *i, const char *property, void *data) {
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering /* We store this negated internally, to match the kernel, but
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering * we expose it normalized. */
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering return bus_property_append_uint64(i, property, &inverted);
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poetteringint bus_execute_append_capabilities(DBusMessageIter *i, const char *property, void *data) {
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering const char *s;
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering s = t = cap_to_text(c->capabilities, NULL);
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering b = dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &s);
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poetteringint bus_execute_append_rlimits(DBusMessageIter *i, const char *property, void *data) {
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering assert_se((r = rlimit_from_string(property)) >= 0);
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
9d485985338a46b8cb1acdf1af6c1eb2e88acfeeLennart Poetteringint bus_execute_append_command(DBusMessageIter *i, const char *property, void *data) {
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "(sasbttttuii)", &sub))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &c->path) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_open_container(&sub2, DBUS_TYPE_ARRAY, "s", &sub3))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_append_basic(&sub3, DBUS_TYPE_STRING, l))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering status = (int32_t) c->exec_status.status;
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_close_container(&sub2, &sub3) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_BOOLEAN, &b) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &c->exec_status.start_timestamp.realtime) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &c->exec_status.start_timestamp.monotonic) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &c->exec_status.exit_timestamp.realtime) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &c->exec_status.exit_timestamp.monotonic) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &pid) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_INT32, &code) ||
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_INT32, &status))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_close_container(&sub, &sub2))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering if (!dbus_message_iter_close_container(i, &sub))
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poetteringconst BusProperty bus_exec_context_properties[] = {
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "Environment", bus_property_append_strv, "as", offsetof(ExecContext, environment), true },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "EnvironmentFiles", bus_execute_append_env_files, "a(sb)", offsetof(ExecContext, environment_files), true },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "UMask", bus_property_append_mode, "u", offsetof(ExecContext, umask) },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitCPU", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitFSIZE", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitDATA", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitSTACK", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitCORE", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitRSS", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitNOFILE", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitAS", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitNPROC", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitMEMLOCK", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitLOCKS", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitSIGPENDING", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitMSGQUEUE", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitNICE", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitRTPRIO", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "LimitRTTIME", bus_execute_append_rlimits, "t", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "WorkingDirectory", bus_property_append_string, "s", offsetof(ExecContext, working_directory), true },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "RootDirectory", bus_property_append_string, "s", offsetof(ExecContext, root_directory), true },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "OOMScoreAdjust", bus_execute_append_oom_score_adjust, "i", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "Nice", bus_execute_append_nice, "i", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "IOScheduling", bus_execute_append_ioprio, "i", 0 },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "CPUSchedulingPolicy", bus_execute_append_cpu_sched_policy, "i", 0 },
e70df46b9721a3d025e7a0b4ffb5893cbde5e55dLennart Poettering { "CPUSchedulingPriority", bus_execute_append_cpu_sched_priority, "i", 0 },
e70df46b9721a3d025e7a0b4ffb5893cbde5e55dLennart Poettering { "CPUAffinity", bus_execute_append_affinity, "ay", 0 },
e70df46b9721a3d025e7a0b4ffb5893cbde5e55dLennart Poettering { "TimerSlackNSec", bus_execute_append_timer_slack_nsec, "t", 0 },
e70df46b9721a3d025e7a0b4ffb5893cbde5e55dLennart Poettering { "CPUSchedulingResetOnFork", bus_property_append_bool, "b", offsetof(ExecContext, cpu_sched_reset_on_fork) },
e70df46b9721a3d025e7a0b4ffb5893cbde5e55dLennart Poettering { "NonBlocking", bus_property_append_bool, "b", offsetof(ExecContext, non_blocking) },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "StandardInput", bus_execute_append_input, "s", offsetof(ExecContext, std_input) },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "StandardOutput", bus_execute_append_output, "s", offsetof(ExecContext, std_output) },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "StandardError", bus_execute_append_output, "s", offsetof(ExecContext, std_error) },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "TTYPath", bus_property_append_string, "s", offsetof(ExecContext, tty_path), true },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "TTYReset", bus_property_append_bool, "b", offsetof(ExecContext, tty_reset) },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "TTYVHangup", bus_property_append_bool, "b", offsetof(ExecContext, tty_vhangup) },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "TTYVTDisallocate", bus_property_append_bool, "b", offsetof(ExecContext, tty_vt_disallocate) },
cabb0bc6b1a4ec57e108dc99364687d7c4f9670fLennart Poettering { "SyslogPriority", bus_property_append_int, "i", offsetof(ExecContext, syslog_priority) },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "SyslogIdentifier", bus_property_append_string, "s", offsetof(ExecContext, syslog_identifier), true },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "SyslogLevelPrefix", bus_property_append_bool, "b", offsetof(ExecContext, syslog_level_prefix) },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "Capabilities", bus_execute_append_capabilities, "s", 0 },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "SecureBits", bus_property_append_int, "i", offsetof(ExecContext, secure_bits) },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "CapabilityBoundingSet", bus_execute_append_capability_bs, "t", offsetof(ExecContext, capability_bounding_set_drop) },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "User", bus_property_append_string, "s", offsetof(ExecContext, user), true },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "Group", bus_property_append_string, "s", offsetof(ExecContext, group), true },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "SupplementaryGroups", bus_property_append_strv, "as", offsetof(ExecContext, supplementary_groups), true },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "TCPWrapName", bus_property_append_string, "s", offsetof(ExecContext, tcpwrap_name), true },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "PAMName", bus_property_append_string, "s", offsetof(ExecContext, pam_name), true },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "ReadWriteDirectories", bus_property_append_strv, "as", offsetof(ExecContext, read_write_dirs), true },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "ReadOnlyDirectories", bus_property_append_strv, "as", offsetof(ExecContext, read_only_dirs), true },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "InaccessibleDirectories", bus_property_append_strv, "as", offsetof(ExecContext, inaccessible_dirs), true },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "MountFlags", bus_property_append_ul, "t", offsetof(ExecContext, mount_flags) },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "PrivateTmp", bus_property_append_bool, "b", offsetof(ExecContext, private_tmp) },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "PrivateNetwork", bus_property_append_bool, "b", offsetof(ExecContext, private_network) },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "SameProcessGroup", bus_property_append_bool, "b", offsetof(ExecContext, same_pgrp) },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "KillMode", bus_execute_append_kill_mode, "s", offsetof(ExecContext, kill_mode) },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "KillSignal", bus_property_append_int, "i", offsetof(ExecContext, kill_signal) },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "UtmpIdentifier", bus_property_append_string, "s", offsetof(ExecContext, utmp_id), true },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "ControlGroupModify", bus_property_append_bool, "b", offsetof(ExecContext, control_group_modify) },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "ControlGroupPersistent", bus_property_append_tristate_false, "b", offsetof(ExecContext, control_group_persistent) },
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering { "IgnoreSIGPIPE", bus_property_append_bool, "b", offsetof(ExecContext, ignore_sigpipe ) },