1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2015 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "alloc-util.h"
24 #include "conf-parser.h"
25 #include "nspawn-network.h"
26 #include "nspawn-settings.h"
27 #include "process-util.h"
31 int settings_load(FILE *f
, const char *path
, Settings
**ret
) {
32 _cleanup_(settings_freep
) Settings
*s
= NULL
;
38 s
= new0(Settings
, 1);
43 s
->personality
= PERSONALITY_INVALID
;
46 s
->volatile_mode
= _VOLATILE_MODE_INVALID
;
48 s
->private_network
= -1;
51 r
= config_parse(NULL
, path
, f
,
55 config_item_perf_lookup
, nspawn_gperf_lookup
,
69 Settings
* settings_free(Settings
*s
) {
74 strv_free(s
->parameters
);
75 strv_free(s
->environment
);
77 free(s
->working_directory
);
79 strv_free(s
->network_interfaces
);
80 strv_free(s
->network_macvlan
);
81 strv_free(s
->network_ipvlan
);
82 strv_free(s
->network_veth_extra
);
83 free(s
->network_bridge
);
84 expose_port_free_all(s
->expose_ports
);
86 custom_mount_free_all(s
->custom_mounts
, s
->n_custom_mounts
);
92 bool settings_private_network(Settings
*s
) {
96 s
->private_network
> 0 ||
97 s
->network_veth
> 0 ||
99 s
->network_interfaces
||
100 s
->network_macvlan
||
102 s
->network_veth_extra
;
105 bool settings_network_veth(Settings
*s
) {
109 s
->network_veth
> 0 ||
113 DEFINE_CONFIG_PARSE_ENUM(config_parse_volatile_mode
, volatile_mode
, VolatileMode
, "Failed to parse volatile mode");
115 int config_parse_expose_port(
117 const char *filename
,
120 unsigned section_line
,
134 r
= expose_port_parse(&s
->expose_ports
, rvalue
);
136 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Duplicate port specification, ignoring: %s", rvalue
);
140 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse host port %s: %m", rvalue
);
147 int config_parse_capability(
149 const char *filename
,
152 unsigned section_line
,
159 uint64_t u
= 0, *result
= data
;
167 _cleanup_free_
char *word
= NULL
;
170 r
= extract_first_word(&rvalue
, &word
, NULL
, 0);
172 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract capability string, ignoring: %s", rvalue
);
178 cap
= capability_from_name(word
);
180 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse capability, ignoring: %s", word
);
184 u
|= 1 << ((uint64_t) cap
);
194 int config_parse_id128(
196 const char *filename
,
199 unsigned section_line
,
206 sd_id128_t t
, *result
= data
;
213 r
= sd_id128_from_string(rvalue
, &t
);
215 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse 128bit ID/UUID, ignoring: %s", rvalue
);
223 int config_parse_bind(
225 const char *filename
,
228 unsigned section_line
,
235 Settings
*settings
= data
;
242 r
= bind_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
, ltype
);
244 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid bind mount specification %s: %m", rvalue
);
251 int config_parse_tmpfs(
253 const char *filename
,
256 unsigned section_line
,
263 Settings
*settings
= data
;
270 r
= tmpfs_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
);
272 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid temporary file system specification %s: %m", rvalue
);
279 int config_parse_veth_extra(
281 const char *filename
,
284 unsigned section_line
,
291 Settings
*settings
= data
;
298 r
= veth_extra_parse(&settings
->network_veth_extra
, rvalue
);
300 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid extra virtual Ethernet link specification %s: %m", rvalue
);