f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering/***
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering This file is part of systemd.
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering Copyright 2015 Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering systemd is free software; you can redistribute it and/or modify it
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering under the terms of the GNU Lesser General Public License as published by
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering (at your option) any later version.
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering systemd is distributed in the hope that it will be useful, but
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering Lesser General Public License for more details.
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering You should have received a copy of the GNU Lesser General Public License
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering***/
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#include "alloc-util.h"
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering#include "cap-list.h"
7b3e062cb6872e28ef5a2e069810070e28bbe0cdLennart Poettering#include "conf-parser.h"
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering#include "nspawn-network.h"
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering#include "nspawn-settings.h"
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering#include "parse-util.h"
7b3e062cb6872e28ef5a2e069810070e28bbe0cdLennart Poettering#include "process-util.h"
7b3e062cb6872e28ef5a2e069810070e28bbe0cdLennart Poettering#include "strv.h"
7b3e062cb6872e28ef5a2e069810070e28bbe0cdLennart Poettering#include "util.h"
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poetteringint settings_load(FILE *f, const char *path, Settings **ret) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering _cleanup_(settings_freep) Settings *s = NULL;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering int r;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(path);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(ret);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering s = new0(Settings, 1);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (!s)
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return -ENOMEM;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering s->start_mode = _START_MODE_INVALID;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering s->personality = PERSONALITY_INVALID;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering s->read_only = -1;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering s->volatile_mode = _VOLATILE_MODE_INVALID;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering s->private_network = -1;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering s->network_veth = -1;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering r = config_parse(NULL, path, f,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering "Exec\0"
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering "Network\0"
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering "Files\0",
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering config_item_perf_lookup, nspawn_gperf_lookup,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering false,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering false,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering true,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering s);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (r < 0)
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return r;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering *ret = s;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering s = NULL;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering}
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart PoetteringSettings* settings_free(Settings *s) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (!s)
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return NULL;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering strv_free(s->parameters);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering strv_free(s->environment);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering free(s->user);
5f932eb9af7a5e4723855bcd776c2acaa2a31932Lennart Poettering free(s->working_directory);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering strv_free(s->network_interfaces);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering strv_free(s->network_macvlan);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering strv_free(s->network_ipvlan);
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering strv_free(s->network_veth_extra);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering free(s->network_bridge);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering expose_port_free_all(s->expose_ports);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering custom_mount_free_all(s->custom_mounts, s->n_custom_mounts);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering free(s);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return NULL;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering}
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poetteringbool settings_private_network(Settings *s) {
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering assert(s);
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering return
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering s->private_network > 0 ||
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering s->network_veth > 0 ||
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering s->network_bridge ||
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering s->network_interfaces ||
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering s->network_macvlan ||
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering s->network_ipvlan ||
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering s->network_veth_extra;
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering}
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poetteringbool settings_network_veth(Settings *s) {
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering assert(s);
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering return
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering s->network_veth > 0 ||
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering s->network_bridge;
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering}
0e2656744f6d2e2cf65788a497f266d469865e30Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart PoetteringDEFINE_CONFIG_PARSE_ENUM(config_parse_volatile_mode, volatile_mode, VolatileMode, "Failed to parse volatile mode");
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poetteringint config_parse_expose_port(
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *unit,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *filename,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering unsigned line,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *section,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering unsigned section_line,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *lvalue,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering int ltype,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *rvalue,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering void *data,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering void *userdata) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering Settings *s = data;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering int r;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(filename);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(lvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering r = expose_port_parse(&s->expose_ports, rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (r == -EEXIST) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, r, "Duplicate port specification, ignoring: %s", rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (r < 0) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse host port %s: %m", rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering}
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poetteringint config_parse_capability(
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *unit,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *filename,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering unsigned line,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *section,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering unsigned section_line,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *lvalue,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering int ltype,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *rvalue,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering void *data,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering void *userdata) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering uint64_t u = 0, *result = data;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering int r;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(filename);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(lvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering for (;;) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering _cleanup_free_ char *word = NULL;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering int cap;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering r = extract_first_word(&rvalue, &word, NULL, 0);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (r < 0) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract capability string, ignoring: %s", rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (r == 0)
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering break;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering cap = capability_from_name(word);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (cap < 0) {
12ca818ffddb77eb6a0fabe369a5bcbf6994ff8bLennart Poettering log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse capability, ignoring: %s", word);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering continue;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering u |= 1 << ((uint64_t) cap);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (u == 0)
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering *result |= u;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering}
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poetteringint config_parse_id128(
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *unit,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *filename,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering unsigned line,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *section,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering unsigned section_line,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *lvalue,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering int ltype,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *rvalue,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering void *data,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering void *userdata) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering sd_id128_t t, *result = data;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering int r;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(filename);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(lvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering r = sd_id128_from_string(rvalue, &t);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (r < 0) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse 128bit ID/UUID, ignoring: %s", rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering *result = t;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering}
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poetteringint config_parse_bind(
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *unit,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *filename,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering unsigned line,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *section,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering unsigned section_line,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *lvalue,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering int ltype,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *rvalue,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering void *data,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering void *userdata) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering Settings *settings = data;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering int r;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(filename);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(lvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering r = bind_mount_parse(&settings->custom_mounts, &settings->n_custom_mounts, rvalue, ltype);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (r < 0) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, r, "Invalid bind mount specification %s: %m", rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering}
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poetteringint config_parse_tmpfs(
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *unit,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *filename,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering unsigned line,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *section,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering unsigned section_line,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *lvalue,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering int ltype,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering const char *rvalue,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering void *data,
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering void *userdata) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering Settings *settings = data;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering int r;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(filename);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(lvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering assert(rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering r = tmpfs_mount_parse(&settings->custom_mounts, &settings->n_custom_mounts, rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering if (r < 0) {
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, r, "Invalid temporary file system specification %s: %m", rvalue);
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering return 0;
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering}
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poetteringint config_parse_veth_extra(
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering const char *unit,
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering const char *filename,
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering unsigned line,
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering const char *section,
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering unsigned section_line,
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering const char *lvalue,
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering int ltype,
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering const char *rvalue,
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering void *data,
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering void *userdata) {
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering Settings *settings = data;
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering int r;
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering assert(filename);
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering assert(lvalue);
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering assert(rvalue);
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering r = veth_extra_parse(&settings->network_veth_extra, rvalue);
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering if (r < 0) {
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering log_syntax(unit, LOG_ERR, filename, line, r, "Invalid extra virtual Ethernet link specification %s: %m", rvalue);
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering return 0;
f6d6bad1461a8f545a80955fadd7ee0c10db15bbLennart Poettering }
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering return 0;
f757855e81fc0bc116de372220096e532afb5cb8Lennart Poettering}
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poetteringint config_parse_boot(
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering const char *unit,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering const char *filename,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering unsigned line,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering const char *section,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering unsigned section_line,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering const char *lvalue,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering int ltype,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering const char *rvalue,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering void *data,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering void *userdata) {
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering Settings *settings = data;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering int r;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering assert(filename);
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering assert(lvalue);
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering assert(rvalue);
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering r = parse_boolean(rvalue);
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering if (r < 0) {
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse Boot= parameter %s, ignoring: %m", rvalue);
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering return 0;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering }
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering if (r > 0) {
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering if (settings->start_mode == START_PID2)
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering goto conflict;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering settings->start_mode = START_BOOT;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering } else {
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering if (settings->start_mode == START_BOOT)
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering goto conflict;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering if (settings->start_mode < 0)
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering settings->start_mode = START_PID1;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering }
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering return 0;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poetteringconflict:
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering log_syntax(unit, LOG_ERR, filename, line, r, "Conflicting Boot= or ProcessTwo= setting found. Ignoring.");
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering return 0;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering}
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poetteringint config_parse_pid2(
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering const char *unit,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering const char *filename,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering unsigned line,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering const char *section,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering unsigned section_line,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering const char *lvalue,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering int ltype,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering const char *rvalue,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering void *data,
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering void *userdata) {
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering Settings *settings = data;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering int r;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering assert(filename);
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering assert(lvalue);
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering assert(rvalue);
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering r = parse_boolean(rvalue);
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering if (r < 0) {
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse ProcessTwo= parameter %s, ignoring: %m", rvalue);
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering return 0;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering }
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering if (r > 0) {
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering if (settings->start_mode == START_BOOT)
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering goto conflict;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering settings->start_mode = START_PID2;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering } else {
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering if (settings->start_mode == START_PID2)
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering goto conflict;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering if (settings->start_mode < 0)
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering settings->start_mode = START_PID1;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering }
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering return 0;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poetteringconflict:
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering log_syntax(unit, LOG_ERR, filename, line, r, "Conflicting Boot= or ProcessTwo= setting found. Ignoring.");
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering return 0;
7732f92bad5f24a4bd03bb357af46da56b0ac94dLennart Poettering}