From 289d6413ebac8b34394a9f5dbffdb6a70e7f145f Mon Sep 17 00:00:00 2001 From: Petr Malat Date: Wed, 15 Jun 2022 15:59:30 +0200 Subject: [PATCH 1/2] meson: Generate compile commands by iterating over an array This makes it possible to add a new command without updating multiple places in the meson file. Signed-off-by: Petr Malat --- src/lxc/tools/meson.build | 230 ++------------------------------------ 1 file changed, 12 insertions(+), 218 deletions(-) diff --git a/src/lxc/tools/meson.build b/src/lxc/tools/meson.build index 072f08beb..1bf3be0c2 100644 --- a/src/lxc/tools/meson.build +++ b/src/lxc/tools/meson.build @@ -2,224 +2,18 @@ tools_common_sources = liblxc_sources + files('arguments.c', 'arguments.h') + include_sources + netns_ifaddrs_sources -tools_lxc_attach_sources = files( - 'lxc_attach.c') + tools_common_sources - -tools_lxc_autostart_sources = files( - 'lxc_autostart.c') + tools_common_sources - -tools_lxc_cgroup_sources = files( - 'lxc_cgroup.c') + tools_common_sources - -tools_lxc_checkpoint_sources = files( - 'lxc_checkpoint.c') + tools_common_sources - -tools_lxc_config_sources = files( - 'lxc_config.c') + tools_common_sources - -tools_lxc_console_sources = files( - 'lxc_console.c') + tools_common_sources - -tools_lxc_copy_sources = files( - 'lxc_copy.c') + tools_common_sources - -tools_lxc_create_sources = files( - 'lxc_create.c') + tools_common_sources - -tools_lxc_destroy_sources = files( - 'lxc_destroy.c') + tools_common_sources - -tools_lxc_device_sources = files( - 'lxc_device.c') + tools_common_sources - -tools_lxc_execute_sources = files( - 'lxc_execute.c') + tools_common_sources - -tools_lxc_freeze_sources = files( - 'lxc_freeze.c') + tools_common_sources - -tools_lxc_info_sources = files( - 'lxc_info.c') + tools_common_sources - -tools_lxc_ls_sources = files( - 'lxc_ls.c') + tools_common_sources - -tools_lxc_monitor_sources = files( - 'lxc_monitor.c') + tools_common_sources - -tools_lxc_snapshot_sources = files( - 'lxc_snapshot.c') + tools_common_sources - -tools_lxc_start_sources = files( - 'lxc_start.c') + tools_common_sources - -tools_lxc_stop_sources = files( - 'lxc_stop.c') + tools_common_sources - -tools_lxc_top_sources = files( - 'lxc_top.c') + tools_common_sources - -tools_lxc_unfreeze_sources = files( - 'lxc_unfreeze.c') + tools_common_sources - -tools_lxc_unshare_sources = files( - 'lxc_unshare.c') + tools_common_sources - -tools_lxc_wait_sources = files( - 'lxc_wait.c') + tools_common_sources +tools_commands = ['attach', 'autostart', 'cgroup', 'checkpoint', 'config', + 'console', 'copy', 'create', 'destroy', 'device', 'execute', 'freeze', + 'info', 'ls', 'monitor', 'snapshot', 'start', 'stop', 'top', 'unfreeze', + 'unshare', 'wait'] if want_tools - public_programs += executable( - 'lxc-attach', - tools_lxc_attach_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-autostart', - tools_lxc_autostart_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-cgroup', - tools_lxc_cgroup_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-checkpoint', - tools_lxc_checkpoint_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-config', - tools_lxc_config_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-console', - tools_lxc_console_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-copy', - tools_lxc_copy_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-create', - tools_lxc_create_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-destroy', - tools_lxc_destroy_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-device', - tools_lxc_device_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-execute', - tools_lxc_execute_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-freeze', - tools_lxc_freeze_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-info', - tools_lxc_info_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-ls', - tools_lxc_ls_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-monitor', - tools_lxc_monitor_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-snapshot', - tools_lxc_snapshot_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-start', - tools_lxc_start_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-stop', - tools_lxc_stop_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-top', - tools_lxc_top_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-unfreeze', - tools_lxc_unfreeze_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-unshare', - tools_lxc_unshare_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) - - public_programs += executable( - 'lxc-wait', - tools_lxc_wait_sources, - include_directories: liblxc_includes, - dependencies: liblxc_dep, - install: true) + foreach cmd : tools_commands + public_programs += executable( + 'lxc-' + cmd, + files('lxc_' + cmd + '.c') + tools_common_sources, + include_directories: liblxc_includes, + dependencies: liblxc_dep, + install: true) + endforeach endif From f4d02217ee2baf7275175d2c6610de4908a9addf Mon Sep 17 00:00:00 2001 From: Petr Malat Date: Wed, 15 Jun 2022 13:16:43 +0200 Subject: [PATCH 2/2] tools: Provide multicall lxc binary Create a binary, which embeds all lxc tools similar way as busybox embeds its applets. This is handy for embedded systems as it saves roughly 90% of the disk space. To disable normal tools and use multicall binary exclusively use the following meson setup options: -Dtools=false -Dtools-multicall=true Signed-off-by: Petr Malat --- meson.build | 3 +- meson_options.txt | 3 + src/lxc/tools/lxc_attach.c | 3 +- src/lxc/tools/lxc_autostart.c | 3 +- src/lxc/tools/lxc_cgroup.c | 3 +- src/lxc/tools/lxc_checkpoint.c | 3 +- src/lxc/tools/lxc_config.c | 3 +- src/lxc/tools/lxc_console.c | 3 +- src/lxc/tools/lxc_copy.c | 3 +- src/lxc/tools/lxc_create.c | 3 +- src/lxc/tools/lxc_destroy.c | 3 +- src/lxc/tools/lxc_device.c | 3 +- src/lxc/tools/lxc_execute.c | 3 +- src/lxc/tools/lxc_freeze.c | 3 +- src/lxc/tools/lxc_info.c | 3 +- src/lxc/tools/lxc_ls.c | 3 +- src/lxc/tools/lxc_monitor.c | 3 +- src/lxc/tools/lxc_multicall.c | 108 +++++++++++++++++++++++++++++++++ src/lxc/tools/lxc_snapshot.c | 3 +- src/lxc/tools/lxc_start.c | 3 +- src/lxc/tools/lxc_stop.c | 3 +- src/lxc/tools/lxc_top.c | 3 +- src/lxc/tools/lxc_unfreeze.c | 3 +- src/lxc/tools/lxc_unshare.c | 3 +- src/lxc/tools/lxc_wait.c | 3 +- src/lxc/tools/meson.build | 23 +++++++ 26 files changed, 180 insertions(+), 23 deletions(-) create mode 100644 src/lxc/tools/lxc_multicall.c diff --git a/meson.build b/meson.build index d974a8392..7ec321462 100644 --- a/meson.build +++ b/meson.build @@ -141,6 +141,7 @@ want_pam_cgroup = get_option('pam-cgroup') want_mans = get_option('man') want_tests = get_option('tests') want_tools = get_option('tools') +want_tools_multicall = get_option('tools-multicall') want_commands = get_option('commands') want_capabilities = get_option('capabilities') want_apparmor = get_option('apparmor') @@ -793,7 +794,7 @@ subdir('hooks') if want_commands subdir('src/lxc/cmd') endif -if want_tools +if want_tools or want_tools_multicall subdir('src/lxc/tools') endif subdir('src/lxc/tools/include') diff --git a/meson_options.txt b/meson_options.txt index 8f9b4e118..d82ae3486 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -34,6 +34,9 @@ option('pam-cgroup', type: 'boolean', value: 'false', option('tools', type: 'boolean', value: 'true', description: 'build and install tools') +option('tools-multicall', type: 'boolean', value: 'false', + description: 'build and install busybox style multicall binary') + # was --{disable,enable}-commands in autotools option('commands', type: 'boolean', value: 'true', description: 'build and install commands') diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c index d7888ddf4..fa303c7b4 100644 --- a/src/lxc/tools/lxc_attach.c +++ b/src/lxc/tools/lxc_attach.c @@ -271,7 +271,8 @@ static int lxc_attach_create_log_file(const char *log_file) return fd; } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_attach_main"))) main(int argc, char *argv[]); +int lxc_attach_main(int argc, char *argv[]) { int ret = -1; int wexit = 0; diff --git a/src/lxc/tools/lxc_autostart.c b/src/lxc/tools/lxc_autostart.c index 062135d40..713e8efdf 100644 --- a/src/lxc/tools/lxc_autostart.c +++ b/src/lxc/tools/lxc_autostart.c @@ -304,7 +304,8 @@ static int toss_list(struct lxc_list *c_groups_list) return 1; } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_autostart_main"))) main(int argc, char *argv[]); +int lxc_autostart_main(int argc, char *argv[]) { int count = 0, failed = 0, i = 0, ret = 0; struct lxc_list *cmd_group; diff --git a/src/lxc/tools/lxc_cgroup.c b/src/lxc/tools/lxc_cgroup.c index eb96c63ee..017d6c734 100644 --- a/src/lxc/tools/lxc_cgroup.c +++ b/src/lxc/tools/lxc_cgroup.c @@ -50,7 +50,8 @@ static int my_checker(const struct lxc_arguments *args) return 0; } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_cgroup_main"))) main(int argc, char *argv[]); +int lxc_cgroup_main(int argc, char *argv[]) { char *state_object = NULL, *value = NULL; struct lxc_container *c; diff --git a/src/lxc/tools/lxc_checkpoint.c b/src/lxc/tools/lxc_checkpoint.c index a8edb4526..3287904f6 100644 --- a/src/lxc/tools/lxc_checkpoint.c +++ b/src/lxc/tools/lxc_checkpoint.c @@ -246,7 +246,8 @@ static bool restore(struct lxc_container *c) } } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_checkpoint_main"))) main(int argc, char *argv[]); +int lxc_checkpoint_main(int argc, char *argv[]) { struct lxc_container *c; struct lxc_log log; diff --git a/src/lxc/tools/lxc_config.c b/src/lxc/tools/lxc_config.c index e4424c4cf..a240d02c9 100644 --- a/src/lxc/tools/lxc_config.c +++ b/src/lxc/tools/lxc_config.c @@ -40,7 +40,8 @@ static void list_config_items(void) exit(EXIT_SUCCESS); } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_config_main"))) main(int argc, char *argv[]); +int lxc_config_main(int argc, char *argv[]) { struct lxc_config_items *i; const char *value; diff --git a/src/lxc/tools/lxc_console.c b/src/lxc/tools/lxc_console.c index 7f43f506b..13d9844ca 100644 --- a/src/lxc/tools/lxc_console.c +++ b/src/lxc/tools/lxc_console.c @@ -77,7 +77,8 @@ static char etoc(const char *expr) return 1 + ((c > 'Z') ? (c - 'a') : (c - 'Z')); } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_console_main"))) main(int argc, char *argv[]); +int lxc_console_main(int argc, char *argv[]) { int ret; struct lxc_container *c; diff --git a/src/lxc/tools/lxc_copy.c b/src/lxc/tools/lxc_copy.c index c7158cc0b..04118e9fa 100644 --- a/src/lxc/tools/lxc_copy.c +++ b/src/lxc/tools/lxc_copy.c @@ -142,7 +142,8 @@ static int parse_mntsubopts(char *subopts, char *const *keys, static int parse_bind_mnt(char *mntstring, enum mnttype type); static int parse_ovl_mnt(char *mntstring, enum mnttype type); -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_copy_main"))) main(int argc, char *argv[]); +int lxc_copy_main(int argc, char *argv[]) { struct lxc_container *c; struct lxc_log log; diff --git a/src/lxc/tools/lxc_create.c b/src/lxc/tools/lxc_create.c index f0482867a..9eda550f5 100644 --- a/src/lxc/tools/lxc_create.c +++ b/src/lxc/tools/lxc_create.c @@ -190,7 +190,8 @@ static bool validate_bdev_args(struct lxc_arguments *args) return true; } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_create_main"))) main(int argc, char *argv[]); +int lxc_create_main(int argc, char *argv[]) { struct lxc_container *c; struct bdev_specs spec; diff --git a/src/lxc/tools/lxc_destroy.c b/src/lxc/tools/lxc_destroy.c index 581460ae4..e0fb09c57 100644 --- a/src/lxc/tools/lxc_destroy.c +++ b/src/lxc/tools/lxc_destroy.c @@ -188,7 +188,8 @@ static bool do_destroy_with_snapshots(struct lxc_container *c) return bret; } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_destroy_main"))) main(int argc, char *argv[]); +int lxc_destroy_main(int argc, char *argv[]) { struct lxc_container *c; struct lxc_log log; diff --git a/src/lxc/tools/lxc_device.c b/src/lxc/tools/lxc_device.c index 82e543462..2dcdab7d3 100644 --- a/src/lxc/tools/lxc_device.c +++ b/src/lxc/tools/lxc_device.c @@ -78,7 +78,8 @@ static bool is_interface(const char *dev_name, pid_t pid) return false; } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_device_main"))) main(int argc, char *argv[]); +int lxc_device_main(int argc, char *argv[]) { struct lxc_container *c; struct lxc_log log; diff --git a/src/lxc/tools/lxc_execute.c b/src/lxc/tools/lxc_execute.c index 5b6a863b4..c5c6d56c3 100644 --- a/src/lxc/tools/lxc_execute.c +++ b/src/lxc/tools/lxc_execute.c @@ -128,7 +128,8 @@ static bool set_argv(struct lxc_container *c, struct lxc_arguments *args) return true; } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_execute_main"))) main(int argc, char *argv[]); +int lxc_execute_main(int argc, char *argv[]) { struct lxc_container *c; struct lxc_log log; diff --git a/src/lxc/tools/lxc_freeze.c b/src/lxc/tools/lxc_freeze.c index c18779ba3..99dad9578 100644 --- a/src/lxc/tools/lxc_freeze.c +++ b/src/lxc/tools/lxc_freeze.c @@ -36,7 +36,8 @@ Options :\n\ .log_file = "none", }; -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_freeze_main"))) main(int argc, char *argv[]); +int lxc_freeze_main(int argc, char *argv[]) { struct lxc_container *c; struct lxc_log log; diff --git a/src/lxc/tools/lxc_info.c b/src/lxc/tools/lxc_info.c index 9755a503d..8929720b1 100644 --- a/src/lxc/tools/lxc_info.c +++ b/src/lxc/tools/lxc_info.c @@ -388,7 +388,8 @@ static int print_info(const char *name, const char *lxcpath) return 0; } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_info_main"))) main(int argc, char *argv[]); +int lxc_info_main(int argc, char *argv[]) { int ret = EXIT_FAILURE; struct lxc_log log; diff --git a/src/lxc/tools/lxc_ls.c b/src/lxc/tools/lxc_ls.c index 23bee59de..2be4e790a 100644 --- a/src/lxc/tools/lxc_ls.c +++ b/src/lxc/tools/lxc_ls.c @@ -188,7 +188,8 @@ Options :\n\ .ls_nesting = 0, }; -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_ls_main"))) main(int argc, char *argv[]); +int lxc_ls_main(int argc, char *argv[]) { int ret = EXIT_FAILURE; struct lxc_log log; diff --git a/src/lxc/tools/lxc_monitor.c b/src/lxc/tools/lxc_monitor.c index 6065f2683..4c6d063e3 100644 --- a/src/lxc/tools/lxc_monitor.c +++ b/src/lxc/tools/lxc_monitor.c @@ -216,7 +216,8 @@ static int lxc_tool_monitord_spawn(const char *lxcpath) _exit(EXIT_FAILURE); } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_monitor_main"))) main(int argc, char *argv[]); +int lxc_monitor_main(int argc, char *argv[]) { char *regexp; struct lxc_msg msg; diff --git a/src/lxc/tools/lxc_multicall.c b/src/lxc/tools/lxc_multicall.c new file mode 100644 index 000000000..a90923ea3 --- /dev/null +++ b/src/lxc/tools/lxc_multicall.c @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include + +#define PREFIX "lxc-" + +int lxc_attach_main(int argc, char *argv[]); +int lxc_autostart_main(int argc, char *argv[]); +int lxc_cgroup_main(int argc, char *argv[]); +int lxc_checkpoint_main(int argc, char *argv[]); +int lxc_config_main(int argc, char *argv[]); +int lxc_console_main(int argc, char *argv[]); +int lxc_copy_main(int argc, char *argv[]); +int lxc_create_main(int argc, char *argv[]); +int lxc_destroy_main(int argc, char *argv[]); +int lxc_device_main(int argc, char *argv[]); +int lxc_execute_main(int argc, char *argv[]); +int lxc_freeze_main(int argc, char *argv[]); +int lxc_info_main(int argc, char *argv[]); +int lxc_ls_main(int argc, char *argv[]); +int lxc_monitor_main(int argc, char *argv[]); +int lxc_snapshot_main(int argc, char *argv[]); +int lxc_start_main(int argc, char *argv[]); +int lxc_stop_main(int argc, char *argv[]); +int lxc_top_main(int argc, char *argv[]); +int lxc_unfreeze_main(int argc, char *argv[]); +int lxc_unshare_main(int argc, char *argv[]); +int lxc_wait_main(int argc, char *argv[]); + +static const struct { + const char *cmd; + int (*main)(int argc, char *argv[]); +} applets[] = { + { "attach", lxc_attach_main }, + { "autostart", lxc_autostart_main }, + { "cgroup", lxc_cgroup_main }, + { "checkpoint", lxc_checkpoint_main }, + { "config", lxc_config_main }, + { "console", lxc_console_main }, + { "copy", lxc_copy_main }, + { "create", lxc_create_main }, + { "destroy", lxc_destroy_main }, + { "device", lxc_device_main }, + { "execute", lxc_execute_main }, + { "freeze", lxc_freeze_main }, + { "info", lxc_info_main }, + { "ls", lxc_ls_main }, + { "monitor", lxc_monitor_main }, + { "snapshot", lxc_snapshot_main }, + { "start", lxc_start_main }, + { "stop", lxc_stop_main }, + { "top", lxc_top_main }, + { "unfreeze", lxc_unfreeze_main }, + { "unshare", lxc_unshare_main }, + { "wait", lxc_wait_main } +}; + +const int applets_nmemb = (int)(sizeof(applets)/sizeof(applets[0])); + +int main(int argc, char *argv[]) +{ + const char *cmd; + int i; + + if (argc < 1) + goto err0; + + cmd = strrchr(argv[0], '/'); + cmd = cmd ? cmd + 1 : argv[0]; + + + if (!strcmp(cmd, "lxc")) { + if (argc < 2) + goto err0; + cmd = argv[1]; + argc -= 1; + argv += 1; + if (!strcmp(cmd, "-h") || !strcmp(cmd, "--help")) + goto err0; + } else if (!strncmp(cmd, PREFIX, strlen(PREFIX))) { + cmd += strlen(PREFIX); + } else { + goto err0; + } + + for (i = 0; i < applets_nmemb; i++) { + if (!strcmp(applets[i].cmd, cmd)) + return applets[i].main(argc, argv); + } + + fprintf(stderr, "Unsupported command '%s'\n", cmd); + goto err1; + +err0: fprintf(stderr, "This is a multi-call binary, argv[0] is expected to be\n" + " a name of the requested command prefixed with '%s'\n" + "or\n" + " 'lxc' and the command should be the 1st argument.\n\n" + "For example calling this program as '%sls' or 'lxc' " + "with the argument 'ls' lists containers.\n\n", + PREFIX, PREFIX); +err1: fprintf(stderr, "Known commands:\n"); + for (i = 0; i < applets_nmemb; i++) { + fprintf(stderr, "%s ", applets[i].cmd); + } + putc('\n', stderr); + return 1; +} diff --git a/src/lxc/tools/lxc_snapshot.c b/src/lxc/tools/lxc_snapshot.c index fc2e91c6b..83effaf68 100644 --- a/src/lxc/tools/lxc_snapshot.c +++ b/src/lxc/tools/lxc_snapshot.c @@ -61,7 +61,8 @@ static int do_snapshot_restore(struct lxc_container *c, static int do_snapshot_task(struct lxc_container *c, enum task task); static void print_file(char *path); -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_snapshot_main"))) main(int argc, char *argv[]); +int lxc_snapshot_main(int argc, char *argv[]) { struct lxc_container *c; struct lxc_log log; diff --git a/src/lxc/tools/lxc_start.c b/src/lxc/tools/lxc_start.c index 6d2c0ae25..b1b3ca5da 100644 --- a/src/lxc/tools/lxc_start.c +++ b/src/lxc/tools/lxc_start.c @@ -149,7 +149,8 @@ static int ensure_path(char **confpath, const char *path) return 0; } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_start_main"))) main(int argc, char *argv[]); +int lxc_start_main(int argc, char *argv[]) { const char *lxcpath; char *const *args; diff --git a/src/lxc/tools/lxc_stop.c b/src/lxc/tools/lxc_stop.c index 8787bacd5..98e567353 100644 --- a/src/lxc/tools/lxc_stop.c +++ b/src/lxc/tools/lxc_stop.c @@ -81,7 +81,8 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg) return 0; } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_stop_main"))) main(int argc, char *argv[]); +int lxc_stop_main(int argc, char *argv[]) { struct lxc_container *c; struct lxc_log log; diff --git a/src/lxc/tools/lxc_top.c b/src/lxc/tools/lxc_top.c index d3db4142c..3ddaf89e7 100644 --- a/src/lxc/tools/lxc_top.c +++ b/src/lxc/tools/lxc_top.c @@ -564,7 +564,8 @@ static int stdin_handler(int fd, uint32_t events, void *data, return LXC_MAINLOOP_CLOSE; } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_top_main"))) main(int argc, char *argv[]); +int lxc_top_main(int argc, char *argv[]) { struct lxc_async_descr descr; int ret, ct_print_cnt; diff --git a/src/lxc/tools/lxc_unfreeze.c b/src/lxc/tools/lxc_unfreeze.c index 818447cad..9c8dd3613 100644 --- a/src/lxc/tools/lxc_unfreeze.c +++ b/src/lxc/tools/lxc_unfreeze.c @@ -36,7 +36,8 @@ Options :\n\ .log_file = "none", }; -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_unfreeze_main"))) main(int argc, char *argv[]); +int lxc_unfreeze_main(int argc, char *argv[]) { struct lxc_container *c; struct lxc_log log; diff --git a/src/lxc/tools/lxc_unshare.c b/src/lxc/tools/lxc_unshare.c index d53f4299b..d4ab2e347 100644 --- a/src/lxc/tools/lxc_unshare.c +++ b/src/lxc/tools/lxc_unshare.c @@ -280,7 +280,8 @@ static void free_ifname_list(void) } } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_unshare_main"))) main(int argc, char *argv[]); +int lxc_unshare_main(int argc, char *argv[]) { int ret; pid_t pid; diff --git a/src/lxc/tools/lxc_wait.c b/src/lxc/tools/lxc_wait.c index 7bafbd52c..1c415e8c2 100644 --- a/src/lxc/tools/lxc_wait.c +++ b/src/lxc/tools/lxc_wait.c @@ -72,7 +72,8 @@ static int my_checker(const struct lxc_arguments *args) return 0; } -int main(int argc, char *argv[]) +int __attribute__((weak, alias("lxc_wait_main"))) main(int argc, char *argv[]); +int lxc_wait_main(int argc, char *argv[]) { struct lxc_container *c; struct lxc_log log; diff --git a/src/lxc/tools/meson.build b/src/lxc/tools/meson.build index 1bf3be0c2..c98d0e5be 100644 --- a/src/lxc/tools/meson.build +++ b/src/lxc/tools/meson.build @@ -17,3 +17,26 @@ if want_tools install: true) endforeach endif + +if want_tools_multicall + tools_all_sources = files('lxc_multicall.c') + tools_common_sources + foreach cmd : tools_commands + tools_all_sources += files('lxc_' + cmd + '.c') + endforeach + + public_programs += executable( + 'lxc', + tools_all_sources, + include_directories: liblxc_includes, + dependencies: liblxc_dep, + install: true) + + if want_tools == false + foreach cmd : tools_commands + public_programs += install_symlink( + 'lxc-' + cmd, + pointing_to: 'lxc', + install_dir: get_option('bindir')) + endforeach + endif +endif