Commit b3c723c4 by Serge Hallyn Committed by GitHub

Merge pull request #1756 from brauner/2017-08-10/further_lxc_2.1_preparations

further lxc 2.1 preparations
parents ed07dfa9 d6259d36
...@@ -68,14 +68,12 @@ ...@@ -68,14 +68,12 @@
lxc_log_define(lxc_confile, lxc); lxc_log_define(lxc_confile, lxc);
#define lxc_config_define(name) \ #define lxc_config_define(name) \
static int set_config_##name(const char *, const char *, \ static int set_config_##name(const char *, const char *, \
struct lxc_conf *, void *); \ struct lxc_conf *, void *); \
static int get_config_##name(const char *, char *, int, \ static int get_config_##name(const char *, char *, int, \
struct lxc_conf *, void *); \ struct lxc_conf *, void *); \
static int clr_config_##name(const char *, struct lxc_conf *, \ static int clr_config_##name(const char *, struct lxc_conf *, void *);
void *);
lxc_config_define(personality); lxc_config_define(personality);
lxc_config_define(pty_max); lxc_config_define(pty_max);
...@@ -139,54 +137,39 @@ lxc_config_define(prlimit); ...@@ -139,54 +137,39 @@ lxc_config_define(prlimit);
static struct lxc_config_t config[] = { static struct lxc_config_t config[] = {
/* REMOVE in LXC 3.0 */ /* REMOVE in LXC 3.0 */
{ "lxc.arch", false, set_config_personality, get_config_personality, clr_config_personality, }, { "lxc.arch", false, set_config_personality, get_config_personality, clr_config_personality, },
{ "lxc.pty.max", false, set_config_pty_max, get_config_pty_max, clr_config_pty_max, },
{ "lxc.tty.dir", false, set_config_tty_dir, get_config_tty_dir, clr_config_tty_dir, },
{ "lxc.tty.max", false, set_config_tty_max, get_config_tty_max, clr_config_tty_max, },
/* [START]: REMOVE IN LXC 3.0 */
{ "lxc.pts", true, set_config_pty_max, get_config_pty_max, clr_config_pty_max, },
{ "lxc.devttydir", true, set_config_tty_dir, get_config_tty_dir, clr_config_tty_dir, },
{ "lxc.tty", true, set_config_tty_max, get_config_tty_max, clr_config_tty_max, },
/* [END]: REMOVE IN LXC 3.0 */
{ "lxc.apparmor.profile", false, set_config_apparmor_profile, get_config_apparmor_profile, clr_config_apparmor_profile, }, { "lxc.apparmor.profile", false, set_config_apparmor_profile, get_config_apparmor_profile, clr_config_apparmor_profile, },
{ "lxc.apparmor.allow_incomplete", false, set_config_apparmor_allow_incomplete, get_config_apparmor_allow_incomplete, clr_config_apparmor_allow_incomplete, }, { "lxc.apparmor.allow_incomplete", false, set_config_apparmor_allow_incomplete, get_config_apparmor_allow_incomplete, clr_config_apparmor_allow_incomplete, },
{ "lxc.selinux.context", false, set_config_selinux_context, get_config_selinux_context, clr_config_selinux_context, }, { "lxc.autodev", false, set_config_autodev, get_config_autodev, clr_config_autodev, },
{ "lxc.cap.drop", false, set_config_cap_drop, get_config_cap_drop, clr_config_cap_drop, },
/* [START]: REMOVE IN LXC 3.0 */ { "lxc.cap.keep", false, set_config_cap_keep, get_config_cap_keep, clr_config_cap_keep, },
{ "lxc.aa_profile", true, set_config_lsm_aa_profile, get_config_lsm_aa_profile, clr_config_lsm_aa_profile, },
{ "lxc.aa_allow_incomplete", true, set_config_lsm_aa_incomplete, get_config_lsm_aa_incomplete, clr_config_lsm_aa_incomplete, },
{ "lxc.se_context", true, set_config_lsm_se_context, get_config_lsm_se_context, clr_config_lsm_se_context, },
/* [END]: REMOVE IN LXC 3.0 */
{ "lxc.cgroup", false, set_config_cgroup, get_config_cgroup, clr_config_cgroup, }, { "lxc.cgroup", false, set_config_cgroup, get_config_cgroup, clr_config_cgroup, },
{ "lxc.idmap", false, set_config_idmaps, get_config_idmaps, clr_config_idmaps, }, { "lxc.console.logfile", false, set_config_console_logfile, get_config_console_logfile, clr_config_console_logfile, },
{ "lxc.mount.entry", false, set_config_mount, get_config_mount, clr_config_mount, }, { "lxc.console.path", false, set_config_console_path, get_config_console_path, clr_config_console_path, },
{ "lxc.mount.auto", false, set_config_mount_auto, get_config_mount_auto, clr_config_mount_auto, }, { "lxc.environment", false, set_config_environment, get_config_environment, clr_config_environment, },
{ "lxc.mount.fstab", false, set_config_mount_fstab, get_config_mount_fstab, clr_config_mount_fstab, }, { "lxc.ephemeral", false, set_config_ephemeral, get_config_ephemeral, clr_config_ephemeral, },
{ "lxc.rootfs.mount", false, set_config_rootfs_mount, get_config_rootfs_mount, clr_config_rootfs_mount, }, { "lxc.group", false, set_config_group, get_config_group, clr_config_group, },
{ "lxc.rootfs.options", false, set_config_rootfs_options, get_config_rootfs_options, clr_config_rootfs_options, }, { "lxc.hook.autodev", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.rootfs.path", false, set_config_rootfs_path, get_config_rootfs_path, clr_config_rootfs_path, }, { "lxc.hook.clone", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.destroy", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
/* [START]: REMOVE IN LXC 3.0 */ { "lxc.hook.mount", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.id_map", true, set_config_idmaps, get_config_idmaps, clr_config_idmaps, }, { "lxc.hook.post-stop", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.mount", true, set_config_mount_fstab, get_config_mount_fstab, clr_config_mount_fstab, },
{ "lxc.rootfs.backend", true, set_config_rootfs_backend, get_config_rootfs_backend, clr_config_rootfs_backend, },
{ "lxc.rootfs", true, set_config_rootfs_path, get_config_rootfs_path, clr_config_rootfs_path, },
{ "lxc.utsname", true, set_config_uts_name, get_config_uts_name, clr_config_uts_name, },
/* [END]: REMOVE IN LXC 3.0 */
{ "lxc.uts.name", false, set_config_uts_name, get_config_uts_name, clr_config_uts_name, },
{ "lxc.hook.pre-start", false, set_config_hooks, get_config_hooks, clr_config_hooks, }, { "lxc.hook.pre-start", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.pre-mount", false, set_config_hooks, get_config_hooks, clr_config_hooks, }, { "lxc.hook.pre-mount", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.mount", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.autodev", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.start", false, set_config_hooks, get_config_hooks, clr_config_hooks, }, { "lxc.hook.start", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.stop", false, set_config_hooks, get_config_hooks, clr_config_hooks, }, { "lxc.hook.stop", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.post-stop", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.clone", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.destroy", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook", false, set_config_hooks, get_config_hooks, clr_config_hooks, }, { "lxc.hook", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.idmap", false, set_config_idmaps, get_config_idmaps, clr_config_idmaps, },
{ "lxc.include", false, set_config_includefiles, get_config_includefiles, clr_config_includefiles, },
{ "lxc.init.cmd", false, set_config_init_cmd, get_config_init_cmd, clr_config_init_cmd, },
{ "lxc.init.gid", false, set_config_init_gid, get_config_init_gid, clr_config_init_gid, },
{ "lxc.init.uid", false, set_config_init_uid, get_config_init_uid, clr_config_init_uid, },
{ "lxc.log.file", false, set_config_log_file, get_config_log_file, clr_config_log_file, },
{ "lxc.log.level", false, set_config_log_level, get_config_log_level, clr_config_log_level, },
{ "lxc.log.syslog", false, set_config_log_syslog, get_config_log_syslog, clr_config_log_syslog, },
{ "lxc.monitor.unshare", false, set_config_monitor, get_config_monitor, clr_config_monitor, },
{ "lxc.mount.auto", false, set_config_mount_auto, get_config_mount_auto, clr_config_mount_auto, },
{ "lxc.mount.entry", false, set_config_mount, get_config_mount, clr_config_mount, },
{ "lxc.mount.fstab", false, set_config_mount_fstab, get_config_mount_fstab, clr_config_mount_fstab, },
/* [START]: REMOVE IN LXC 3.0 */ /* [START]: REMOVE IN LXC 3.0 */
{ "lxc.network.type", true, set_config_network_legacy_type, get_config_network_legacy_item, clr_config_network_legacy_item, }, { "lxc.network.type", true, set_config_network_legacy_type, get_config_network_legacy_item, clr_config_network_legacy_item, },
...@@ -208,52 +191,58 @@ static struct lxc_config_t config[] = { ...@@ -208,52 +191,58 @@ static struct lxc_config_t config[] = {
{ "lxc.network", true, set_config_network_legacy, get_config_network_legacy, clr_config_network_legacy, }, { "lxc.network", true, set_config_network_legacy, get_config_network_legacy, clr_config_network_legacy, },
/* [END]: REMOVE IN LXC 3.0 */ /* [END]: REMOVE IN LXC 3.0 */
{ "lxc.net.type", false, set_config_net_type, get_config_net_type, clr_config_net_type, },
{ "lxc.net.flags", false, set_config_net_flags, get_config_net_flags, clr_config_net_flags, }, { "lxc.net.flags", false, set_config_net_flags, get_config_net_flags, clr_config_net_flags, },
{ "lxc.net.hwaddr", false, set_config_net_hwaddr, get_config_net_hwaddr, clr_config_net_hwaddr, },
{ "lxc.net.ipv4.address", false, set_config_net_ipv4_address, get_config_net_ipv4_address, clr_config_net_ipv4_address, },
{ "lxc.net.ipv4.gateway", false, set_config_net_ipv4_gateway, get_config_net_ipv4_gateway, clr_config_net_ipv4_gateway, },
{ "lxc.net.ipv6.address", false, set_config_net_ipv6_address, get_config_net_ipv6_address, clr_config_net_ipv6_address, },
{ "lxc.net.ipv6.gateway", false, set_config_net_ipv6_gateway, get_config_net_ipv6_gateway, clr_config_net_ipv6_gateway, },
{ "lxc.net.link", false, set_config_net_link, get_config_net_link, clr_config_net_link, }, { "lxc.net.link", false, set_config_net_link, get_config_net_link, clr_config_net_link, },
{ "lxc.net.name", false, set_config_net_name, get_config_net_name, clr_config_net_name, },
{ "lxc.net.macvlan.mode", false, set_config_net_macvlan_mode, get_config_net_macvlan_mode, clr_config_net_macvlan_mode, }, { "lxc.net.macvlan.mode", false, set_config_net_macvlan_mode, get_config_net_macvlan_mode, clr_config_net_macvlan_mode, },
{ "lxc.net.veth.pair", false, set_config_net_veth_pair, get_config_net_veth_pair, clr_config_net_veth_pair, },
{ "lxc.net.script.up", false, set_config_net_script_up, get_config_net_script_up, clr_config_net_script_up, },
{ "lxc.net.script.down", false, set_config_net_script_down, get_config_net_script_down, clr_config_net_script_down, },
{ "lxc.net.hwaddr", false, set_config_net_hwaddr, get_config_net_hwaddr, clr_config_net_hwaddr, },
{ "lxc.net.mtu", false, set_config_net_mtu, get_config_net_mtu, clr_config_net_mtu, }, { "lxc.net.mtu", false, set_config_net_mtu, get_config_net_mtu, clr_config_net_mtu, },
{ "lxc.net.name", false, set_config_net_name, get_config_net_name, clr_config_net_name, },
{ "lxc.net.script.down", false, set_config_net_script_down, get_config_net_script_down, clr_config_net_script_down, },
{ "lxc.net.script.up", false, set_config_net_script_up, get_config_net_script_up, clr_config_net_script_up, },
{ "lxc.net.type", false, set_config_net_type, get_config_net_type, clr_config_net_type, },
{ "lxc.net.vlan.id", false, set_config_net_vlan_id, get_config_net_vlan_id, clr_config_net_vlan_id, }, { "lxc.net.vlan.id", false, set_config_net_vlan_id, get_config_net_vlan_id, clr_config_net_vlan_id, },
{ "lxc.net.ipv4.gateway", false, set_config_net_ipv4_gateway, get_config_net_ipv4_gateway, clr_config_net_ipv4_gateway, }, { "lxc.net.veth.pair", false, set_config_net_veth_pair, get_config_net_veth_pair, clr_config_net_veth_pair, },
{ "lxc.net.ipv4.address", false, set_config_net_ipv4_address, get_config_net_ipv4_address, clr_config_net_ipv4_address, },
{ "lxc.net.ipv6.gateway", false, set_config_net_ipv6_gateway, get_config_net_ipv6_gateway, clr_config_net_ipv6_gateway, },
{ "lxc.net.ipv6.address", false, set_config_net_ipv6_address, get_config_net_ipv6_address, clr_config_net_ipv6_address, },
{ "lxc.net.", false, set_config_net_nic, get_config_net_nic, clr_config_net_nic, }, { "lxc.net.", false, set_config_net_nic, get_config_net_nic, clr_config_net_nic, },
{ "lxc.net", false, set_config_net, get_config_net, clr_config_net, }, { "lxc.net", false, set_config_net, get_config_net, clr_config_net, },
{ "lxc.cap.drop", false, set_config_cap_drop, get_config_cap_drop, clr_config_cap_drop, }, { "lxc.no_new_privs", false, set_config_no_new_privs, get_config_no_new_privs, clr_config_no_new_privs, },
{ "lxc.cap.keep", false, set_config_cap_keep, get_config_cap_keep, clr_config_cap_keep, }, { "lxc.prlimit", false, set_config_prlimit, get_config_prlimit, clr_config_prlimit, },
{ "lxc.console.logfile", false, set_config_console_logfile, get_config_console_logfile, clr_config_console_logfile, }, { "lxc.pty.max", false, set_config_pty_max, get_config_pty_max, clr_config_pty_max, },
{ "lxc.console.path", false, set_config_console_path, get_config_console_path, clr_config_console_path, }, { "lxc.rootfs.mount", false, set_config_rootfs_mount, get_config_rootfs_mount, clr_config_rootfs_mount, },
{ "lxc.rootfs.options", false, set_config_rootfs_options, get_config_rootfs_options, clr_config_rootfs_options, },
{ "lxc.rootfs.path", false, set_config_rootfs_path, get_config_rootfs_path, clr_config_rootfs_path, },
{ "lxc.seccomp.profile", false, set_config_seccomp_profile, get_config_seccomp_profile, clr_config_seccomp_profile, }, { "lxc.seccomp.profile", false, set_config_seccomp_profile, get_config_seccomp_profile, clr_config_seccomp_profile, },
{ "lxc.include", false, set_config_includefiles, get_config_includefiles, clr_config_includefiles, }, { "lxc.selinux.context", false, set_config_selinux_context, get_config_selinux_context, clr_config_selinux_context, },
{ "lxc.autodev", false, set_config_autodev, get_config_autodev, clr_config_autodev, },
/* [START]: REMOVE IN LXC 3.0 */
{ "lxc.seccomp", true, set_config_seccomp_profile, get_config_seccomp_profile, clr_config_seccomp_profile, },
{ "lxc.console", true, set_config_console_path, get_config_console_path, clr_config_console_path, },
{ "lxc.haltsignal", true, set_config_signal_halt, get_config_signal_halt, clr_config_signal_halt, },
{ "lxc.rebootsignal", true, set_config_signal_reboot, get_config_signal_reboot, clr_config_signal_reboot, },
{ "lxc.stopsignal", true, set_config_signal_stop, get_config_signal_stop, clr_config_signal_stop, },
/* [END]: REMOVE IN LXC 3.0 */
{ "lxc.signal.halt", false, set_config_signal_halt, get_config_signal_halt, clr_config_signal_halt, }, { "lxc.signal.halt", false, set_config_signal_halt, get_config_signal_halt, clr_config_signal_halt, },
{ "lxc.signal.reboot", false, set_config_signal_reboot, get_config_signal_reboot, clr_config_signal_reboot, }, { "lxc.signal.reboot", false, set_config_signal_reboot, get_config_signal_reboot, clr_config_signal_reboot, },
{ "lxc.signal.stop", false, set_config_signal_stop, get_config_signal_stop, clr_config_signal_stop, }, { "lxc.signal.stop", false, set_config_signal_stop, get_config_signal_stop, clr_config_signal_stop, },
{ "lxc.start.auto", false, set_config_start, get_config_start, clr_config_start, }, { "lxc.start.auto", false, set_config_start, get_config_start, clr_config_start, },
{ "lxc.start.delay", false, set_config_start, get_config_start, clr_config_start, }, { "lxc.start.delay", false, set_config_start, get_config_start, clr_config_start, },
{ "lxc.start.order", false, set_config_start, get_config_start, clr_config_start, }, { "lxc.start.order", false, set_config_start, get_config_start, clr_config_start, },
{ "lxc.monitor.unshare", false, set_config_monitor, get_config_monitor, clr_config_monitor, }, { "lxc.tty.dir", false, set_config_tty_dir, get_config_tty_dir, clr_config_tty_dir, },
{ "lxc.group", false, set_config_group, get_config_group, clr_config_group, }, { "lxc.tty.max", false, set_config_tty_max, get_config_tty_max, clr_config_tty_max, },
{ "lxc.environment", false, set_config_environment, get_config_environment, clr_config_environment, }, { "lxc.uts.name", false, set_config_uts_name, get_config_uts_name, clr_config_uts_name, },
{ "lxc.ephemeral", false, set_config_ephemeral, get_config_ephemeral, clr_config_ephemeral, },
{ "lxc.no_new_privs", false, set_config_no_new_privs, get_config_no_new_privs, clr_config_no_new_privs, },
/* [START]: REMOVE IN LXC 3.0 */ /* [START]: REMOVE IN LXC 3.0 */
{ "lxc.pts", true, set_config_pty_max, get_config_pty_max, clr_config_pty_max, },
{ "lxc.devttydir", true, set_config_tty_dir, get_config_tty_dir, clr_config_tty_dir, },
{ "lxc.tty", true, set_config_tty_max, get_config_tty_max, clr_config_tty_max, },
{ "lxc.aa_profile", true, set_config_lsm_aa_profile, get_config_lsm_aa_profile, clr_config_lsm_aa_profile, },
{ "lxc.aa_allow_incomplete", true, set_config_lsm_aa_incomplete, get_config_lsm_aa_incomplete, clr_config_lsm_aa_incomplete, },
{ "lxc.se_context", true, set_config_lsm_se_context, get_config_lsm_se_context, clr_config_lsm_se_context, },
{ "lxc.id_map", true, set_config_idmaps, get_config_idmaps, clr_config_idmaps, },
{ "lxc.mount", true, set_config_mount_fstab, get_config_mount_fstab, clr_config_mount_fstab, },
{ "lxc.rootfs.backend", true, set_config_rootfs_backend, get_config_rootfs_backend, clr_config_rootfs_backend, },
{ "lxc.rootfs", true, set_config_rootfs_path, get_config_rootfs_path, clr_config_rootfs_path, },
{ "lxc.utsname", true, set_config_uts_name, get_config_uts_name, clr_config_uts_name, },
{ "lxc.seccomp", true, set_config_seccomp_profile, get_config_seccomp_profile, clr_config_seccomp_profile, },
{ "lxc.console", true, set_config_console_path, get_config_console_path, clr_config_console_path, },
{ "lxc.haltsignal", true, set_config_signal_halt, get_config_signal_halt, clr_config_signal_halt, },
{ "lxc.rebootsignal", true, set_config_signal_reboot, get_config_signal_reboot, clr_config_signal_reboot, },
{ "lxc.stopsignal", true, set_config_signal_stop, get_config_signal_stop, clr_config_signal_stop, },
{ "lxc.syslog", true, set_config_log_syslog, get_config_log_syslog, clr_config_log_syslog, }, { "lxc.syslog", true, set_config_log_syslog, get_config_log_syslog, clr_config_log_syslog, },
{ "lxc.loglevel", true, set_config_log_level, get_config_log_level, clr_config_log_level, }, { "lxc.loglevel", true, set_config_log_level, get_config_log_level, clr_config_log_level, },
{ "lxc.logfile", true, set_config_log_file, get_config_log_file, clr_config_log_file, }, { "lxc.logfile", true, set_config_log_file, get_config_log_file, clr_config_log_file, },
...@@ -262,14 +251,6 @@ static struct lxc_config_t config[] = { ...@@ -262,14 +251,6 @@ static struct lxc_config_t config[] = {
{ "lxc.init_gid", true, set_config_init_gid, get_config_init_gid, clr_config_init_gid, }, { "lxc.init_gid", true, set_config_init_gid, get_config_init_gid, clr_config_init_gid, },
{ "lxc.limit", true, set_config_limit, get_config_limit, clr_config_limit, }, { "lxc.limit", true, set_config_limit, get_config_limit, clr_config_limit, },
/* [END]: REMOVE IN LXC 3.0 */ /* [END]: REMOVE IN LXC 3.0 */
{ "lxc.log.syslog", false, set_config_log_syslog, get_config_log_syslog, clr_config_log_syslog, },
{ "lxc.log.level", false, set_config_log_level, get_config_log_level, clr_config_log_level, },
{ "lxc.log.file", false, set_config_log_file, get_config_log_file, clr_config_log_file, },
{ "lxc.init.cmd", false, set_config_init_cmd, get_config_init_cmd, clr_config_init_cmd, },
{ "lxc.init.uid", false, set_config_init_uid, get_config_init_uid, clr_config_init_uid, },
{ "lxc.init.gid", false, set_config_init_gid, get_config_init_gid, clr_config_init_gid, },
{ "lxc.prlimit", false, set_config_prlimit, get_config_prlimit, clr_config_prlimit, },
}; };
struct signame { struct signame {
...@@ -438,7 +419,7 @@ static int set_config_net_flags(const char *key, const char *value, ...@@ -438,7 +419,7 @@ static int set_config_net_flags(const char *key, const char *value,
} }
static int create_matched_ifnames(const char *value, struct lxc_conf *lxc_conf, static int create_matched_ifnames(const char *value, struct lxc_conf *lxc_conf,
struct lxc_netdev *netdev) struct lxc_netdev *netdev)
{ {
struct ifaddrs *ifaddr, *ifa; struct ifaddrs *ifaddr, *ifa;
int n; int n;
...@@ -576,10 +557,9 @@ static int set_config_net_hwaddr(const char *key, const char *value, ...@@ -576,10 +557,9 @@ static int set_config_net_hwaddr(const char *key, const char *value,
return -1; return -1;
new_value = strdup(value); new_value = strdup(value);
if (!new_value) { if (!new_value)
SYSERROR("failed to strdup \"%s\"", value);
return -1; return -1;
}
rand_complete_hwaddr(new_value); rand_complete_hwaddr(new_value);
if (lxc_config_value_empty(new_value)) { if (lxc_config_value_empty(new_value)) {
...@@ -595,6 +575,7 @@ static int set_config_net_hwaddr(const char *key, const char *value, ...@@ -595,6 +575,7 @@ static int set_config_net_hwaddr(const char *key, const char *value,
static int set_config_net_vlan_id(const char *key, const char *value, static int set_config_net_vlan_id(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
int ret;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
...@@ -607,7 +588,8 @@ static int set_config_net_vlan_id(const char *key, const char *value, ...@@ -607,7 +588,8 @@ static int set_config_net_vlan_id(const char *key, const char *value,
if (!netdev) if (!netdev)
return -1; return -1;
if (get_u16(&netdev->priv.vlan_attr.vid, value, 0)) ret = get_u16(&netdev->priv.vlan_attr.vid, value, 0);
if (ret < 0)
return -1; return -1;
return 0; return 0;
...@@ -634,6 +616,7 @@ static int set_config_net_mtu(const char *key, const char *value, ...@@ -634,6 +616,7 @@ static int set_config_net_mtu(const char *key, const char *value,
static int set_config_net_ipv4_address(const char *key, const char *value, static int set_config_net_ipv4_address(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
int ret;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
struct lxc_inetdev *inetdev; struct lxc_inetdev *inetdev;
struct lxc_list *list; struct lxc_list *list;
...@@ -651,15 +634,13 @@ static int set_config_net_ipv4_address(const char *key, const char *value, ...@@ -651,15 +634,13 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
return -1; return -1;
inetdev = malloc(sizeof(*inetdev)); inetdev = malloc(sizeof(*inetdev));
if (!inetdev) { if (!inetdev)
SYSERROR("failed to allocate ipv4 address");
return -1; return -1;
}
memset(inetdev, 0, sizeof(*inetdev)); memset(inetdev, 0, sizeof(*inetdev));
list = malloc(sizeof(*list)); list = malloc(sizeof(*list));
if (!list) { if (!list) {
SYSERROR("failed to allocate memory");
free(inetdev); free(inetdev);
return -1; return -1;
} }
...@@ -669,7 +650,6 @@ static int set_config_net_ipv4_address(const char *key, const char *value, ...@@ -669,7 +650,6 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
addr = strdup(value); addr = strdup(value);
if (!addr) { if (!addr) {
ERROR("no address specified");
free(inetdev); free(inetdev);
free(list); free(list);
return -1; return -1;
...@@ -687,25 +667,31 @@ static int set_config_net_ipv4_address(const char *key, const char *value, ...@@ -687,25 +667,31 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
prefix = slash + 1; prefix = slash + 1;
} }
if (!inet_pton(AF_INET, addr, &inetdev->addr)) { ret = inet_pton(AF_INET, addr, &inetdev->addr);
SYSERROR("invalid ipv4 address: %s", value); if (!ret || ret < 0) {
SYSERROR("Invalid ipv4 address \"%s\"", value);
free(inetdev); free(inetdev);
free(addr); free(addr);
free(list); free(list);
return -1; return -1;
} }
if (bcast && !inet_pton(AF_INET, bcast, &inetdev->bcast)) { if (bcast) {
SYSERROR("invalid ipv4 broadcast address: %s", value); ret = inet_pton(AF_INET, bcast, &inetdev->bcast);
free(inetdev); if (!ret || ret < 0) {
free(list); SYSERROR("Invalid ipv4 broadcast address \"%s\"", value);
free(addr); free(inetdev);
return -1; free(list);
free(addr);
return -1;
}
} }
/* No prefix specified, determine it from the network class. */ /* No prefix specified, determine it from the network class. */
if (prefix) { if (prefix) {
if (lxc_safe_uint(prefix, &inetdev->prefix) < 0) ret = lxc_safe_uint(prefix, &inetdev->prefix);
if (ret < 0)
return -1; return -1;
} else { } else {
inetdev->prefix = config_ip_prefix(&inetdev->addr); inetdev->prefix = config_ip_prefix(&inetdev->addr);
...@@ -716,8 +702,7 @@ static int set_config_net_ipv4_address(const char *key, const char *value, ...@@ -716,8 +702,7 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
*/ */
if (!bcast) { if (!bcast) {
inetdev->bcast.s_addr = inetdev->addr.s_addr; inetdev->bcast.s_addr = inetdev->addr.s_addr;
inetdev->bcast.s_addr |= inetdev->bcast.s_addr |= htonl(INADDR_BROADCAST >> inetdev->prefix);
htonl(INADDR_BROADCAST >> inetdev->prefix);
} }
lxc_list_add_tail(&netdev->ipv4, list); lxc_list_add_tail(&netdev->ipv4, list);
...@@ -747,16 +732,16 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value, ...@@ -747,16 +732,16 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value,
netdev->ipv4_gateway = NULL; netdev->ipv4_gateway = NULL;
netdev->ipv4_gateway_auto = true; netdev->ipv4_gateway_auto = true;
} else { } else {
int ret;
struct in_addr *gw; struct in_addr *gw;
gw = malloc(sizeof(*gw)); gw = malloc(sizeof(*gw));
if (!gw) { if (!gw)
SYSERROR("failed to allocate ipv4 gateway address");
return -1; return -1;
}
if (!inet_pton(AF_INET, value, gw)) { ret = inet_pton(AF_INET, value, gw);
SYSERROR("invalid ipv4 gateway address: %s", value); if (!ret || ret < 0) {
SYSERROR("Invalid ipv4 gateway address \"%s\"", value);
free(gw); free(gw);
return -1; return -1;
} }
...@@ -771,6 +756,7 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value, ...@@ -771,6 +756,7 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value,
static int set_config_net_ipv6_address(const char *key, const char *value, static int set_config_net_ipv6_address(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
int ret;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
struct lxc_inet6dev *inet6dev; struct lxc_inet6dev *inet6dev;
struct lxc_list *list; struct lxc_list *list;
...@@ -787,15 +773,13 @@ static int set_config_net_ipv6_address(const char *key, const char *value, ...@@ -787,15 +773,13 @@ static int set_config_net_ipv6_address(const char *key, const char *value,
return -1; return -1;
inet6dev = malloc(sizeof(*inet6dev)); inet6dev = malloc(sizeof(*inet6dev));
if (!inet6dev) { if (!inet6dev)
SYSERROR("failed to allocate ipv6 address");
return -1; return -1;
}
memset(inet6dev, 0, sizeof(*inet6dev)); memset(inet6dev, 0, sizeof(*inet6dev));
list = malloc(sizeof(*list)); list = malloc(sizeof(*list));
if (!list) { if (!list) {
SYSERROR("failed to allocate memory");
free(inet6dev); free(inet6dev);
return -1; return -1;
} }
...@@ -805,7 +789,6 @@ static int set_config_net_ipv6_address(const char *key, const char *value, ...@@ -805,7 +789,6 @@ static int set_config_net_ipv6_address(const char *key, const char *value,
valdup = strdup(value); valdup = strdup(value);
if (!valdup) { if (!valdup) {
ERROR("no address specified");
free(list); free(list);
free(inet6dev); free(inet6dev);
return -1; return -1;
...@@ -820,8 +803,9 @@ static int set_config_net_ipv6_address(const char *key, const char *value, ...@@ -820,8 +803,9 @@ static int set_config_net_ipv6_address(const char *key, const char *value,
return -1; return -1;
} }
if (!inet_pton(AF_INET6, valdup, &inet6dev->addr)) { ret = inet_pton(AF_INET6, valdup, &inet6dev->addr);
SYSERROR("invalid ipv6 address: %s", valdup); if (!ret || ret < 0) {
SYSERROR("Invalid ipv6 address \"%s\"", valdup);
free(list); free(list);
free(inet6dev); free(inet6dev);
free(valdup); free(valdup);
...@@ -855,16 +839,16 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value, ...@@ -855,16 +839,16 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value,
netdev->ipv6_gateway = NULL; netdev->ipv6_gateway = NULL;
netdev->ipv6_gateway_auto = true; netdev->ipv6_gateway_auto = true;
} else { } else {
int ret;
struct in6_addr *gw; struct in6_addr *gw;
gw = malloc(sizeof(*gw)); gw = malloc(sizeof(*gw));
if (!gw) { if (!gw)
SYSERROR("failed to allocate ipv6 gateway address");
return -1; return -1;
}
if (!inet_pton(AF_INET6, value, gw)) { ret = inet_pton(AF_INET6, value, gw);
SYSERROR("invalid ipv6 gateway address: %s", value); if (!ret || ret < 0) {
SYSERROR("Invalid ipv6 gateway address \"%s\"", value);
free(gw); free(gw);
return -1; return -1;
} }
...@@ -944,15 +928,14 @@ static int set_config_init_uid(const char *key, const char *value, ...@@ -944,15 +928,14 @@ static int set_config_init_uid(const char *key, const char *value,
{ {
unsigned int init_uid; unsigned int init_uid;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->init_uid = 0; lxc_conf->init_uid = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &init_uid) < 0) if (lxc_safe_uint(value, &init_uid) < 0)
return -1; return -1;
lxc_conf->init_uid = init_uid; lxc_conf->init_uid = init_uid;
return 0; return 0;
...@@ -963,15 +946,14 @@ static int set_config_init_gid(const char *key, const char *value, ...@@ -963,15 +946,14 @@ static int set_config_init_gid(const char *key, const char *value,
{ {
unsigned int init_gid; unsigned int init_gid;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->init_gid = 0; lxc_conf->init_gid = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &init_gid) < 0) if (lxc_safe_uint(value, &init_gid) < 0)
return -1; return -1;
lxc_conf->init_gid = init_gid; lxc_conf->init_gid = init_gid;
return 0; return 0;
...@@ -986,14 +968,13 @@ static int set_config_hooks(const char *key, const char *value, ...@@ -986,14 +968,13 @@ static int set_config_hooks(const char *key, const char *value,
return lxc_clear_hooks(lxc_conf, key); return lxc_clear_hooks(lxc_conf, key);
if (strcmp(key + 4, "hook") == 0) { if (strcmp(key + 4, "hook") == 0) {
ERROR("lxc.hook cannot take a value"); ERROR("lxc.hook must not have a value");
return -1; return -1;
} }
copy = strdup(value); copy = strdup(value);
if (!copy) { if (!copy)
SYSERROR("failed to dup string '%s'", value);
return -1; return -1;
}
if (strcmp(key + 9, "pre-start") == 0) if (strcmp(key + 9, "pre-start") == 0)
return add_hook(lxc_conf, LXCHOOK_PRESTART, copy); return add_hook(lxc_conf, LXCHOOK_PRESTART, copy);
...@@ -1014,7 +995,6 @@ static int set_config_hooks(const char *key, const char *value, ...@@ -1014,7 +995,6 @@ static int set_config_hooks(const char *key, const char *value,
else if (strcmp(key + 9, "destroy") == 0) else if (strcmp(key + 9, "destroy") == 0)
return add_hook(lxc_conf, LXCHOOK_DESTROY, copy); return add_hook(lxc_conf, LXCHOOK_DESTROY, copy);
SYSERROR("Unknown key: %s", key);
free(copy); free(copy);
return -1; return -1;
} }
...@@ -1027,7 +1007,7 @@ static int set_config_personality(const char *key, const char *value, ...@@ -1027,7 +1007,7 @@ static int set_config_personality(const char *key, const char *value,
if (personality >= 0) if (personality >= 0)
lxc_conf->personality = personality; lxc_conf->personality = personality;
else else
WARN("unsupported personality '%s'", value); WARN("Unsupported personality \"%s\"", value);
return 0; return 0;
} }
...@@ -1035,13 +1015,11 @@ static int set_config_personality(const char *key, const char *value, ...@@ -1035,13 +1015,11 @@ static int set_config_personality(const char *key, const char *value,
static int set_config_pty_max(const char *key, const char *value, static int set_config_pty_max(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->pts = 0; lxc_conf->pts = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &lxc_conf->pts) < 0) if (lxc_safe_uint(value, &lxc_conf->pts) < 0)
return -1; return -1;
...@@ -1061,13 +1039,11 @@ static int set_config_start(const char *key, const char *value, ...@@ -1061,13 +1039,11 @@ static int set_config_start(const char *key, const char *value,
is_empty = lxc_config_value_empty(value); is_empty = lxc_config_value_empty(value);
if (*(key + 10) == 'a') { /* lxc.start.auto */ if (*(key + 10) == 'a') { /* lxc.start.auto */
/* Set config value to default. */
if (is_empty) { if (is_empty) {
lxc_conf->start_auto = 0; lxc_conf->start_auto = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &lxc_conf->start_auto) < 0) if (lxc_safe_uint(value, &lxc_conf->start_auto) < 0)
return -1; return -1;
...@@ -1076,43 +1052,35 @@ static int set_config_start(const char *key, const char *value, ...@@ -1076,43 +1052,35 @@ static int set_config_start(const char *key, const char *value,
return 0; return 0;
} else if (*(key + 10) == 'd') { /* lxc.start.delay */ } else if (*(key + 10) == 'd') { /* lxc.start.delay */
/* Set config value to default. */
if (is_empty) { if (is_empty) {
lxc_conf->start_delay = 0; lxc_conf->start_delay = 0;
return 0; return 0;
} }
/* Parse new config value. */
return lxc_safe_uint(value, &lxc_conf->start_delay); return lxc_safe_uint(value, &lxc_conf->start_delay);
} else if (*(key + 10) == 'o') { /* lxc.start.order */ } else if (*(key + 10) == 'o') { /* lxc.start.order */
/* Set config value to default. */
if (is_empty) { if (is_empty) {
lxc_conf->start_order = 0; lxc_conf->start_order = 0;
return 0; return 0;
} }
/* Parse new config value. */
return lxc_safe_int(value, &lxc_conf->start_order); return lxc_safe_int(value, &lxc_conf->start_order);
} }
SYSERROR("Unknown key: %s", key);
return -1; return -1;
} }
static int set_config_monitor(const char *key, const char *value, static int set_config_monitor(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->monitor_unshare = 0; lxc_conf->monitor_unshare = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (strcmp(key + 12, "unshare") == 0) if (strcmp(key + 12, "unshare") == 0)
return lxc_safe_uint(value, &lxc_conf->monitor_unshare); return lxc_safe_uint(value, &lxc_conf->monitor_unshare);
SYSERROR("Unknown key: %s", key);
return -1; return -1;
} }
...@@ -1127,13 +1095,11 @@ static int set_config_group(const char *key, const char *value, ...@@ -1127,13 +1095,11 @@ static int set_config_group(const char *key, const char *value,
return lxc_clear_groups(lxc_conf); return lxc_clear_groups(lxc_conf);
groups = strdup(value); groups = strdup(value);
if (!groups) { if (!groups)
SYSERROR("failed to dup '%s'", value);
return -1; return -1;
}
/* In case several groups are specified in a single line /* In case several groups are specified in a single line split these
* split these groups in a single element for the list. * groups in a single element for the list.
*/ */
for (groupptr = groups;; groupptr = NULL) { for (groupptr = groups;; groupptr = NULL) {
token = strtok_r(groupptr, " \t", &sptr); token = strtok_r(groupptr, " \t", &sptr);
...@@ -1143,14 +1109,11 @@ static int set_config_group(const char *key, const char *value, ...@@ -1143,14 +1109,11 @@ static int set_config_group(const char *key, const char *value,
} }
grouplist = malloc(sizeof(*grouplist)); grouplist = malloc(sizeof(*grouplist));
if (!grouplist) { if (!grouplist)
SYSERROR("failed to allocate groups list");
break; break;
}
grouplist->elem = strdup(token); grouplist->elem = strdup(token);
if (!grouplist->elem) { if (!grouplist->elem) {
SYSERROR("failed to dup '%s'", token);
free(grouplist); free(grouplist);
break; break;
} }
...@@ -1191,13 +1154,11 @@ on_error: ...@@ -1191,13 +1154,11 @@ on_error:
static int set_config_tty_max(const char *key, const char *value, static int set_config_tty_max(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->tty = 0; lxc_conf->tty = 0;
return 0; return 0;
} }
/* Parse new config value. */
return lxc_safe_uint(value, &lxc_conf->tty); return lxc_safe_uint(value, &lxc_conf->tty);
} }
...@@ -1219,21 +1180,16 @@ static int set_config_apparmor_allow_incomplete(const char *key, ...@@ -1219,21 +1180,16 @@ static int set_config_apparmor_allow_incomplete(const char *key,
struct lxc_conf *lxc_conf, struct lxc_conf *lxc_conf,
void *data) void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->lsm_aa_allow_incomplete = 0; lxc_conf->lsm_aa_allow_incomplete = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &lxc_conf->lsm_aa_allow_incomplete) < 0) if (lxc_safe_uint(value, &lxc_conf->lsm_aa_allow_incomplete) < 0)
return -1; return -1;
if (lxc_conf->lsm_aa_allow_incomplete > 1) { if (lxc_conf->lsm_aa_allow_incomplete > 1)
ERROR("Wrong value for lxc.apparmor.allow_incomplete. Can only "
"be set to 0 or 1");
return -1; return -1;
}
return 0; return 0;
} }
...@@ -1261,6 +1217,7 @@ static int set_config_log_file(const char *key, const char *value, ...@@ -1261,6 +1217,7 @@ static int set_config_log_file(const char *key, const char *value,
ret = set_config_path_item(&c->logfile, value); ret = set_config_path_item(&c->logfile, value);
if (ret == 0) if (ret == 0)
ret = lxc_log_set_file(&c->logfd, c->logfile); ret = lxc_log_set_file(&c->logfd, c->logfile);
return ret; return ret;
} }
...@@ -1269,13 +1226,11 @@ static int set_config_log_level(const char *key, const char *value, ...@@ -1269,13 +1226,11 @@ static int set_config_log_level(const char *key, const char *value,
{ {
int newlevel; int newlevel;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->loglevel = LXC_LOG_LEVEL_NOTSET; lxc_conf->loglevel = LXC_LOG_LEVEL_NOTSET;
return 0; return 0;
} }
/* Parse new config value. */
if (value[0] >= '0' && value[0] <= '9') { if (value[0] >= '0' && value[0] <= '9') {
if (lxc_safe_int(value, &newlevel) < 0) if (lxc_safe_int(value, &newlevel) < 0)
return -1; return -1;
...@@ -1293,20 +1248,16 @@ static int set_config_log_level(const char *key, const char *value, ...@@ -1293,20 +1248,16 @@ static int set_config_log_level(const char *key, const char *value,
static int set_config_autodev(const char *key, const char *value, static int set_config_autodev(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->autodev = 0; lxc_conf->autodev = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &lxc_conf->autodev) < 0) if (lxc_safe_uint(value, &lxc_conf->autodev) < 0)
return -1; return -1;
if (lxc_conf->autodev > 1) { if (lxc_conf->autodev > 1)
ERROR("Wrong value for lxc.autodev. Can only be set to 0 or 1");
return -1; return -1;
}
return 0; return 0;
} }
...@@ -1365,17 +1316,15 @@ static int set_config_signal_halt(const char *key, const char *value, ...@@ -1365,17 +1316,15 @@ static int set_config_signal_halt(const char *key, const char *value,
{ {
int sig_n; int sig_n;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->haltsignal = 0; lxc_conf->haltsignal = 0;
return 0; return 0;
} }
/* Parse new config value. */
sig_n = sig_parse(value); sig_n = sig_parse(value);
if (sig_n < 0) if (sig_n < 0)
return -1; return -1;
lxc_conf->haltsignal = sig_n; lxc_conf->haltsignal = sig_n;
return 0; return 0;
...@@ -1386,16 +1335,15 @@ static int set_config_signal_reboot(const char *key, const char *value, ...@@ -1386,16 +1335,15 @@ static int set_config_signal_reboot(const char *key, const char *value,
{ {
int sig_n; int sig_n;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->rebootsignal = 0; lxc_conf->rebootsignal = 0;
return 0; return 0;
} }
/* Parse new config value. */
sig_n = sig_parse(value); sig_n = sig_parse(value);
if (sig_n < 0) if (sig_n < 0)
return -1; return -1;
lxc_conf->rebootsignal = sig_n; lxc_conf->rebootsignal = sig_n;
return 0; return 0;
...@@ -1406,16 +1354,15 @@ static int set_config_signal_stop(const char *key, const char *value, ...@@ -1406,16 +1354,15 @@ static int set_config_signal_stop(const char *key, const char *value,
{ {
int sig_n; int sig_n;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->stopsignal = 0; lxc_conf->stopsignal = 0;
return 0; return 0;
} }
/* Parse new config value. */
sig_n = sig_parse(value); sig_n = sig_parse(value);
if (sig_n < 0) if (sig_n < 0)
return -1; return -1;
lxc_conf->stopsignal = sig_n; lxc_conf->stopsignal = sig_n;
return 0; return 0;
...@@ -1467,12 +1414,9 @@ static int set_config_cgroup(const char *key, const char *value, ...@@ -1467,12 +1414,9 @@ static int set_config_cgroup(const char *key, const char *value,
out: out:
free(cglist); free(cglist);
if (cgelem) { if (cgelem) {
free(cgelem->subsystem); free(cgelem->subsystem);
free(cgelem->value); free(cgelem->value);
free(cgelem); free(cgelem);
} }
...@@ -1595,7 +1539,7 @@ static int set_config_idmaps(const char *key, const char *value, ...@@ -1595,7 +1539,7 @@ static int set_config_idmaps(const char *key, const char *value,
if (ret < 0) if (ret < 0)
goto on_error; goto on_error;
INFO("read uid map: type %c nsid %lu hostid %lu range %lu", type, nsid, hostid, range); INFO("Read uid map: type %c nsid %lu hostid %lu range %lu", type, nsid, hostid, range);
if (type == 'u') if (type == 'u')
idmap->idtype = ID_TYPE_UID; idmap->idtype = ID_TYPE_UID;
else if (type == 'g') else if (type == 'g')
...@@ -1656,9 +1600,9 @@ static int set_config_mount_auto(const char *key, const char *value, ...@@ -1656,9 +1600,9 @@ static int set_config_mount_auto(const char *key, const char *value,
{ "cgroup-full:mixed", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_MIXED }, { "cgroup-full:mixed", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_MIXED },
{ "cgroup-full:ro", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RO }, { "cgroup-full:ro", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RO },
{ "cgroup-full:rw", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RW }, { "cgroup-full:rw", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RW },
/* NB: For adding anything that is just a single on/off, but has /* For adding anything that is just a single on/off, but has no
* no options: keep mask and flag identical and just define the * options: keep mask and flag identical and just define the enum
* enum value as an unused bit so far * value as an unused bit so far
*/ */
{ NULL, 0, 0 } { NULL, 0, 0 }
}; };
...@@ -1669,10 +1613,8 @@ static int set_config_mount_auto(const char *key, const char *value, ...@@ -1669,10 +1613,8 @@ static int set_config_mount_auto(const char *key, const char *value,
} }
autos = strdup(value); autos = strdup(value);
if (!autos) { if (!autos)
SYSERROR("failed to dup '%s'", value);
return -1; return -1;
}
for (autoptr = autos;; autoptr = NULL) { for (autoptr = autos;; autoptr = NULL) {
token = strtok_r(autoptr, " \t", &sptr); token = strtok_r(autoptr, " \t", &sptr);
...@@ -1687,7 +1629,7 @@ static int set_config_mount_auto(const char *key, const char *value, ...@@ -1687,7 +1629,7 @@ static int set_config_mount_auto(const char *key, const char *value,
} }
if (!allowed_auto_mounts[i].token) { if (!allowed_auto_mounts[i].token) {
ERROR("Invalid filesystem to automount: %s", token); ERROR("Invalid filesystem to automount \"%s\"", token);
break; break;
} }
...@@ -1735,10 +1677,8 @@ static int set_config_cap_keep(const char *key, const char *value, ...@@ -1735,10 +1677,8 @@ static int set_config_cap_keep(const char *key, const char *value,
return lxc_clear_config_keepcaps(lxc_conf); return lxc_clear_config_keepcaps(lxc_conf);
keepcaps = strdup(value); keepcaps = strdup(value);
if (!keepcaps) { if (!keepcaps)
SYSERROR("failed to dup '%s'", value);
return -1; return -1;
}
/* In case several capability keep is specified in a single line /* In case several capability keep is specified in a single line
* split these caps in a single element for the list. * split these caps in a single element for the list.
...@@ -1754,14 +1694,11 @@ static int set_config_cap_keep(const char *key, const char *value, ...@@ -1754,14 +1694,11 @@ static int set_config_cap_keep(const char *key, const char *value,
lxc_clear_config_keepcaps(lxc_conf); lxc_clear_config_keepcaps(lxc_conf);
keeplist = malloc(sizeof(*keeplist)); keeplist = malloc(sizeof(*keeplist));
if (!keeplist) { if (!keeplist)
SYSERROR("failed to allocate keepcap list");
break; break;
}
keeplist->elem = strdup(token); keeplist->elem = strdup(token);
if (!keeplist->elem) { if (!keeplist->elem) {
SYSERROR("failed to dup '%s'", token);
free(keeplist); free(keeplist);
break; break;
} }
...@@ -1785,10 +1722,8 @@ static int set_config_cap_drop(const char *key, const char *value, ...@@ -1785,10 +1722,8 @@ static int set_config_cap_drop(const char *key, const char *value,
return lxc_clear_config_caps(lxc_conf); return lxc_clear_config_caps(lxc_conf);
dropcaps = strdup(value); dropcaps = strdup(value);
if (!dropcaps) { if (!dropcaps)
SYSERROR("failed to dup '%s'", value);
return -1; return -1;
}
/* In case several capability drop is specified in a single line /* In case several capability drop is specified in a single line
* split these caps in a single element for the list. * split these caps in a single element for the list.
...@@ -1801,14 +1736,11 @@ static int set_config_cap_drop(const char *key, const char *value, ...@@ -1801,14 +1736,11 @@ static int set_config_cap_drop(const char *key, const char *value,
} }
droplist = malloc(sizeof(*droplist)); droplist = malloc(sizeof(*droplist));
if (!droplist) { if (!droplist)
SYSERROR("failed to allocate drop list");
break; break;
}
droplist->elem = strdup(token); droplist->elem = strdup(token);
if (!droplist->elem) { if (!droplist->elem) {
SYSERROR("failed to dup '%s'", token);
free(droplist); free(droplist);
break; break;
} }
...@@ -1856,6 +1788,7 @@ int append_unexp_config_line(const char *line, struct lxc_conf *conf) ...@@ -1856,6 +1788,7 @@ int append_unexp_config_line(const char *line, struct lxc_conf *conf)
strcat(conf->unexpanded_config, "\n"); strcat(conf->unexpanded_config, "\n");
conf->unexpanded_len++; conf->unexpanded_len++;
} }
return 0; return 0;
} }
...@@ -1868,10 +1801,8 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf) ...@@ -1868,10 +1801,8 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
int ret = -1; int ret = -1;
dir = opendir(dirp); dir = opendir(dirp);
if (!dir) { if (!dir)
SYSERROR("failed to open '%s'", dirp);
return -1; return -1;
}
while ((direntp = readdir(dir))) { while ((direntp = readdir(dir))) {
const char *fnam; const char *fnam;
...@@ -1888,9 +1819,9 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf) ...@@ -1888,9 +1819,9 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
len = strlen(fnam); len = strlen(fnam);
if (len < 6 || strncmp(fnam + len - 5, ".conf", 5) != 0) if (len < 6 || strncmp(fnam + len - 5, ".conf", 5) != 0)
continue; continue;
len = snprintf(path, MAXPATHLEN, "%s/%s", dirp, fnam); len = snprintf(path, MAXPATHLEN, "%s/%s", dirp, fnam);
if (len < 0 || len >= MAXPATHLEN) { if (len < 0 || len >= MAXPATHLEN) {
ERROR("lxc.include filename too long under '%s'", dirp);
ret = -1; ret = -1;
goto out; goto out;
} }
...@@ -1902,8 +1833,7 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf) ...@@ -1902,8 +1833,7 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
ret = 0; ret = 0;
out: out:
if (closedir(dir)) closedir(dir);
WARN("lxc.include dir: failed to close directory");
return ret; return ret;
} }
...@@ -1911,13 +1841,11 @@ out: ...@@ -1911,13 +1841,11 @@ out:
static int set_config_includefiles(const char *key, const char *value, static int set_config_includefiles(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
clr_config_includefiles(key, lxc_conf, NULL); clr_config_includefiles(key, lxc_conf, NULL);
return 0; return 0;
} }
/* Parse new config value. */
if (is_dir(value)) if (is_dir(value))
return do_includedir(value, lxc_conf); return do_includedir(value, lxc_conf);
...@@ -1959,13 +1887,10 @@ static int set_config_uts_name(const char *key, const char *value, ...@@ -1959,13 +1887,10 @@ static int set_config_uts_name(const char *key, const char *value,
} }
utsname = malloc(sizeof(*utsname)); utsname = malloc(sizeof(*utsname));
if (!utsname) { if (!utsname)
SYSERROR("failed to allocate memory");
return -1; return -1;
}
if (strlen(value) >= sizeof(utsname->nodename)) { if (strlen(value) >= sizeof(utsname->nodename)) {
ERROR("node name '%s' is too long", value);
free(utsname); free(utsname);
return -1; return -1;
} }
...@@ -1992,15 +1917,13 @@ static int parse_line(char *buffer, void *data) ...@@ -1992,15 +1917,13 @@ static int parse_line(char *buffer, void *data)
if (lxc_is_line_empty(buffer)) if (lxc_is_line_empty(buffer))
return 0; return 0;
/* we have to dup the buffer otherwise, at the re-exec for /* We have to dup the buffer otherwise, at the re-exec for reboot we
* reboot we modified the original string on the stack by * modified the original string on the stack by replacing '=' by '\0'
* replacing '=' by '\0' below * below.
*/ */
linep = line = strdup(buffer); linep = line = strdup(buffer);
if (!line) { if (!line)
SYSERROR("failed to allocate memory for '%s'", buffer);
return -1; return -1;
}
if (!plc->from_include) if (!plc->from_include)
if ((ret = append_unexp_config_line(line, plc->conf))) if ((ret = append_unexp_config_line(line, plc->conf)))
...@@ -2034,7 +1957,9 @@ static int parse_line(char *buffer, void *data) ...@@ -2034,7 +1957,9 @@ static int parse_line(char *buffer, void *data)
value[lxc_char_right_gc(value, strlen(value))] = '\0'; value[lxc_char_right_gc(value, strlen(value))] = '\0';
if (*value == '\'' || *value == '\"') { if (*value == '\'' || *value == '\"') {
size_t len = strlen(value); size_t len;
len = strlen(value);
if (len > 1 && value[len - 1] == *value) { if (len > 1 && value[len - 1] == *value) {
value[len - 1] = '\0'; value[len - 1] = '\0';
value++; value++;
...@@ -2043,7 +1968,7 @@ static int parse_line(char *buffer, void *data) ...@@ -2043,7 +1968,7 @@ static int parse_line(char *buffer, void *data)
config = lxc_get_config(key); config = lxc_get_config(key);
if (!config) { if (!config) {
ERROR("unknown key %s", key); ERROR("Unknown configuration key \"%s\"", key);
goto out; goto out;
} }
...@@ -2054,8 +1979,9 @@ static int parse_line(char *buffer, void *data) ...@@ -2054,8 +1979,9 @@ static int parse_line(char *buffer, void *data)
* legacy configuration item in the configuration file and then * legacy configuration item in the configuration file and then
* an update is required. * an update is required.
*/ */
fprintf(stderr, "The configuration file contains legacy configuration keys.\n" fprintf(stderr, "The configuration file contains legacy "
"Please update your configuration file!\n"); "configuration keys.\nPlease update your "
"configuration file!\n");
} }
/* [END]: REMOVE IN LXC 3.0 */ /* [END]: REMOVE IN LXC 3.0 */
...@@ -2078,16 +2004,17 @@ static int lxc_config_readline(char *buffer, struct lxc_conf *conf) ...@@ -2078,16 +2004,17 @@ static int lxc_config_readline(char *buffer, struct lxc_conf *conf)
int lxc_config_read(const char *file, struct lxc_conf *conf, bool from_include) int lxc_config_read(const char *file, struct lxc_conf *conf, bool from_include)
{ {
int ret;
struct parse_line_conf c; struct parse_line_conf c;
c.conf = conf; c.conf = conf;
c.from_include = from_include; c.from_include = from_include;
if (access(file, R_OK) == -1) { ret = access(file, R_OK);
if (ret < 0)
return -1; return -1;
}
/* Catch only the top level config file name in the structure */ /* Catch only the top level config file name in the structure. */
if (!conf->rcfile) if (!conf->rcfile)
conf->rcfile = strdup(file); conf->rcfile = strdup(file);
...@@ -2189,21 +2116,20 @@ int lxc_fill_elevated_privileges(char *flaglist, int *flags) ...@@ -2189,21 +2116,20 @@ int lxc_fill_elevated_privileges(char *flaglist, int *flags)
if (!flaglist) { if (!flaglist) {
/* For the sake of backward compatibility, drop all privileges /* For the sake of backward compatibility, drop all privileges
* if none is specified. * if none is specified.
*/ */
for (i = 0; all_privs[i].token; i++) { for (i = 0; all_privs[i].token; i++)
*flags |= all_privs[i].flag; *flags |= all_privs[i].flag;
}
return 0; return 0;
} }
token = strtok_r(flaglist, "|", &saveptr); token = strtok_r(flaglist, "|", &saveptr);
while (token) { while (token) {
aflag = -1; aflag = -1;
for (i = 0; all_privs[i].token; i++) { for (i = 0; all_privs[i].token; i++)
if (!strcmp(all_privs[i].token, token)) if (!strcmp(all_privs[i].token, token))
aflag = all_privs[i].flag; aflag = all_privs[i].flag;
}
if (aflag < 0) if (aflag < 0)
return -1; return -1;
...@@ -2226,7 +2152,7 @@ void write_config(FILE *fout, struct lxc_conf *c) ...@@ -2226,7 +2152,7 @@ void write_config(FILE *fout, struct lxc_conf *c)
ret = fwrite(c->unexpanded_config, 1, len, fout); ret = fwrite(c->unexpanded_config, 1, len, fout);
if (ret != len) if (ret != len)
SYSERROR("Error writing configuration file"); SYSERROR("Failed to write configuration file");
} }
bool do_append_unexp_config_line(struct lxc_conf *conf, const char *key, bool do_append_unexp_config_line(struct lxc_conf *conf, const char *key,
...@@ -2303,19 +2229,15 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath, ...@@ -2303,19 +2229,15 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath,
olddir = alloca(olddirlen + 1); olddir = alloca(olddirlen + 1);
ret = snprintf(olddir, olddirlen + 1, "%s=%s/%s", ovldir, oldpath, ret = snprintf(olddir, olddirlen + 1, "%s=%s/%s", ovldir, oldpath,
oldname); oldname);
if (ret < 0 || ret >= olddirlen + 1) { if (ret < 0 || ret >= olddirlen + 1)
ERROR("failed to create string");
return false; return false;
}
newdirlen = strlen(ovldir) + strlen(newpath) + strlen(newname) + 2; newdirlen = strlen(ovldir) + strlen(newpath) + strlen(newname) + 2;
newdir = alloca(newdirlen + 1); newdir = alloca(newdirlen + 1);
ret = snprintf(newdir, newdirlen + 1, "%s=%s/%s", ovldir, newpath, ret = snprintf(newdir, newdirlen + 1, "%s=%s/%s", ovldir, newpath,
newname); newname);
if (ret < 0 || ret >= newdirlen + 1) { if (ret < 0 || ret >= newdirlen + 1)
ERROR("failed to create string");
return false; return false;
}
if (!conf->unexpanded_config) if (!conf->unexpanded_config)
return true; return true;
...@@ -2375,15 +2297,14 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath, ...@@ -2375,15 +2297,14 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath,
size_t poffset = q - conf->unexpanded_config; size_t poffset = q - conf->unexpanded_config;
new = realloc(conf->unexpanded_config, newlen + 1); new = realloc(conf->unexpanded_config, newlen + 1);
if (!new) { if (!new)
ERROR("Out of memory");
return false; return false;
}
conf->unexpanded_len = newlen; conf->unexpanded_len = newlen;
conf->unexpanded_alloced = newlen + 1; conf->unexpanded_alloced = newlen + 1;
new[newlen - 1] = '\0'; new[newlen - 1] = '\0';
lend = new + (lend - conf->unexpanded_config); lend = new + (lend - conf->unexpanded_config);
/* move over the remainder to make room for the newdir /* Move over the remainder to make room for the newdir.
*/ */
memmove(new + poffset + newdirlen, memmove(new + poffset + newdirlen,
new + poffset + olddirlen, new + poffset + olddirlen,
...@@ -2412,20 +2333,18 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath, ...@@ -2412,20 +2333,18 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath,
olddirlen = strlen(oldpath) + strlen(oldname) + 1; olddirlen = strlen(oldpath) + strlen(oldname) + 1;
olddir = alloca(olddirlen + 1); olddir = alloca(olddirlen + 1);
ret = snprintf(olddir, olddirlen + 1, "%s/%s", oldpath, oldname); ret = snprintf(olddir, olddirlen + 1, "%s/%s", oldpath, oldname);
if (ret < 0 || ret >= olddirlen + 1) { if (ret < 0 || ret >= olddirlen + 1)
ERROR("failed to create string");
return false; return false;
}
newdirlen = strlen(newpath) + strlen(newname) + 1; newdirlen = strlen(newpath) + strlen(newname) + 1;
newdir = alloca(newdirlen + 1); newdir = alloca(newdirlen + 1);
ret = snprintf(newdir, newdirlen + 1, "%s/%s", newpath, newname); ret = snprintf(newdir, newdirlen + 1, "%s/%s", newpath, newname);
if (ret < 0 || ret >= newdirlen + 1) { if (ret < 0 || ret >= newdirlen + 1)
ERROR("failed to create string");
return false; return false;
}
if (!conf->unexpanded_config) if (!conf->unexpanded_config)
return true; return true;
while (*lstart) { while (*lstart) {
lend = strchr(lstart, '\n'); lend = strchr(lstart, '\n');
if (!lend) if (!lend)
...@@ -2468,15 +2387,14 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath, ...@@ -2468,15 +2387,14 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath,
size_t poffset = p - conf->unexpanded_config; size_t poffset = p - conf->unexpanded_config;
new = realloc(conf->unexpanded_config, newlen + 1); new = realloc(conf->unexpanded_config, newlen + 1);
if (!new) { if (!new)
ERROR("failed to allocate memory");
return false; return false;
}
conf->unexpanded_len = newlen; conf->unexpanded_len = newlen;
conf->unexpanded_alloced = newlen + 1; conf->unexpanded_alloced = newlen + 1;
new[newlen - 1] = '\0'; new[newlen - 1] = '\0';
lend = new + (lend - conf->unexpanded_config); lend = new + (lend - conf->unexpanded_config);
/* move over the remainder to make room for the newdir /* Move over the remainder to make room for the newdir.
*/ */
memmove(new + poffset + newdirlen, memmove(new + poffset + newdirlen,
new + poffset + olddirlen, new + poffset + olddirlen,
...@@ -2500,9 +2418,8 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath, ...@@ -2500,9 +2418,8 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath,
} \ } \
} }
/* /* This is called only from clone. We wish to update all hwaddrs in the
* This is called only from clone. We wish to update all hwaddrs in the * unexpanded config file. We can't/don't want to update any which come from
* unexpanded config file. We can't/don't want to update any which come from
* lxc.includes (there shouldn't be any). * lxc.includes (there shouldn't be any).
* We can't just walk the c->lxc-conf->network list because that includes netifs * We can't just walk the c->lxc-conf->network list because that includes netifs
* from the include files. So we update the ones which we find in the unexp * from the include files. So we update the ones which we find in the unexp
...@@ -2560,9 +2477,9 @@ bool network_new_hwaddrs(struct lxc_conf *conf) ...@@ -2560,9 +2477,9 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
return false; return false;
memcpy(p, newhwaddr, 17); memcpy(p, newhwaddr, 17);
lxc_list_for_each(it, &conf->network) lxc_list_for_each(it, &conf->network) {
{
struct lxc_netdev *n = it->elem; struct lxc_netdev *n = it->elem;
if (n->hwaddr && memcmp(oldhwaddr, n->hwaddr, 17) == 0) if (n->hwaddr && memcmp(oldhwaddr, n->hwaddr, 17) == 0)
memcpy(n->hwaddr, newhwaddr, 17); memcpy(n->hwaddr, newhwaddr, 17);
} }
...@@ -2576,21 +2493,16 @@ bool network_new_hwaddrs(struct lxc_conf *conf) ...@@ -2576,21 +2493,16 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
static int set_config_ephemeral(const char *key, const char *value, static int set_config_ephemeral(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->ephemeral = 0; lxc_conf->ephemeral = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &lxc_conf->ephemeral) < 0) if (lxc_safe_uint(value, &lxc_conf->ephemeral) < 0)
return -1; return -1;
if (lxc_conf->ephemeral > 1) { if (lxc_conf->ephemeral > 1)
ERROR(
"Wrong value for lxc.ephemeral. Can only be set to 0 or 1");
return -1; return -1;
}
return 0; return 0;
} }
...@@ -2600,22 +2512,17 @@ static int set_config_log_syslog(const char *key, const char *value, ...@@ -2600,22 +2512,17 @@ static int set_config_log_syslog(const char *key, const char *value,
{ {
int facility; int facility;
/* Clear any previously set value. */
if (lxc_conf->syslog) { if (lxc_conf->syslog) {
free(lxc_conf->syslog); free(lxc_conf->syslog);
lxc_conf->syslog = NULL; lxc_conf->syslog = NULL;
} }
/* Check if value is empty. */
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return 0; return 0;
/* Parse value. */
facility = lxc_syslog_priority_to_int(value); facility = lxc_syslog_priority_to_int(value);
if (facility == -EINVAL) { if (facility == -EINVAL)
ERROR("Wrong value for lxc.log.syslog.");
return -1; return -1;
}
lxc_log_syslog(facility); lxc_log_syslog(facility);
return set_config_string_item(&lxc_conf->syslog, value); return set_config_string_item(&lxc_conf->syslog, value);
...@@ -2626,21 +2533,16 @@ static int set_config_no_new_privs(const char *key, const char *value, ...@@ -2626,21 +2533,16 @@ static int set_config_no_new_privs(const char *key, const char *value,
{ {
unsigned int v; unsigned int v;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->no_new_privs = false; lxc_conf->no_new_privs = false;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &v) < 0) if (lxc_safe_uint(value, &v) < 0)
return -1; return -1;
if (v > 1) { if (v > 1)
ERROR("Wrong value for lxc.no_new_privs. Can only be set to 0 "
"or 1");
return -1; return -1;
}
lxc_conf->no_new_privs = v ? true : false; lxc_conf->no_new_privs = v ? true : false;
...@@ -2714,14 +2616,13 @@ static int get_config_selinux_context(const char *key, char *retv, int inlen, ...@@ -2714,14 +2616,13 @@ static int get_config_selinux_context(const char *key, char *retv, int inlen,
return lxc_get_conf_str(retv, inlen, c->lsm_se_context); return lxc_get_conf_str(retv, inlen, c->lsm_se_context);
} }
/* /* If you ask for a specific cgroup value, i.e. lxc.cgroup.devices.list, then
* If you ask for a specific cgroup value, i.e. lxc.cgroup.devices.list, * just the value(s) will be printed. Since there still could be more than one,
* then just the value(s) will be printed. Since there still could be * it is newline-separated.
* more than one, it is newline-separated. * (Maybe that's ambigous, since some values, i.e. devices.list, will already
* (Maybe that's ambigous, since some values, i.e. devices.list, will * have newlines?)
* already have newlines?) * If you ask for 'lxc.cgroup", then all cgroup entries will be printed, in
* If you ask for 'lxc.cgroup", then all cgroup entries will be printed, * 'lxc.cgroup.subsystem.key = value' format.
* in 'lxc.cgroup.subsystem.key = value' format.
*/ */
static int get_config_cgroup(const char *key, char *retv, int inlen, static int get_config_cgroup(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data) struct lxc_conf *c, void *data)
...@@ -2745,8 +2646,10 @@ static int get_config_cgroup(const char *key, char *retv, int inlen, ...@@ -2745,8 +2646,10 @@ static int get_config_cgroup(const char *key, char *retv, int inlen,
lxc_list_for_each(it, &c->cgroup) { lxc_list_for_each(it, &c->cgroup) {
struct lxc_cgroup *cg = it->elem; struct lxc_cgroup *cg = it->elem;
if (get_all) { if (get_all) {
strprint(retv, inlen, "lxc.cgroup.%s = %s\n", cg->subsystem, cg->value); strprint(retv, inlen, "lxc.cgroup.%s = %s\n",
cg->subsystem, cg->value);
} else if (!strcmp(cg->subsystem, key)) { } else if (!strcmp(cg->subsystem, key)) {
strprint(retv, inlen, "%s\n", cg->value); strprint(retv, inlen, "%s\n", cg->value);
} }
...@@ -2919,8 +2822,7 @@ static int get_config_mount(const char *key, char *retv, int inlen, ...@@ -2919,8 +2822,7 @@ static int get_config_mount(const char *key, char *retv, int inlen,
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
lxc_list_for_each(it, &c->mount_list) lxc_list_for_each(it, &c->mount_list) {
{
strprint(retv, inlen, "%s\n", (char *)it->elem); strprint(retv, inlen, "%s\n", (char *)it->elem);
} }
...@@ -2967,7 +2869,6 @@ static int get_config_hooks(const char *key, char *retv, int inlen, ...@@ -2967,7 +2869,6 @@ static int get_config_hooks(const char *key, char *retv, int inlen,
struct lxc_list *it; struct lxc_list *it;
int i; int i;
/* "lxc.hook.mount" */
subkey = strchr(key, '.'); subkey = strchr(key, '.');
if (subkey) if (subkey)
subkey = strchr(subkey + 1, '.'); subkey = strchr(subkey + 1, '.');
...@@ -3030,6 +2931,7 @@ static int get_config_cap_drop(const char *key, char *retv, int inlen, ...@@ -3030,6 +2931,7 @@ static int get_config_cap_drop(const char *key, char *retv, int inlen,
lxc_list_for_each(it, &c->caps) { lxc_list_for_each(it, &c->caps) {
strprint(retv, inlen, "%s\n", (char *)it->elem); strprint(retv, inlen, "%s\n", (char *)it->elem);
} }
return fulllen; return fulllen;
} }
...@@ -3047,6 +2949,7 @@ static int get_config_cap_keep(const char *key, char *retv, int inlen, ...@@ -3047,6 +2949,7 @@ static int get_config_cap_keep(const char *key, char *retv, int inlen,
lxc_list_for_each(it, &c->keepcaps) { lxc_list_for_each(it, &c->keepcaps) {
strprint(retv, inlen, "%s\n", (char *)it->elem); strprint(retv, inlen, "%s\n", (char *)it->elem);
} }
return fulllen; return fulllen;
} }
...@@ -3075,19 +2978,19 @@ static int get_config_autodev(const char *key, char *retv, int inlen, ...@@ -3075,19 +2978,19 @@ static int get_config_autodev(const char *key, char *retv, int inlen,
} }
static int get_config_signal_halt(const char *key, char *retv, int inlen, static int get_config_signal_halt(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data) struct lxc_conf *c, void *data)
{ {
return lxc_get_conf_int(c, retv, inlen, c->haltsignal); return lxc_get_conf_int(c, retv, inlen, c->haltsignal);
} }
static int get_config_signal_reboot(const char *key, char *retv, int inlen, static int get_config_signal_reboot(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data) struct lxc_conf *c, void *data)
{ {
return lxc_get_conf_int(c, retv, inlen, c->rebootsignal); return lxc_get_conf_int(c, retv, inlen, c->rebootsignal);
} }
static int get_config_signal_stop(const char *key, char *retv, int inlen, static int get_config_signal_stop(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data) struct lxc_conf *c, void *data)
{ {
return lxc_get_conf_int(c, retv, inlen, c->stopsignal); return lxc_get_conf_int(c, retv, inlen, c->stopsignal);
} }
...@@ -3106,7 +3009,7 @@ static int get_config_start(const char *key, char *retv, int inlen, ...@@ -3106,7 +3009,7 @@ static int get_config_start(const char *key, char *retv, int inlen,
} }
static int get_config_log_syslog(const char *key, char *retv, int inlen, static int get_config_log_syslog(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data) struct lxc_conf *c, void *data)
{ {
return lxc_get_conf_str(retv, inlen, c->syslog); return lxc_get_conf_str(retv, inlen, c->syslog);
} }
...@@ -3131,6 +3034,7 @@ static int get_config_group(const char *key, char *retv, int inlen, ...@@ -3131,6 +3034,7 @@ static int get_config_group(const char *key, char *retv, int inlen,
lxc_list_for_each(it, &c->groups) { lxc_list_for_each(it, &c->groups) {
strprint(retv, inlen, "%s\n", (char *)it->elem); strprint(retv, inlen, "%s\n", (char *)it->elem);
} }
return fulllen; return fulllen;
} }
...@@ -3148,6 +3052,7 @@ static int get_config_environment(const char *key, char *retv, int inlen, ...@@ -3148,6 +3052,7 @@ static int get_config_environment(const char *key, char *retv, int inlen,
lxc_list_for_each(it, &c->environment) { lxc_list_for_each(it, &c->environment) {
strprint(retv, inlen, "%s\n", (char *)it->elem); strprint(retv, inlen, "%s\n", (char *)it->elem);
} }
return fulllen; return fulllen;
} }
...@@ -3181,8 +3086,7 @@ static int get_config_no_new_privs(const char *key, char *retv, int inlen, ...@@ -3181,8 +3086,7 @@ static int get_config_no_new_privs(const char *key, char *retv, int inlen,
return lxc_get_conf_int(c, retv, inlen, c->no_new_privs); return lxc_get_conf_int(c, retv, inlen, c->no_new_privs);
} }
/* /* If you ask for a specific value, i.e. lxc.prlimit.nofile, then just the value
* If you ask for a specific value, i.e. lxc.prlimit.nofile, then just the value
* will be printed. If you ask for 'lxc.prlimit', then all limit entries will be * will be printed. If you ask for 'lxc.prlimit', then all limit entries will be
* printed, in 'lxc.prlimit.resource = value' format. * printed, in 'lxc.prlimit.resource = value' format.
*/ */
...@@ -3220,19 +3124,18 @@ static int get_config_prlimit(const char *key, char *retv, int inlen, ...@@ -3220,19 +3124,18 @@ static int get_config_prlimit(const char *key, char *retv, int inlen,
(uint64_t)lim->limit.rlim_cur); (uint64_t)lim->limit.rlim_cur);
} }
if (lim->limit.rlim_cur != lim->limit.rlim_max) { if (lim->limit.rlim_cur != lim->limit.rlim_max) {
if (lim->limit.rlim_max == RLIM_INFINITY) { if (lim->limit.rlim_max == RLIM_INFINITY)
memcpy(buf + partlen, ":unlimited", memcpy(buf + partlen, ":unlimited",
sizeof(":unlimited")); sizeof(":unlimited"));
} else { else
sprintf(buf + partlen, ":%" PRIu64, sprintf(buf + partlen, ":%" PRIu64,
(uint64_t)lim->limit.rlim_max); (uint64_t)lim->limit.rlim_max);
}
} }
if (get_all) { if (get_all) {
strprint(retv, inlen, "lxc.prlimit.%s = %s\n", strprint(retv, inlen, "lxc.prlimit.%s = %s\n",
lim->resource, buf); lim->resource, buf);
} else if (strcmp(lim->resource, key) == 0) { } else if (!strcmp(lim->resource, key)) {
strprint(retv, inlen, "%s", buf); strprint(retv, inlen, "%s", buf);
} }
} }
...@@ -3604,8 +3507,8 @@ static struct lxc_config_t *get_network_config_ops(const char *key, ...@@ -3604,8 +3507,8 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
* (Checking for INT_MAX here is intentional.) * (Checking for INT_MAX here is intentional.)
*/ */
if (tmpidx == INT_MAX) { if (tmpidx == INT_MAX) {
SYSERROR("number of configured networks would overflow the " SYSERROR("Number of configured networks would overflow the "
"counter... what are you doing?"); "counter");
goto on_error; goto on_error;
} }
*idx = tmpidx; *idx = tmpidx;
...@@ -3624,7 +3527,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key, ...@@ -3624,7 +3527,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
config = lxc_get_config(copy); config = lxc_get_config(copy);
if (!config) { if (!config) {
ERROR("unknown network configuration key %s", key); ERROR("Unknown network configuration key \"%s\"", key);
goto on_error; goto on_error;
} }
} }
...@@ -3639,10 +3542,9 @@ on_error: ...@@ -3639,10 +3542,9 @@ on_error:
return NULL; return NULL;
} }
/* /* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.' was
* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.' * found. So we make sure next comes an integer, find the right callback (by
* was found. So we make sure next comes an integer, find the right callback * rewriting the key), and call it.
* (by rewriting the key), and call it.
*/ */
static int set_config_net_nic(const char *key, const char *value, static int set_config_net_nic(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
...@@ -3676,11 +3578,6 @@ static int set_config_net_nic(const char *key, const char *value, ...@@ -3676,11 +3578,6 @@ static int set_config_net_nic(const char *key, const char *value,
return ret; return ret;
} }
/*
* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.'
* was found. So we make sure next comes an integer, find the right callback
* (by rewriting the key), and call it.
*/
static int clr_config_net_nic(const char *key, struct lxc_conf *lxc_conf, static int clr_config_net_nic(const char *key, struct lxc_conf *lxc_conf,
void *data) void *data)
{ {
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
#ifndef __LXC_CONFILE_H #ifndef __LXC_CONFILE_H
#define __LXC_CONFILE_H #define __LXC_CONFILE_H
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <lxc/attach_options.h> #include <lxc/attach_options.h>
#include <stdbool.h>
struct lxc_conf; struct lxc_conf;
struct lxc_list; struct lxc_list;
......
...@@ -128,30 +128,59 @@ if ([ $KVER_MAJOR -lt 4 ]) || ([ $KVER_MAJOR -eq 4 ] && [ $KVER_MINOR -lt 7 ]); ...@@ -128,30 +128,59 @@ if ([ $KVER_MAJOR -lt 4 ]) || ([ $KVER_MAJOR -eq 4 ] && [ $KVER_MINOR -lt 7 ]);
echo -n "Multiple /dev/pts instances: " && is_enabled DEVPTS_MULTIPLE_INSTANCES echo -n "Multiple /dev/pts instances: " && is_enabled DEVPTS_MULTIPLE_INSTANCES
fi fi
echo echo
echo "--- Control groups ---" echo "--- Control groups ---"
echo -n "Cgroups: " && is_enabled CONFIG_CGROUPS
echo
print_cgroups() { print_cgroups() {
# print all mountpoints for cgroup filesystems # print all mountpoints for cgroup filesystems
awk '$1 !~ /#/ && $3 == mp { print $2; } ; END { exit(0); } ' "mp=$1" "$2" ; awk '$1 !~ /#/ && $3 == mp { print $2; } ; END { exit(0); } ' "mp=$1" "$2" ;
} }
CGROUP_MNT_PATH=`print_cgroups cgroup /proc/self/mounts | head -n 1` CGROUP_V1_MNTS=`print_cgroups cgroup /proc/self/mounts`
echo
echo "Cgroup v1 mount points: "
echo "$CGROUP_V1_MNTS"
echo
echo -n "Cgroup: " && is_enabled CONFIG_CGROUPS CGROUP_V2_MNTS=`print_cgroups cgroup2 /proc/self/mounts`
echo "Cgroup v2 mount points: "
echo "$CGROUP_V2_MNTS"
echo echo
CGROUP_SYSTEMD_MNTPT=`echo "$CGROUP_V1_MNTS" | grep "/systemd"`
if [ -z "$CGROUP_SYSTEMD_MNTPT" ]; then
echo -n "Cgroup v1 systemd controller: "
"$SETCOLOR_FAILURE" && echo -n "missing" && $SETCOLOR_NORMAL
echo
fi
CGROUP_FREEZER_MNTPT=`echo "$CGROUP_V1_MNTS" | grep "/freezer"`
if [ -z "$CGROUP_FREEZER_MNTPT" ]; then
echo -n "Cgroup v1 freezer controller: "
"$SETCOLOR_FAILURE" && echo -n "missing" && $SETCOLOR_NORMAL
echo
fi
CGROUP_MNT_PATH=`echo "$CGROUP_V1_MNTS" | head -n 1`
if [ -f $CGROUP_MNT_PATH/cgroup.clone_children ]; then if [ -f $CGROUP_MNT_PATH/cgroup.clone_children ]; then
echo -n "Cgroup clone_children flag: " && echo -n "Cgroup v1 clone_children flag: " &&
$SETCOLOR_SUCCESS && echo "enabled" && $SETCOLOR_NORMAL $SETCOLOR_SUCCESS && echo "enabled" && $SETCOLOR_NORMAL
else else
echo -n "Cgroup namespace: " && is_enabled CONFIG_CGROUP_NS yes echo -n "Cgroup namespace: " && is_enabled CONFIG_CGROUP_NS yes
fi fi
echo -n "Cgroup device: " && is_enabled CONFIG_CGROUP_DEVICE echo -n "Cgroup device: " && is_enabled CONFIG_CGROUP_DEVICE
echo echo
echo -n "Cgroup sched: " && is_enabled CONFIG_CGROUP_SCHED echo -n "Cgroup sched: " && is_enabled CONFIG_CGROUP_SCHED
echo echo
echo -n "Cgroup cpu account: " && is_enabled CONFIG_CGROUP_CPUACCT echo -n "Cgroup cpu account: " && is_enabled CONFIG_CGROUP_CPUACCT
echo echo
echo -n "Cgroup memory controller: " echo -n "Cgroup memory controller: "
if ([ $KVER_MAJOR -ge 3 ] && [ $KVER_MINOR -ge 6 ]) || ([ $KVER_MAJOR -gt 3 ]); then if ([ $KVER_MAJOR -ge 3 ] && [ $KVER_MINOR -ge 6 ]) || ([ $KVER_MAJOR -gt 3 ]); then
is_enabled CONFIG_MEMCG is_enabled CONFIG_MEMCG
...@@ -159,8 +188,10 @@ else ...@@ -159,8 +188,10 @@ else
is_enabled CONFIG_CGROUP_MEM_RES_CTLR is_enabled CONFIG_CGROUP_MEM_RES_CTLR
fi fi
echo echo
is_set CONFIG_SMP && echo -n "Cgroup cpuset: " && is_enabled CONFIG_CPUSETS && echo is_set CONFIG_SMP && echo -n "Cgroup cpuset: " && is_enabled CONFIG_CPUSETS && echo
echo echo
echo "--- Misc ---" echo "--- Misc ---"
echo -n "Veth pair device: " && is_enabled CONFIG_VETH && is_probed veth echo -n "Veth pair device: " && is_enabled CONFIG_VETH && is_probed veth
echo echo
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment