HALF ECHO LEARN / REFERENCE COLLECTION

v262.2

src/core/dbus-execute.c

193,499 bytesGit mode 100644Download original fileLGPL-2.1-or-later

Git blob: 4d86c07a41a43be36f83303ea24907c57169829b

Lines 3001–4000 of 4,331

                        return r;
 
                r = sd_bus_message_read(message, "b", &allow_list);
                if (r < 0)
                        return r;
 
                r = sd_bus_message_read_strv(message, &l);
                if (r < 0)
                        return r;
 
                r = sd_bus_message_exit_container(message);
                if (r < 0)
                        return r;
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        _cleanup_free_ char *joined = NULL;
 
                        if (strv_isempty(l)) {
                                c->address_families_allow_list = allow_list;
                                c->address_families = set_free(c->address_families);
 
                                unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s",
                                                    allow_list ? "none" : "");
                                return 1;
                        }
 
                        if (!c->address_families) {
                                c->address_families = set_new(NULL);
                                if (!c->address_families)
                                        return log_oom();
 
                                c->address_families_allow_list = allow_list;
                        }
 
                        STRV_FOREACH(s, l) {
                                int af;
 
                                af = af_from_name(*s);
                                if (af < 0)
                                        return af;
 
                                if (allow_list == c->address_families_allow_list) {
                                        r = set_put(c->address_families, INT_TO_PTR(af));
                                        if (r < 0)
                                                return r;
                                } else
                                        set_remove(c->address_families, INT_TO_PTR(af));
                        }
 
                        joined = strv_join(l, " ");
                        if (!joined)
                                return -ENOMEM;
 
                        unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s%s", allow_list ? "" : "~", joined);
                }
 
                return 1;
        }
