2 This file is part of systemd.
4 Copyright 2015 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "alloc-util.h"
22 #include "conf-parser.h"
23 #include "nspawn-network.h"
24 #include "nspawn-settings.h"
25 #include "parse-util.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);
41 s
->start_mode
= _START_MODE_INVALID
;
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
);
76 free(s
->working_directory
);
78 strv_free(s
->network_interfaces
);
79 strv_free(s
->network_macvlan
);
80 strv_free(s
->network_ipvlan
);
81 strv_free(s
->network_veth_extra
);
82 free(s
->network_bridge
);
83 expose_port_free_all(s
->expose_ports
);
85 custom_mount_free_all(s
->custom_mounts
, s
->n_custom_mounts
);
91 bool settings_private_network(Settings
*s
) {
95 s
->private_network
> 0 ||
96 s
->network_veth
> 0 ||
98 s
->network_interfaces
||
101 s
->network_veth_extra
;
104 bool settings_network_veth(Settings
*s
) {
108 s
->network_veth
> 0 ||
112 DEFINE_CONFIG_PARSE_ENUM(config_parse_volatile_mode
, volatile_mode
, VolatileMode
, "Failed to parse volatile mode");
114 int config_parse_expose_port(
116 const char *filename
,
119 unsigned section_line
,
133 r
= expose_port_parse(&s
->expose_ports
, rvalue
);
135 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Duplicate port specification, ignoring: %s", rvalue
);
139 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse host port %s: %m", rvalue
);
146 int config_parse_capability(
148 const char *filename
,
151 unsigned section_line
,
158 uint64_t u
= 0, *result
= data
;
166 _cleanup_free_
char *word
= NULL
;
169 r
= extract_first_word(&rvalue
, &word
, NULL
, 0);
171 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract capability string, ignoring: %s", rvalue
);
177 cap
= capability_from_name(word
);
179 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse capability, ignoring: %s", word
);
183 u
|= 1 << ((uint64_t) cap
);
193 int config_parse_id128(
195 const char *filename
,
198 unsigned section_line
,
205 sd_id128_t t
, *result
= data
;
212 r
= sd_id128_from_string(rvalue
, &t
);
214 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse 128bit ID/UUID, ignoring: %s", rvalue
);
222 int config_parse_bind(
224 const char *filename
,
227 unsigned section_line
,
234 Settings
*settings
= data
;
241 r
= bind_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
, ltype
);
243 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid bind mount specification %s: %m", rvalue
);
250 int config_parse_tmpfs(
252 const char *filename
,
255 unsigned section_line
,
262 Settings
*settings
= data
;
269 r
= tmpfs_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
);
271 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid temporary file system specification %s: %m", rvalue
);
278 int config_parse_veth_extra(
280 const char *filename
,
283 unsigned section_line
,
290 Settings
*settings
= data
;
297 r
= veth_extra_parse(&settings
->network_veth_extra
, rvalue
);
299 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid extra virtual Ethernet link specification %s: %m", rvalue
);
306 int config_parse_boot(
308 const char *filename
,
311 unsigned section_line
,
318 Settings
*settings
= data
;
325 r
= parse_boolean(rvalue
);
327 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse Boot= parameter %s, ignoring: %m", rvalue
);
332 if (settings
->start_mode
== START_PID2
)
335 settings
->start_mode
= START_BOOT
;
337 if (settings
->start_mode
== START_BOOT
)
340 if (settings
->start_mode
< 0)
341 settings
->start_mode
= START_PID1
;
347 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Conflicting Boot= or ProcessTwo= setting found. Ignoring.");
351 int config_parse_pid2(
353 const char *filename
,
356 unsigned section_line
,
363 Settings
*settings
= data
;
370 r
= parse_boolean(rvalue
);
372 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse ProcessTwo= parameter %s, ignoring: %m", rvalue
);
377 if (settings
->start_mode
== START_BOOT
)
380 settings
->start_mode
= START_PID2
;
382 if (settings
->start_mode
== START_PID2
)
385 if (settings
->start_mode
< 0)
386 settings
->start_mode
= START_PID1
;
392 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Conflicting Boot= or ProcessTwo= setting found. Ignoring.");