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 "parse-util.h"
28 #include "process-util.h"
32 int settings_load(FILE *f
, const char *path
, Settings
**ret
) {
33 _cleanup_(settings_freep
) Settings
*s
= NULL
;
39 s
= new0(Settings
, 1);
43 s
->start_mode
= _START_MODE_INVALID
;
44 s
->personality
= PERSONALITY_INVALID
;
47 s
->volatile_mode
= _VOLATILE_MODE_INVALID
;
49 s
->private_network
= -1;
52 r
= config_parse(NULL
, path
, f
,
56 config_item_perf_lookup
, nspawn_gperf_lookup
,
70 Settings
* settings_free(Settings
*s
) {
75 strv_free(s
->parameters
);
76 strv_free(s
->environment
);
78 free(s
->working_directory
);
80 strv_free(s
->network_interfaces
);
81 strv_free(s
->network_macvlan
);
82 strv_free(s
->network_ipvlan
);
83 strv_free(s
->network_veth_extra
);
84 free(s
->network_bridge
);
85 expose_port_free_all(s
->expose_ports
);
87 custom_mount_free_all(s
->custom_mounts
, s
->n_custom_mounts
);
93 bool settings_private_network(Settings
*s
) {
97 s
->private_network
> 0 ||
98 s
->network_veth
> 0 ||
100 s
->network_interfaces
||
101 s
->network_macvlan
||
103 s
->network_veth_extra
;
106 bool settings_network_veth(Settings
*s
) {
110 s
->network_veth
> 0 ||
114 DEFINE_CONFIG_PARSE_ENUM(config_parse_volatile_mode
, volatile_mode
, VolatileMode
, "Failed to parse volatile mode");
116 int config_parse_expose_port(
118 const char *filename
,
121 unsigned section_line
,
135 r
= expose_port_parse(&s
->expose_ports
, rvalue
);
137 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Duplicate port specification, ignoring: %s", rvalue
);
141 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse host port %s: %m", rvalue
);
148 int config_parse_capability(
150 const char *filename
,
153 unsigned section_line
,
160 uint64_t u
= 0, *result
= data
;
168 _cleanup_free_
char *word
= NULL
;
171 r
= extract_first_word(&rvalue
, &word
, NULL
, 0);
173 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract capability string, ignoring: %s", rvalue
);
179 cap
= capability_from_name(word
);
181 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse capability, ignoring: %s", word
);
185 u
|= 1 << ((uint64_t) cap
);
195 int config_parse_id128(
197 const char *filename
,
200 unsigned section_line
,
207 sd_id128_t t
, *result
= data
;
214 r
= sd_id128_from_string(rvalue
, &t
);
216 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse 128bit ID/UUID, ignoring: %s", rvalue
);
224 int config_parse_bind(
226 const char *filename
,
229 unsigned section_line
,
236 Settings
*settings
= data
;
243 r
= bind_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
, ltype
);
245 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid bind mount specification %s: %m", rvalue
);
252 int config_parse_tmpfs(
254 const char *filename
,
257 unsigned section_line
,
264 Settings
*settings
= data
;
271 r
= tmpfs_mount_parse(&settings
->custom_mounts
, &settings
->n_custom_mounts
, rvalue
);
273 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid temporary file system specification %s: %m", rvalue
);
280 int config_parse_veth_extra(
282 const char *filename
,
285 unsigned section_line
,
292 Settings
*settings
= data
;
299 r
= veth_extra_parse(&settings
->network_veth_extra
, rvalue
);
301 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid extra virtual Ethernet link specification %s: %m", rvalue
);
308 int config_parse_boot(
310 const char *filename
,
313 unsigned section_line
,
320 Settings
*settings
= data
;
327 r
= parse_boolean(rvalue
);
329 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse Boot= parameter %s, ignoring: %m", rvalue
);
334 if (settings
->start_mode
== START_PID2
)
337 settings
->start_mode
= START_BOOT
;
339 if (settings
->start_mode
== START_BOOT
)
342 if (settings
->start_mode
< 0)
343 settings
->start_mode
= START_PID1
;
349 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Conflicting Boot= or ProcessTwo= setting found. Ignoring.");
353 int config_parse_pid2(
355 const char *filename
,
358 unsigned section_line
,
365 Settings
*settings
= data
;
372 r
= parse_boolean(rvalue
);
374 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse ProcessTwo= parameter %s, ignoring: %m", rvalue
);
379 if (settings
->start_mode
== START_BOOT
)
382 settings
->start_mode
= START_PID2
;
384 if (settings
->start_mode
== START_PID2
)
387 if (settings
->start_mode
< 0)
388 settings
->start_mode
= START_PID1
;
394 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Conflicting Boot= or ProcessTwo= setting found. Ignoring.");