#endif
        if (STR_IN_SET(name, "CPUAffinity", "NUMAMask")) {
                _cleanup_(cpu_set_done) CPUSet set = {};
                const void *a;
                size_t n;
 
                r = sd_bus_message_read_array(message, 'y', &a, &n);
                if (r < 0)
                        return r;
 
                r = cpu_set_from_dbus(a, n, &set);
                if (r < 0)
                        return r;
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        CPUSet *cpuset = streq(name, "CPUAffinity") ? &c->cpu_set : &c->numa_policy.nodes;
 
                        if (n == 0) {
                                cpu_set_done(cpuset);
                                unit_write_settingf(u, flags, name, "%s=", name);
                        } else {
                                _cleanup_free_ char *str = NULL;
 
                                str = cpu_set_to_string(&set);
                                if (!str)
                                        return -ENOMEM;
 
                                /* We forego any optimizations here, and always create the structure using
                                 * cpu_set_add_set(), because we don't want to care if the existing size we
                                 * got over dbus is appropriate. */
                                r = cpu_set_add_set(cpuset, &set);
                                if (r < 0)
                                        return r;
 
                                unit_write_settingf(u, flags, name, "%s=%s", name, str);
                        }
                }
 
                return 1;
 
        } else if (streq(name, "CPUAffinityFromNUMA")) {
                int q;
 
                r = sd_bus_message_read_basic(message, 'b', &q);
                if (r < 0)
                        return r;
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        c->cpu_affinity_from_numa = q;
                        unit_write_settingf(u, flags, name, "%s=%s", "CPUAffinity", "numa");
                }
 
                return 1;
 
        } else if (streq(name, "NUMAPolicy")) {
                int32_t type;
 
                r = sd_bus_message_read(message, "i", &type);
                if (r < 0)
                        return r;
 
                if (!mpol_is_valid(type))
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid NUMAPolicy value: %i", type);
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags))
                        c->numa_policy.type = type;
 
                return 1;
 
        } else if (streq(name, "Nice")) {
                int32_t q;
 
                r = sd_bus_message_read(message, "i", &q);
                if (r < 0)
                        return r;
 
                if (!nice_is_valid(q))
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Nice value: %i", q);
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        c->nice = q;
                        c->nice_set = true;
 
                        unit_write_settingf(u, flags, name, "Nice=%i", q);
                }
 
                return 1;
 
        } else if (streq(name, "CPUSchedulingPolicy")) {
                int32_t q;
 
                r = sd_bus_message_read(message, "i", &q);
                if (r < 0)
                        return r;
 
                if (!sched_policy_is_valid(q))
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling policy: %i", q);
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        _cleanup_free_ char *s = NULL;
 
                        r = sched_policy_to_string_alloc(q, &s);
                        if (r < 0)
                                return r;
 
                        c->cpu_sched_policy = q;
                        c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min_safe(q), sched_get_priority_max_safe(q));
                        c->cpu_sched_set = true;
 
                        unit_write_settingf(u, flags, name, "CPUSchedulingPolicy=%s", s);
                }
 
                return 1;
 
        } else if (streq(name, "CPUSchedulingPriority")) {
                int32_t p;
 
                r = sd_bus_message_read(message, "i", &p);
                if (r < 0)
                        return r;
 
                /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set
                 * later so we do not check the precise range, but only the generic outer bounds. */
                if (p < 0 || p > 99)
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling priority: %i", p);
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        c->cpu_sched_priority = p;
                        c->cpu_sched_set = true;
 
                        unit_write_settingf(u, flags, name, "CPUSchedulingPriority=%i", p);
                }
 
                return 1;
 
        } else if (streq(name, "IOSchedulingClass")) {
                int32_t q;
 
                r = sd_bus_message_read(message, "i", &q);
                if (r < 0)
                        return r;
 
                if (!ioprio_class_is_valid(q))
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling class: %i", q);
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        _cleanup_free_ char *s = NULL;
 
                        r = ioprio_class_to_string_alloc(q, &s);
                        if (r < 0)
                                return r;
 
                        c->ioprio = ioprio_normalize(ioprio_prio_value(q, ioprio_prio_data(c->ioprio)));
                        c->ioprio_is_set = true;
 
                        unit_write_settingf(u, flags, name, "IOSchedulingClass=%s", s);
                }
 
                return 1;
 
        } else if (streq(name, "IOSchedulingPriority")) {
                int32_t p;
 
                r = sd_bus_message_read(message, "i", &p);
                if (r < 0)
                        return r;
 
                if (!ioprio_priority_is_valid(p))
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling priority: %i", p);
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        c->ioprio = ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c->ioprio), p));
                        c->ioprio_is_set = true;
 
                        unit_write_settingf(u, flags, name, "IOSchedulingPriority=%i", p);
                }
 
                return 1;
 
        } else if (streq(name, "WorkingDirectory")) {
                _cleanup_free_ char *simplified = NULL;
                bool missing_ok = false, is_home = false;
                const char *s;
 
                r = sd_bus_message_read(message, "s", &s);
                if (r < 0)
                        return r;
 
                if (!isempty(s)) {
                        if (s[0] == '-') {
                                missing_ok = true;
                                s++;
                        }
 
                        if (streq(s, "~"))
                                is_home = true;
                        else {
                                if (!path_is_absolute(s))
                                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS,
                                                                "WorkingDirectory= expects an absolute path or '~'");
 
                                r = path_simplify_alloc(s, &simplified);
                                if (r < 0)
                                        return r;
 
                                if (!path_is_normalized(simplified))
                                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS,
                                                                "WorkingDirectory= expects a normalized path or '~'");
                        }
                }
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        free_and_replace(c->working_directory, simplified);
                        c->working_directory_home = is_home;
                        c->working_directory_missing_ok = missing_ok;
 
                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name,
                                            "WorkingDirectory=%s%s",
                                            c->working_directory_missing_ok ? "-" : "",
                                            c->working_directory_home ? "~" : strempty(c->working_directory));
                }
 
                return 1;
 
        } else if (STR_IN_SET(name,
                              "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
                const char *s;
 
                r = sd_bus_message_read(message, "s", &s);
                if (r < 0)
                        return r;
 
                if (!isempty(s) && !fdname_is_valid(s))
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name");
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
 
                        if (streq(name, "StandardInputFileDescriptorName")) {
                                r = free_and_strdup(c->stdio_fdname + STDIN_FILENO, empty_to_null(s));
                                if (r < 0)
                                        return r;
 
                                c->std_input = EXEC_INPUT_NAMED_FD;
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=fd:%s", exec_context_fdname(c, STDIN_FILENO));
 
                        } else if (streq(name, "StandardOutputFileDescriptorName")) {
                                r = free_and_strdup(c->stdio_fdname + STDOUT_FILENO, empty_to_null(s));
                                if (r < 0)
                                        return r;
 
                                c->std_output = EXEC_OUTPUT_NAMED_FD;
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=fd:%s", exec_context_fdname(c, STDOUT_FILENO));
 
                        } else {
                                assert(streq(name, "StandardErrorFileDescriptorName"));
 
                                r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], empty_to_null(s));
                                if (r < 0)
                                        return r;
 
                                c->std_error = EXEC_OUTPUT_NAMED_FD;
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=fd:%s", exec_context_fdname(c, STDERR_FILENO));
                        }
                }
 
                return 1;
 
        } else if (STR_IN_SET(name,
                              "StandardInputFile",
                              "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate",
                              "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate")) {
                const char *s;
 
                r = sd_bus_message_read(message, "s", &s);
                if (r < 0)
                        return r;
 
                if (!path_is_absolute(s))
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute", s);
                if (!path_is_normalized(s))
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not normalized", s);
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
 
                        if (streq(name, "StandardInputFile")) {
                                r = free_and_strdup(&c->stdio_file[STDIN_FILENO], s);
                                if (r < 0)
                                        return r;
 
                                c->std_input = EXEC_INPUT_FILE;
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=file:%s", s);
 
                        } else if (STR_IN_SET(name, "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate")) {
                                r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], s);
                                if (r < 0)
                                        return r;
 
                                if (streq(name, "StandardOutputFile")) {
                                        c->std_output = EXEC_OUTPUT_FILE;
                                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=file:%s", s);
                                } else if (streq(name, "StandardOutputFileToAppend")) {
                                        c->std_output = EXEC_OUTPUT_FILE_APPEND;
                                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=append:%s", s);
                                } else {
                                        assert(streq(name, "StandardOutputFileToTruncate"));
                                        c->std_output = EXEC_OUTPUT_FILE_TRUNCATE;
                                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=truncate:%s", s);
                                }
                        } else {
                                assert(STR_IN_SET(name, "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate"));
 
                                r = free_and_strdup(&c->stdio_file[STDERR_FILENO], s);
                                if (r < 0)
                                        return r;
 
                                if (streq(name, "StandardErrorFile")) {
                                        c->std_error = EXEC_OUTPUT_FILE;
                                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=file:%s", s);
                                } else if (streq(name, "StandardErrorFileToAppend")) {
                                        c->std_error = EXEC_OUTPUT_FILE_APPEND;
                                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=append:%s", s);
                                } else {
                                        assert(streq(name, "StandardErrorFileToTruncate"));
                                        c->std_error = EXEC_OUTPUT_FILE_TRUNCATE;
                                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=truncate:%s", s);
                                }
                        }
                }
 
                return 1;
 
        } else if (streq(name, "StandardInputData")) {
                const void *p;
                size_t sz;
 
                r = sd_bus_message_read_array(message, 'y', &p, &sz);
                if (r < 0)
                        return r;
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        _cleanup_free_ char *encoded = NULL;
 
                        if (sz == 0) {
                                c->stdin_data = mfree(c->stdin_data);
                                c->stdin_data_size = 0;
 
                                unit_write_settingf(u, flags, name, "StandardInputData=");
                        } else {
                                void *q;
                                ssize_t n;
 
                                if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */
                                    c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX)
                                        return -E2BIG;
 
                                n = base64mem(p, sz, &encoded);
                                if (n < 0)
                                        return (int) n;
 
                                q = realloc(c->stdin_data, c->stdin_data_size + sz);
                                if (!q)
                                        return -ENOMEM;
 
                                memcpy((uint8_t*) q + c->stdin_data_size, p, sz);
 
                                c->stdin_data = q;
                                c->stdin_data_size += sz;
 
                                unit_write_settingf(u, flags, name, "StandardInputData=%s", encoded);
                        }
                }
 
                return 1;
 
        } else if (streq(name, "Environment")) {
 
                _cleanup_strv_free_ char **l = NULL;
 
                r = sd_bus_message_read_strv(message, &l);
                if (r < 0)
                        return r;
 
                r = exec_context_apply_environment(u, c, l, flags);
                if (r == -E2BIG)
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED,
                                                "Too many environment assignments.");
                if (r == -EINVAL)
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
                if (r < 0)
                        return r;
 
                return 1;
 
        } else if (streq(name, "UnsetEnvironment")) {
 
                _cleanup_strv_free_ char **l = NULL;
 
                r = sd_bus_message_read_strv(message, &l);
                if (r < 0)
                        return r;
 
                if (strv_length(l) > ENVIRONMENT_ASSIGNMENTS_MAX)
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED,
                                                "Too many environment variable names or assignments.");
                if (!strv_env_name_or_assignment_is_valid(l))
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list.");
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        if (strv_isempty(l)) {
                                c->unset_environment = strv_free(c->unset_environment);
                                unit_write_setting(u, flags, name, "UnsetEnvironment=");
                        } else {
                                _cleanup_free_ char *joined = NULL;
                                char **e;
 
                                joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
                                if (!joined)
                                        return -ENOMEM;
 
                                e = strv_env_merge(c->unset_environment, l);
                                if (!e)
                                        return -ENOMEM;
 
                                strv_free_and_replace(c->unset_environment, e);
                                unit_write_settingf(u, flags, name, "UnsetEnvironment=%s", joined);
                        }
                }
 
                return 1;
 
        } else if (streq(name, "OOMScoreAdjust")) {
                int oa;
 
                r = sd_bus_message_read(message, "i", &oa);
                if (r < 0)
                        return r;
 
                if (!oom_score_adjust_is_valid(oa))
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range");
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        c->oom_score_adjust = oa;
                        c->oom_score_adjust_set = true;
                        unit_write_settingf(u, flags, name, "OOMScoreAdjust=%i", oa);
                }
 
                return 1;
 
        } else if (streq(name, "CoredumpFilter")) {
                uint64_t f;
 
                r = sd_bus_message_read(message, "t", &f);
                if (r < 0)
                        return r;
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        c->coredump_filter = f;
                        c->coredump_filter_set = true;
                        unit_write_settingf(u, flags, name, "CoredumpFilter=0x%"PRIx64, f);
                }
 
                return 1;
 
        } else if (streq(name, "EnvironmentFiles")) {
                _cleanup_(memstream_done) MemStream m = {};
                _cleanup_free_ char *joined = NULL;
                _cleanup_strv_free_ char **l = NULL;
                FILE *f;
 
                r = sd_bus_message_enter_container(message, 'a', "(sb)");
                if (r < 0)
                        return r;
 
                f = memstream_init(&m);
                if (!f)
                        return -ENOMEM;
 
                fputs("EnvironmentFile=\n", f);
 
                STRV_FOREACH(i, c->environment_files) {
                        _cleanup_free_ char *q = NULL;
 
                        q = specifier_escape(*i);
                        if (!q)
                                return -ENOMEM;
 
                        fprintf(f, "EnvironmentFile=%s\n", q);
                }
 
                while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) {
                        const char *path;
                        int b;
 
                        r = sd_bus_message_read(message, "sb", &path, &b);
                        if (r < 0)
                                return r;
 
                        r = sd_bus_message_exit_container(message);
                        if (r < 0)
                                return r;
 
                        if (!path_is_absolute(path))
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
 
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                                _cleanup_free_ char *q = NULL, *buf = NULL;
 
                                buf = strjoin(b ? "-" : "", path);
                                if (!buf)
                                        return -ENOMEM;
 
                                q = specifier_escape(buf);
                                if (!q)
                                        return -ENOMEM;
 
                                fprintf(f, "EnvironmentFile=%s\n", q);
 
                                r = strv_consume(&l, TAKE_PTR(buf));
                                if (r < 0)
                                        return r;
                        }
                }
                if (r < 0)
                        return r;
 
                r = sd_bus_message_exit_container(message);
                if (r < 0)
                        return r;
 
                r = memstream_finalize(&m, &joined, NULL);
                if (r < 0)
                        return r;
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        if (strv_isempty(l)) {
                                c->environment_files = strv_free(c->environment_files);
                                unit_write_setting(u, flags, name, "EnvironmentFile=");
                        } else {
                                r = strv_extend_strv(&c->environment_files, l, true);
                                if (r < 0)
                                        return r;
 
                                unit_write_setting(u, flags, name, joined);
                        }
                }
 
                return 1;
 
        } else if (streq(name, "PassEnvironment")) {
 
                _cleanup_strv_free_ char **l = NULL;
 
                r = sd_bus_message_read_strv(message, &l);
                if (r < 0)
                        return r;
 
                if (strv_length(l) > ENVIRONMENT_ASSIGNMENTS_MAX)
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_LIMITS_EXCEEDED,
                                                "Too many environment variable names.");
                if (!strv_env_name_is_valid(l))
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment= block.");
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        if (strv_isempty(l)) {
                                c->pass_environment = strv_free(c->pass_environment);
                                unit_write_setting(u, flags, name, "PassEnvironment=");
                        } else {
                                _cleanup_free_ char *joined = NULL;
 
                                r = strv_extend_strv(&c->pass_environment, l, true);
                                if (r < 0)
                                        return r;
 
                                /* We write just the new settings out to file, with unresolved specifiers. */
                                joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
                                if (!joined)
                                        return -ENOMEM;
 
                                unit_write_settingf(u, flags, name, "PassEnvironment=%s", joined);
                        }
                }
 
                return 1;
 
        } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
                              "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths", "ExecPaths", "NoExecPaths",
                              "ExtensionDirectories")) {
                _cleanup_strv_free_ char **l = NULL;
                char ***dirs;
 
                r = sd_bus_message_read_strv(message, &l);
                if (r < 0)
                        return r;
 
                STRV_FOREACH(p, l) {
                        char *i = *p;
                        size_t offset;
 
                        offset = i[0] == '-';
                        offset += i[offset] == '+';
                        if (!path_is_absolute(i + offset))
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
 
                        path_simplify(i + offset);
                }
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths"))
                                dirs = &c->read_write_paths;
                        else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths"))
                                dirs = &c->read_only_paths;
                        else if (streq(name, "ExecPaths"))
                                dirs = &c->exec_paths;
                        else if (streq(name, "NoExecPaths"))
                                dirs = &c->no_exec_paths;
                        else if (streq(name, "ExtensionDirectories"))
                                dirs = &c->extension_directories;
                        else /* "InaccessiblePaths" */
                                dirs = &c->inaccessible_paths;
 
                        if (strv_isempty(l)) {
                                *dirs = strv_free(*dirs);
                                unit_write_settingf(u, flags, name, "%s=", name);
                        } else {
                                _cleanup_free_ char *joined = NULL;
 
                                joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
                                if (!joined)
                                        return -ENOMEM;
 
                                r = strv_extend_strv(dirs, l, true);
                                if (r < 0)
                                        return r;
 
                                unit_write_settingf(u, flags, name, "%s=%s", name, joined);
                        }
                }
 
                return 1;
 
        } else if (streq(name, "ExecSearchPath")) {
                _cleanup_strv_free_ char **l = NULL;
 
                r = sd_bus_message_read_strv(message, &l);
                if (r < 0)
                        return r;
 
                STRV_FOREACH(p, l)
                        if (!path_is_absolute(*p) || !path_is_normalized(*p) || strchr(*p, ':'))
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        if (strv_isempty(l)) {
                                c->exec_search_path = strv_free(c->exec_search_path);
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath=");
                        } else {
                                _cleanup_free_ char *joined = NULL;
                                r = strv_extend_strv(&c->exec_search_path, l, true);
                                if (r < 0)
                                        return r;
                                joined = strv_join(c->exec_search_path, ":");
                                if (!joined)
                                        return log_oom();
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath=%s", joined);
                        }
                }
 
                return 1;
 
        } else if (STR_IN_SET(name, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
                _cleanup_strv_free_ char **l = NULL;
 
                r = sd_bus_message_read_strv(message, &l);
                if (r < 0)
                        return r;
 
                STRV_FOREACH(p, l) {
                        if (!path_is_normalized(*p))
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is not normalized: %s", name, *p);
 
                        if (path_is_absolute(*p))
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is absolute: %s", name, *p);
 
                        if (path_startswith(*p, "private"))
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "%s= path can't be 'private': %s", name, *p);
                }
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        ExecDirectoryType i;
                        ExecDirectory *d;
 
                        assert_se((i = exec_directory_type_from_string(name)) >= 0);
                        d = c->directories + i;
 
                        if (strv_isempty(l)) {
                                exec_directory_done(d);
                                unit_write_settingf(u, flags, name, "%s=", name);
                        } else {
                                _cleanup_free_ char *joined = NULL;
 
                                STRV_FOREACH(source, l) {
                                        r = exec_directory_add(d, *source, /* symlink= */ NULL, /* flags= */ 0);
                                        if (r < 0)
                                                return log_oom();
                                }
                                exec_directory_sort(d);
 
                                joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
                                if (!joined)
                                        return -ENOMEM;
 
                                unit_write_settingf(u, flags, name, "%s=%s", name, joined);
                        }
                }
 
                return 1;
 
        } else if (STR_IN_SET(name, "StateDirectoryQuota", "CacheDirectoryQuota", "LogsDirectoryQuota")) {
                uint64_t quota_absolute = UINT64_MAX;
                uint32_t quota_scale = UINT32_MAX;
                const char *enforce_flag;
                int quota_enforce;
 
                r = sd_bus_message_read(message, "(tus)", &quota_absolute, &quota_scale, &enforce_flag);
                if (r < 0)
                        return r;
 
                quota_enforce = parse_boolean(enforce_flag);
                if (quota_enforce < 0)
                        return quota_enforce;
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        ExecDirectoryType dt;
                        if (streq(name, "StateDirectoryQuota"))
                                dt = EXEC_DIRECTORY_STATE;
                        else if (streq(name, "CacheDirectoryQuota"))
                                dt = EXEC_DIRECTORY_CACHE;
                        else if (streq(name, "LogsDirectoryQuota"))
                                dt = EXEC_DIRECTORY_LOGS;
                        else
                                assert_not_reached();
 
                        if (quota_enforce) {
                                c->directories[dt].exec_quota.quota_absolute = quota_absolute;
                                c->directories[dt].exec_quota.quota_scale = quota_scale;
 
                                if (quota_absolute != UINT64_MAX)
                                        unit_write_settingf(u, flags, name, "%s=%" PRIu64, name, quota_absolute);
                                else
                                        unit_write_settingf(u, flags, name, "%s=%d%%", name, UINT32_SCALE_TO_PERCENT(quota_scale));
                        } else
                                unit_write_settingf(u, flags, name, "%s=", name);
 
                        c->directories[dt].exec_quota.quota_enforce = quota_enforce;
                }
 
                return 1;
 
        } else if (STR_IN_SET(name, "AppArmorProfile", "SmackProcessLabel")) {
                int ignore;
                const char *s;
 
                r = sd_bus_message_read(message, "(bs)", &ignore, &s);
                if (r < 0)
                        return r;
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                        char **p;
                        bool *b;
 
                        if (streq(name, "AppArmorProfile")) {
                                p = &c->apparmor_profile;
                                b = &c->apparmor_profile_ignore;
                        } else { /* "SmackProcessLabel" */
                                p = &c->smack_process_label;
                                b = &c->smack_process_label_ignore;
                        }
 
                        if (isempty(s)) {
                                *p = mfree(*p);
                                *b = false;
                        } else {
                                if (free_and_strdup(p, s) < 0)
                                        return -ENOMEM;
                                *b = ignore;
                        }
 
                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s%s", name, ignore ? "-" : "", strempty(s));
                }
 
                return 1;
 
        } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) {
                char *source, *destination;
                int ignore_enoent;
                uint64_t mount_flags;
                bool empty = true;
 
                r = sd_bus_message_enter_container(message, 'a', "(ssbt)");
                if (r < 0)
                        return r;
 
                while ((r = sd_bus_message_read(message, "(ssbt)", &source, &destination, &ignore_enoent, &mount_flags)) > 0) {
 
                        if (!path_is_absolute(source))
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
                        if (!path_is_absolute(destination))
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
                        if (!IN_SET(mount_flags, 0, MS_REC))
                                return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags.");
 
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                                r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
                                                   &(BindMount) {
                                                           .source = source,
                                                           .destination = destination,
                                                           .read_only = !!strstr(name, "ReadOnly"),
                                                           .recursive = !!(mount_flags & MS_REC),
                                                           .ignore_enoent = ignore_enoent,
                                                   });
                                if (r < 0)
                                        return r;
 
                                unit_write_settingf(
                                                u, flags|UNIT_ESCAPE_SPECIFIERS, name,
                                                "%s=%s%s:%s:%s",
                                                name,
                                                ignore_enoent ? "-" : "",
                                                source,
                                                destination,
                                                (mount_flags & MS_REC) ? "rbind" : "norbind");
                        }
 
                        empty = false;
                }
                if (r < 0)
                        return r;
 
                r = sd_bus_message_exit_container(message);
                if (r < 0)
                        return r;
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags) && empty) {
                        bind_mount_free_many(c->bind_mounts, c->n_bind_mounts);
                        c->bind_mounts = NULL;
                        c->n_bind_mounts = 0;
 
                        unit_write_settingf(u, flags, name, "%s=", name);
                }
 
                return 1;
 
        } else if (streq(name, "TemporaryFileSystem")) {
                const char *path, *options;
                bool empty = true;
 
                r = sd_bus_message_enter_container(message, 'a', "(ss)");
                if (r < 0)
                        return r;
 
                while ((r = sd_bus_message_read(message, "(ss)", &path, &options)) > 0) {
 
                        if (!path_is_absolute(path))
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Mount point %s is not absolute.", path);
 
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                                r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
                                if (r < 0)
                                        return r;
 
                                unit_write_settingf(
                                                u, flags|UNIT_ESCAPE_SPECIFIERS, name,
                                                "%s=%s:%s",
                                                name,
                                                path,
                                                options);
                        }
 
                        empty = false;
                }
                if (r < 0)
                        return r;
 
                r = sd_bus_message_exit_container(message);
                if (r < 0)
                        return r;
 
                if (!UNIT_WRITE_FLAGS_NOOP(flags) && empty) {
                        temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems);
                        c->temporary_filesystems = NULL;
                        c->n_temporary_filesystems = 0;
 
                        unit_write_settingf(u, flags, name, "%s=", name);
                }
 
                return 1;
 
        } else if ((suffix = startswith(name, "Limit"))) {
                const char *soft = NULL;
                int ri;
 
                ri = rlimit_from_string(suffix);
                if (ri < 0) {
                        soft = endswith(suffix, "Soft");
                        if (soft) {
                                const char *n;
 
                                n = strndupa_safe(suffix, soft - suffix);
                                ri = rlimit_from_string(n);
                                if (ri >= 0)
                                        name = strjoina("Limit", n);
                        }
                }
 
                if (ri >= 0) {
                        uint64_t rl;
                        rlim_t x;
 
                        r = sd_bus_message_read(message, "t", &rl);
                        if (r < 0)
                                return r;
 
                        if (rl == UINT64_MAX)
                                x = RLIM_INFINITY;
                        else {
                                x = (rlim_t) rl;
 
                                if ((uint64_t) x != rl)
                                        return -ERANGE;
                        }
 
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                                _cleanup_free_ char *f = NULL;
                                struct rlimit nl;
 
                                if (c->rlimit[ri]) {
                                        nl = *c->rlimit[ri];
 
                                        if (soft)
                                                nl.rlim_cur = x;
                                        else
                                                nl.rlim_max = x;