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 DEFINE_CONFIG_PARSE_ENUM(config_parse_volatile_mode
, volatile_mode
, VolatileMode
, "Failed to parse volatile mode");
90 int config_parse_expose_port(
95 unsigned section_line
,
109 r
= expose_port_parse(&s
->expose_ports
, rvalue
);
111 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Duplicate port specification, ignoring: %s", rvalue
);
115 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse host port %s: %m", rvalue
);
122 int config_parse_capability(
124 const char *filename
,
127 unsigned section_line
,
134 uint64_t u
= 0, *result
= data
;
142 _cleanup_free_
char *word
= NULL
;
145 r
= extract_first_word(&rvalue
, &word
, NULL
, 0);
147 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract capability string, ignoring: %s", rvalue
);
153 cap
= capability_from_name(word
);
155 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse capability, ignoring: %s", word
);
159 u
|= 1 << ((uint64_t) cap
);
169 int config_parse_id128(
171 const char *filename
,
174 unsigned section_line
,
181 sd_id128_t t
, *result
= data
;
188 r
= sd_id128_from_string(rvalue
, &t
);
190 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse 128bit ID/UUID, ignoring: %s", rvalue
);
198 int config_parse_bind(
200 const char *filename
,
203 unsigned section_line
,
210 Settings
*settings
= data
;
217 r
= bind_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
, ltype
);
219 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid bind mount specification %s: %m", rvalue
);
226 int config_parse_tmpfs(
228 const char *filename
,
231 unsigned section_line
,
238 Settings
*settings
= data
;
245 r
= tmpfs_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
);
247 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid temporary file system specification %s: %m", rvalue
);
251 if (settings
->network_bridge
)
252 settings
->network_veth
= true;
254 if (settings
->network_interfaces
||
255 settings
->network_macvlan
||
256 settings
->network_ipvlan
||
257 settings
->network_bridge
||
258 settings
->network_veth
)
259 settings
->private_network
= true;