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-settings.h"
26 #include "process-util.h"
30 int settings_load(FILE *f
, const char *path
, Settings
**ret
) {
31 _cleanup_(settings_freep
) Settings
*s
= NULL
;
37 s
= new0(Settings
, 1);
42 s
->personality
= PERSONALITY_INVALID
;
45 s
->volatile_mode
= _VOLATILE_MODE_INVALID
;
47 s
->private_network
= -1;
50 r
= config_parse(NULL
, path
, f
,
54 config_item_perf_lookup
, nspawn_gperf_lookup
,
68 Settings
* settings_free(Settings
*s
) {
73 strv_free(s
->parameters
);
74 strv_free(s
->environment
);
77 strv_free(s
->network_interfaces
);
78 strv_free(s
->network_macvlan
);
79 strv_free(s
->network_ipvlan
);
80 free(s
->network_bridge
);
81 expose_port_free_all(s
->expose_ports
);
83 custom_mount_free_all(s
->custom_mounts
, s
->n_custom_mounts
);
89 bool settings_private_network(Settings
*s
) {
93 s
->private_network
> 0 ||
94 s
->network_veth
> 0 ||
96 s
->network_interfaces
||
101 bool settings_network_veth(Settings
*s
) {
105 s
->network_veth
> 0 ||
109 DEFINE_CONFIG_PARSE_ENUM(config_parse_volatile_mode
, volatile_mode
, VolatileMode
, "Failed to parse volatile mode");
111 int config_parse_expose_port(
113 const char *filename
,
116 unsigned section_line
,
130 r
= expose_port_parse(&s
->expose_ports
, rvalue
);
132 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Duplicate port specification, ignoring: %s", rvalue
);
136 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse host port %s: %m", rvalue
);
143 int config_parse_capability(
145 const char *filename
,
148 unsigned section_line
,
155 uint64_t u
= 0, *result
= data
;
163 _cleanup_free_
char *word
= NULL
;
166 r
= extract_first_word(&rvalue
, &word
, NULL
, 0);
168 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract capability string, ignoring: %s", rvalue
);
174 cap
= capability_from_name(word
);
176 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse capability, ignoring: %s", word
);
180 u
|= 1 << ((uint64_t) cap
);
190 int config_parse_id128(
192 const char *filename
,
195 unsigned section_line
,
202 sd_id128_t t
, *result
= data
;
209 r
= sd_id128_from_string(rvalue
, &t
);
211 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse 128bit ID/UUID, ignoring: %s", rvalue
);
219 int config_parse_bind(
221 const char *filename
,
224 unsigned section_line
,
231 Settings
*settings
= data
;
238 r
= bind_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
, ltype
);
240 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid bind mount specification %s: %m", rvalue
);
247 int config_parse_tmpfs(
249 const char *filename
,
252 unsigned section_line
,
259 Settings
*settings
= data
;
266 r
= tmpfs_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
);
268 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid temporary file system specification %s: %m", rvalue
);
272 if (settings
->network_bridge
)
273 settings
->network_veth
= true;
275 if (settings
->network_interfaces
||
276 settings
->network_macvlan
||
277 settings
->network_ipvlan
||
278 settings
->network_bridge
||
279 settings
->network_veth
)
280 settings
->private_network
= true;