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/>.
23 #include "conf-parser.h"
27 #include "nspawn-settings.h"
29 int settings_load(FILE *f
, const char *path
, Settings
**ret
) {
30 _cleanup_(settings_freep
) Settings
*s
= NULL
;
36 s
= new0(Settings
, 1);
41 s
->personality
= PERSONALITY_INVALID
;
44 s
->volatile_mode
= _VOLATILE_MODE_INVALID
;
46 s
->private_network
= -1;
49 r
= config_parse(NULL
, path
, f
,
53 config_item_perf_lookup
, nspawn_gperf_lookup
,
67 Settings
* settings_free(Settings
*s
) {
72 strv_free(s
->parameters
);
73 strv_free(s
->environment
);
76 strv_free(s
->network_interfaces
);
77 strv_free(s
->network_macvlan
);
78 strv_free(s
->network_ipvlan
);
79 free(s
->network_bridge
);
80 expose_port_free_all(s
->expose_ports
);
82 custom_mount_free_all(s
->custom_mounts
, s
->n_custom_mounts
);
88 bool settings_private_network(Settings
*s
) {
92 s
->private_network
> 0 ||
93 s
->network_veth
> 0 ||
95 s
->network_interfaces
||
100 bool settings_network_veth(Settings
*s
) {
104 s
->network_veth
> 0 ||
108 DEFINE_CONFIG_PARSE_ENUM(config_parse_volatile_mode
, volatile_mode
, VolatileMode
, "Failed to parse volatile mode");
110 int config_parse_expose_port(
112 const char *filename
,
115 unsigned section_line
,
129 r
= expose_port_parse(&s
->expose_ports
, rvalue
);
131 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Duplicate port specification, ignoring: %s", rvalue
);
135 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse host port %s: %m", rvalue
);
142 int config_parse_capability(
144 const char *filename
,
147 unsigned section_line
,
154 uint64_t u
= 0, *result
= data
;
162 _cleanup_free_
char *word
= NULL
;
165 r
= extract_first_word(&rvalue
, &word
, NULL
, 0);
167 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract capability string, ignoring: %s", rvalue
);
173 cap
= capability_from_name(word
);
175 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse capability, ignoring: %s", word
);
179 u
|= 1 << ((uint64_t) cap
);
189 int config_parse_id128(
191 const char *filename
,
194 unsigned section_line
,
201 sd_id128_t t
, *result
= data
;
208 r
= sd_id128_from_string(rvalue
, &t
);
210 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse 128bit ID/UUID, ignoring: %s", rvalue
);
218 int config_parse_bind(
220 const char *filename
,
223 unsigned section_line
,
230 Settings
*settings
= data
;
237 r
= bind_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
, ltype
);
239 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid bind mount specification %s: %m", rvalue
);
246 int config_parse_tmpfs(
248 const char *filename
,
251 unsigned section_line
,
258 Settings
*settings
= data
;
265 r
= tmpfs_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
);
267 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid temporary file system specification %s: %m", rvalue
);
271 if (settings
->network_bridge
)
272 settings
->network_veth
= true;
274 if (settings
->network_interfaces
||
275 settings
->network_macvlan
||
276 settings
->network_ipvlan
||
277 settings
->network_bridge
||
278 settings
->network_veth
)
279 settings
->private_network
= true;