Merge pull request #4149 from petris/lxc_multicall

tools: Provide multicall lxc binary
This commit is contained in:
Christian Brauner 2022-06-18 15:33:00 +02:00 committed by GitHub
commit 0a73102d43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 192 additions and 241 deletions

View File

@ -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')

View File

@ -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')

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -0,0 +1,108 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <string.h>
#include <stdio.h>
#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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -2,224 +2,41 @@
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
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