diff --git a/src/cmd/commander.h b/src/cmd/commander.h index 775456e91b67861ceca8370987c7132107489863..d1feb5c71c49e60c7a668786c3bad2e6b93dc8c0 100644 --- a/src/cmd/commander.h +++ b/src/cmd/commander.h @@ -21,6 +21,10 @@ #include "host_config.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifndef COMMANDER_MAX_OPTIONS #define COMMANDER_MAX_OPTIONS 64 #endif @@ -112,5 +116,9 @@ int check_default_ulimit_type(const char *type); void free_default_ulimit(host_config_ulimits_element **default_ulimit); +#ifdef __cplusplus +} +#endif + #endif /* COMMANDER_H */ diff --git a/src/cmd/isula/arguments.h b/src/cmd/isula/arguments.h index 4ecc5b6b840aeb6ee99f0f8c8401dbc171fa439e..1a1ab04755033edd54d9437c2da262aed5618244 100644 --- a/src/cmd/isula/arguments.h +++ b/src/cmd/isula/arguments.h @@ -26,6 +26,10 @@ #include "json_common.h" #include "isula_connect.h" +#ifdef __cplusplus +extern "C" { +#endif + /* max arguments can be specify in client */ #define MAX_CLIENT_ARGS 1000 @@ -322,15 +326,15 @@ struct client_arguments { { CMD_OPT_TYPE_STRING_DUP, false, "host", 'H', &(cmdargs).socket, \ "Daemon socket(s) to connect to", command_valid_socket }, \ { CMD_OPT_TYPE_BOOL, false, "tls", 0, &(cmdargs).tls, \ - "Use TLS; implied by --tlsverify", NULL}, \ + "Use TLS; implied by --tlsverify", NULL}, \ { CMD_OPT_TYPE_BOOL, false, "tlsverify", 0, &(cmdargs).tls_verify, \ - "Use TLS and verify the remote", NULL}, \ + "Use TLS and verify the remote", NULL}, \ { CMD_OPT_TYPE_STRING_DUP, false, "tlscacert", 0, &(cmdargs).ca_file, \ - "Trust certs signed only by this CA (default \"/root/.iSulad/ca.pem\")", NULL }, \ + "Trust certs signed only by this CA (default \"/root/.iSulad/ca.pem\")", NULL }, \ { CMD_OPT_TYPE_STRING_DUP, false, "tlscert", 0, &(cmdargs).cert_file, \ - "Path to TLS certificate file (default \"/root/.iSulad/cert.pem\")", NULL }, \ + "Path to TLS certificate file (default \"/root/.iSulad/cert.pem\")", NULL }, \ { CMD_OPT_TYPE_STRING_DUP, false, "tlskey", 0, &(cmdargs).key_file, \ - "Path to TLS key file (default \"/root/.iSulad/key.pem\")", NULL }, \ + "Path to TLS key file (default \"/root/.iSulad/key.pem\")", NULL }, \ { CMD_OPT_TYPE_STRING, false, "help", 0, NULL, "Print usage", NULL } #define VERSION_OPTIONS(cmdargs) \ @@ -350,5 +354,9 @@ extern void client_print_error(uint32_t cc, uint32_t server_errono, const char * extern client_connect_config_t get_connect_config(const struct client_arguments *args); +#ifdef __cplusplus +} +#endif + #endif /* __ISULA_ARGUMENTS_H */ diff --git a/src/cmd/isula/base/create.h b/src/cmd/isula/base/create.h index 87ad1c1cea2ff03343e5ad85372890e879d8f0a7..b586831ec12fcb66ff1917d1a789c981b1581584 100644 --- a/src/cmd/isula/base/create.h +++ b/src/cmd/isula/base/create.h @@ -17,137 +17,141 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define CREATE_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_CALLBACK, false, "accel", 0, &(cmdargs).custom_conf.accel, \ "Accelerator bindings (format: [=][@[,]])", \ command_append_array }, \ { CMD_OPT_TYPE_BOOL, false, "read-only", 0, &(cmdargs).custom_conf.readonly, \ - "Make container rootfs readonly", NULL }, \ + "Make container rootfs readonly", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "cap-add", 0, &(cmdargs).custom_conf.cap_adds, \ - "Add Linux capabilities ('ALL' to add all capabilities)", command_append_array }, \ + "Add Linux capabilities ('ALL' to add all capabilities)", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "cap-drop", 0, &(cmdargs).custom_conf.cap_drops, \ - "Drop Linux capabilities ('ALL' to drop all capabilities)", command_append_array }, \ + "Drop Linux capabilities ('ALL' to drop all capabilities)", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "cpu-shares", 0, &(cmdargs).cr.cpu_shares, \ - "CPU shares (relative weight)", command_convert_llong }, \ + "CPU shares (relative weight)", command_convert_llong }, \ { CMD_OPT_TYPE_CALLBACK, false, "cpu-period", 0, &(cmdargs).cr.cpu_period, \ - "Limit CPU CFS (Completely Fair Scheduler) period", command_convert_llong }, \ + "Limit CPU CFS (Completely Fair Scheduler) period", command_convert_llong }, \ { CMD_OPT_TYPE_CALLBACK, false, "cpu-quota", 0, &(cmdargs).cr.cpu_quota, \ - "Limit CPU CFS (Completely Fair Scheduler) quota", command_convert_llong }, \ + "Limit CPU CFS (Completely Fair Scheduler) quota", command_convert_llong }, \ { CMD_OPT_TYPE_STRING, false, "cpuset-cpus", 0, &(cmdargs).cr.cpuset_cpus, \ - "CPUs in which to allow execution (e.g. 0-3, 0,1)", NULL }, \ + "CPUs in which to allow execution (e.g. 0-3, 0,1)", NULL }, \ { CMD_OPT_TYPE_STRING, false, "cpuset-mems", 0, &(cmdargs).cr.cpuset_mems, \ - "MEMs in which to allow execution (0-3, 0,1)", NULL }, \ + "MEMs in which to allow execution (0-3, 0,1)", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "device-read-bps", 0, &(cmdargs).custom_conf.blkio_throttle_read_bps_device, \ - "Limit read rate (bytes per second) from a device (default [])", command_append_array }, \ + "Limit read rate (bytes per second) from a device (default [])", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "device-write-bps", 0, &(cmdargs).custom_conf.blkio_throttle_write_bps_device, \ - "Limit write rate (bytes per second) to a device (default [])", command_append_array }, \ + "Limit write rate (bytes per second) to a device (default [])", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "oom-score-adj", 0, &(cmdargs).cr.oom_score_adj, \ - "Tune host's OOM preferences (-1000 to 1000)", command_convert_llong }, \ + "Tune host's OOM preferences (-1000 to 1000)", command_convert_llong }, \ { CMD_OPT_TYPE_CALLBACK, false, "device", 0, &(cmdargs).custom_conf.devices, \ - "Add a host device to the container", command_append_array }, \ + "Add a host device to the container", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "env", 'e', &(cmdargs).custom_conf.env, \ - "Set environment variables", command_append_array }, \ + "Set environment variables", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "env-file", 0, &(cmdargs).custom_conf.env_file, \ - "Read in a file of environment variables", command_append_array }, \ + "Read in a file of environment variables", command_append_array }, \ { CMD_OPT_TYPE_STRING_DUP, false, "entrypoint", 0, &(cmdargs).custom_conf.entrypoint, \ - "Entrypoint to run when starting the container", NULL }, \ + "Entrypoint to run when starting the container", NULL }, \ { CMD_OPT_TYPE_STRING, false, "external-rootfs", 0, &(cmdargs).external_rootfs, \ - "Specify the custom rootfs that is not managed by isulad for the container, directory or block device", NULL }, \ + "Specify the custom rootfs that is not managed by isulad for the container, directory or block device", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "files-limit", 0, &(cmdargs).custom_conf.files_limit, \ - "Tune container files limit (set -1 for unlimited)", command_convert_llong }, \ + "Tune container files limit (set -1 for unlimited)", command_convert_llong }, \ { CMD_OPT_TYPE_STRING_DUP, false, "hook-spec", 0, &(cmdargs).custom_conf.hook_spec, \ - "File containing hook definition(prestart, poststart, poststop)", NULL }, \ + "File containing hook definition(prestart, poststart, poststop)", NULL }, \ { CMD_OPT_TYPE_STRING_DUP, false, "hostname", 'h', &(cmdargs).custom_conf.hostname, \ - "Container host name", NULL }, \ + "Container host name", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "add-host", 0, &(cmdargs).custom_conf.extra_hosts, \ - "Add a custom host-to-IP mapping (host:ip)", command_append_array }, \ + "Add a custom host-to-IP mapping (host:ip)", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "dns", 0, &(cmdargs).custom_conf.dns, \ - "Set custom DNS servers", command_append_array }, \ + "Set custom DNS servers", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "dns-opt", 0, &(cmdargs).custom_conf.dns_options, \ - "Set DNS options", command_append_array }, \ + "Set DNS options", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "dns-search", 0, &(cmdargs).custom_conf.dns_search, \ - "Set custom DNS search domains", command_append_array }, \ + "Set custom DNS search domains", command_append_array }, \ { CMD_OPT_TYPE_STRING, false, "user-remap", 0, &(cmdargs).custom_conf.user_remap, \ - "Set user remap for container", NULL }, \ + "Set user remap for container", NULL }, \ { CMD_OPT_TYPE_STRING_DUP, false, "ipc", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_IPC], \ - "IPC namespace to use", NULL }, \ + "IPC namespace to use", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "shm-size", 0, &(cmdargs).custom_conf.shm_size, \ - "Size of /dev/shm, default value is 64MB", command_convert_membytes }, \ + "Size of /dev/shm, default value is 64MB", command_convert_membytes }, \ { CMD_OPT_TYPE_CALLBACK, false, "kernel-memory", 0, &(cmdargs).cr.kernel_memory_limit, \ - "Kernel memory limit", command_convert_membytes }, \ + "Kernel memory limit", command_convert_membytes }, \ { CMD_OPT_TYPE_CALLBACK, false, "hugetlb-limit", 0, &(cmdargs).custom_conf.hugepage_limits, \ - "Huge page limit (format: [size:], e.g. --hugetlb-limit 2MB:32MB)", command_append_array }, \ + "Huge page limit (format: [size:], e.g. --hugetlb-limit 2MB:32MB)", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "log-opt", 0, &(cmdargs), \ - "Container log options, value formate: key=value", callback_log_opt }, \ + "Container log options, value formate: key=value", callback_log_opt }, \ { CMD_OPT_TYPE_CALLBACK, false, "memory", 'm', &(cmdargs).cr.memory_limit, \ - "Memory limit", command_convert_membytes }, \ + "Memory limit", command_convert_membytes }, \ { CMD_OPT_TYPE_CALLBACK, false, "memory-reservation", 0, &(cmdargs).cr.memory_reservation, \ - "Memory soft limit", command_convert_membytes }, \ + "Memory soft limit", command_convert_membytes }, \ { CMD_OPT_TYPE_CALLBACK, false, "memory-swap", 0, &(cmdargs).cr.memory_swap, \ - "Swap limit equal to memory plus swap: '-1' to enable unlimited swap", command_convert_memswapbytes }, \ + "Swap limit equal to memory plus swap: '-1' to enable unlimited swap", command_convert_memswapbytes }, \ { CMD_OPT_TYPE_CALLBACK, false, "mount", 0, &(cmdargs).custom_conf.mounts, \ - "Attach a filesystem mount to the service", command_append_array }, \ + "Attach a filesystem mount to the service", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "group-add", 0, &(cmdargs).custom_conf.group_add, \ - "Add additional groups to join", command_append_array }, \ + "Add additional groups to join", command_append_array }, \ { CMD_OPT_TYPE_STRING_DUP, false, "name", 'n', &(cmdargs).name, "Name of the container", NULL }, \ { CMD_OPT_TYPE_STRING_DUP, false, "net", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_NET], \ - "Connect a container to a network", NULL }, \ + "Connect a container to a network", NULL }, \ { CMD_OPT_TYPE_STRING_DUP, false, "pid", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_PID], \ - "PID namespace to use", NULL }, \ + "PID namespace to use", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "pids-limit", 0, &(cmdargs).custom_conf.pids_limit, \ - "Tune container pids limit (set -1 for unlimited)", command_convert_llong }, \ + "Tune container pids limit (set -1 for unlimited)", command_convert_llong }, \ { CMD_OPT_TYPE_BOOL, false, "privileged", 0, &(cmdargs).custom_conf.privileged, \ - "Give extended privileges to this container", NULL }, \ + "Give extended privileges to this container", NULL }, \ { CMD_OPT_TYPE_BOOL, false, "tty", 't', &(cmdargs).custom_conf.tty, "Allocate a pseudo-TTY", NULL }, \ { CMD_OPT_TYPE_STRING, false, "restart", 0, &(cmdargs).restart, \ - "Restart policy to apply when a container exits(no, always, on-reboot, on-failure[:max-retries])", NULL }, \ + "Restart policy to apply when a container exits(no, always, on-reboot, on-failure[:max-retries])", NULL }, \ { CMD_OPT_TYPE_STRING, false, "host-channel", 0, &(cmdargs).host_channel, \ - "Create share memory between host and container", NULL }, \ + "Create share memory between host and container", NULL }, \ { CMD_OPT_TYPE_STRING, false, "runtime", 'R', &(cmdargs).runtime, \ - "Runtime to use for containers(default: lcr)", NULL }, \ + "Runtime to use for containers(default: lcr)", NULL }, \ { CMD_OPT_TYPE_STRING_DUP, false, "user", 'u', &(cmdargs).custom_conf.user, \ - "Username or UID (format: [:])", NULL }, \ + "Username or UID (format: [:])", NULL }, \ { CMD_OPT_TYPE_STRING_DUP, false, "uts", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_UTS], \ - "UTS namespace to use", NULL }, \ + "UTS namespace to use", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "volume", 'v', &(cmdargs).custom_conf.volumes, \ - "Bind mount a volume", command_append_array }, \ + "Bind mount a volume", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "annotation", 0, &(cmdargs), \ - "Set annotations on a container", callback_annotation }, \ + "Set annotations on a container", callback_annotation }, \ { CMD_OPT_TYPE_STRING_DUP, false, "workdir", 0, &(cmdargs).custom_conf.workdir, \ - "Working directory inside the container", NULL }, \ + "Working directory inside the container", NULL }, \ { CMD_OPT_TYPE_BOOL, false, "system-container", 0, &(cmdargs).custom_conf.system_container, \ - "Extend some features only needed by running system container", NULL }, \ + "Extend some features only needed by running system container", NULL }, \ { CMD_OPT_TYPE_BOOL, false, "oom-kill-disable", 0, &(cmdargs).custom_conf.oom_kill_disable, \ - "Disable OOM Killer", NULL }, \ + "Disable OOM Killer", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "security-opt", 0, &(cmdargs).custom_conf.security, \ - "Security Options (default [])", command_append_array }, \ + "Security Options (default [])", command_append_array }, \ { CMD_OPT_TYPE_CALLBACK, false, "storage-opt", 0, &(cmdargs).custom_conf.storage_opts, \ - "Storage driver options for the container", command_append_array }, \ + "Storage driver options for the container", command_append_array }, \ { CMD_OPT_TYPE_STRING_DUP, false, "health-cmd", 0, &(cmdargs).custom_conf.health_cmd, \ - "Command to run to check health", NULL }, \ + "Command to run to check health", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "sysctl", 0, &(cmdargs).custom_conf.sysctls, \ - "Sysctl options", command_append_array }, \ + "Sysctl options", command_append_array }, \ { CMD_OPT_TYPE_STRING_DUP, false, "env-target-file", 0, &(cmdargs).custom_conf.env_target_file, \ - "Export env to target file path in rootfs", NULL }, \ + "Export env to target file path in rootfs", NULL }, \ { CMD_OPT_TYPE_STRING_DUP, false, "cgroup-parent", 0, &(cmdargs).custom_conf.cgroup_parent, \ - "Optional parent cgroup for the container", NULL }, \ + "Optional parent cgroup for the container", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "health-interval", 0, &(cmdargs).custom_conf.health_interval, \ - "Time between running the check (ms|s|m|h) (default 30s)", command_convert_nanoseconds }, \ + "Time between running the check (ms|s|m|h) (default 30s)", command_convert_nanoseconds }, \ { CMD_OPT_TYPE_CALLBACK, false, "health-retries", 0, &(cmdargs).custom_conf.health_retries, \ - "Consecutive failures needed to report unhealthy (default 3)", command_convert_int }, \ + "Consecutive failures needed to report unhealthy (default 3)", command_convert_int }, \ { CMD_OPT_TYPE_CALLBACK, false, "health-timeout", 0, &(cmdargs).custom_conf.health_timeout, \ - "Maximum time to allow one check to run (ms|s|m|h) (default 30s)", command_convert_nanoseconds }, \ + "Maximum time to allow one check to run (ms|s|m|h) (default 30s)", command_convert_nanoseconds }, \ { CMD_OPT_TYPE_CALLBACK, false, "health-start-period", 0, &(cmdargs).custom_conf.health_start_period, \ - "Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) " \ - "(default 0s)", command_convert_nanoseconds }, \ + "Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) " \ + "(default 0s)", command_convert_nanoseconds }, \ { CMD_OPT_TYPE_BOOL, false, "no-healthcheck", 0, &(cmdargs).custom_conf.no_healthcheck, \ - "Disable any container-specified HEALTHCHECK", NULL }, \ + "Disable any container-specified HEALTHCHECK", NULL }, \ { CMD_OPT_TYPE_BOOL, false, "health-exit-on-unhealthy", 0, &(cmdargs).custom_conf.exit_on_unhealthy, \ - "Kill the container when it is detected to be unhealthy", NULL }, \ + "Kill the container when it is detected to be unhealthy", NULL }, \ { CMD_OPT_TYPE_STRING, false, "ns-change-opt", 0, &(cmdargs).custom_conf.ns_change_opt, \ - "Namespaced kernel param options for system container (default [])", NULL }, \ + "Namespaced kernel param options for system container (default [])", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "ulimit", 0, &(cmdargs).custom_conf.ulimits, \ - "Ulimit options (default [])", command_append_array } + "Ulimit options (default [])", command_append_array } #define CREATE_EXTEND_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_BOOL, false, "interactive", 'i', &(cmdargs).custom_conf.open_stdin, \ @@ -169,5 +173,9 @@ int callback_annotation(command_option_t *option, const char *value); int cmd_create_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_CREATE_H */ diff --git a/src/cmd/isula/base/kill.h b/src/cmd/isula/base/kill.h index 605b225058551447678ec2d949d6bcf99986cc9b..8b087869fddc942d0754d6576211e4b5917eebd3 100644 --- a/src/cmd/isula/base/kill.h +++ b/src/cmd/isula/base/kill.h @@ -18,6 +18,10 @@ #include "arguments.h" #include "wait.h" +#ifdef __cplusplus +extern "C" { +#endif + #define KILL_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_STRING, false, "signal", 's', &(cmdargs).signal, \ "Signal to send to the container (default \"SIGKILL\")", NULL } @@ -26,5 +30,10 @@ extern const char g_cmd_kill_desc[]; extern const char g_cmd_kill_usage[]; extern struct client_arguments g_cmd_kill_args; int cmd_kill_main(int argc, const char **argv); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/cmd/isula/base/rename.h b/src/cmd/isula/base/rename.h index 9f921f7bdbb72df289c0b4365780cee226389d01..2f9c211c5015a370a2201cc3ae2cad1e0f0e527b 100644 --- a/src/cmd/isula/base/rename.h +++ b/src/cmd/isula/base/rename.h @@ -17,10 +17,18 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + extern const char g_cmd_rename_desc[]; extern const char g_cmd_rename_usage[]; extern struct client_arguments g_cmd_rename_args; int cmd_rename_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/cmd/isula/base/restart.h b/src/cmd/isula/base/restart.h index 1af6a224af110c9d197d6093e353bfe579ea7c68..0f1e00c5e233826c286fbec7e4c904559df538e0 100644 --- a/src/cmd/isula/base/restart.h +++ b/src/cmd/isula/base/restart.h @@ -15,6 +15,10 @@ #ifndef __CMD_RESTART_H #define __CMD_RESTART_H +#ifdef __cplusplus +extern "C" { +#endif + #define RESTART_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_CALLBACK, false, "time", 't', &(cmdargs).time, \ "Seconds to wait for stop before killing it (default 10)", command_convert_int } @@ -24,5 +28,9 @@ extern const char g_cmd_restart_usage[]; extern struct client_arguments g_cmd_restart_args; int cmd_restart_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_RESTART_H */ diff --git a/src/cmd/isula/base/rm.h b/src/cmd/isula/base/rm.h index 5f6ee084d8b4417d797b07fdbfcfb616f8f2b3c3..c89d7cfcd881742394c30a2e08d78a2e0f591019 100644 --- a/src/cmd/isula/base/rm.h +++ b/src/cmd/isula/base/rm.h @@ -17,16 +17,24 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define DELETE_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_BOOL, false, "force", 'f', &(cmdargs).force, \ "Force the removal of a running container (uses SIGKILL)", NULL }, \ { CMD_OPT_TYPE_BOOL, false, "volumes", 'v', &(cmdargs).volume, \ - "Remove the volumes associated with the container", NULL } + "Remove the volumes associated with the container", NULL } extern const char g_cmd_delete_desc[]; extern const char g_cmd_delete_usage[]; extern struct client_arguments g_cmd_delete_args; int cmd_delete_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_DELETE_H */ diff --git a/src/cmd/isula/base/run.h b/src/cmd/isula/base/run.h index e080fe3f047115f175cf3924a532afc859f5aac9..1589a2b0f958f8fd46ee0694ae52ab676c8ac01a 100644 --- a/src/cmd/isula/base/run.h +++ b/src/cmd/isula/base/run.h @@ -19,16 +19,24 @@ #include "start.h" #include "wait.h" +#ifdef __cplusplus +extern "C" { +#endif + #define RUN_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_BOOL, false, "detach", 'd', &(cmdargs).detach, \ "Run container in background and print container ID", NULL }, \ { CMD_OPT_TYPE_BOOL, false, "rm", 0, &(cmdargs).custom_conf.auto_remove, \ - "Automatically remove the container when it exits", NULL } + "Automatically remove the container when it exits", NULL } extern const char g_cmd_run_desc[]; extern const char g_cmd_run_usage[]; extern struct client_arguments g_cmd_run_args; int cmd_run_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_RUN_H */ diff --git a/src/cmd/isula/base/start.h b/src/cmd/isula/base/start.h index b5840000a2c53d67d923f80fea8751ddc7f742f4..69945ccb553b390fa11ff5722175efe2f1ebf4cb 100644 --- a/src/cmd/isula/base/start.h +++ b/src/cmd/isula/base/start.h @@ -19,6 +19,10 @@ #include "commands.h" #include +#ifdef __cplusplus +extern "C" { +#endif + extern const char g_cmd_start_desc[]; extern struct client_arguments g_cmd_start_args; @@ -28,5 +32,10 @@ void client_restore_console(bool reset_tty, const struct termios *oldtios, struc int client_start(const struct client_arguments *args, bool *reset_tty, struct termios *oldtios, struct command_fifo_config **console_fifos); int cmd_start_main(int argc, const char **argv); + +#ifdef __cplusplus +} +#endif + #endif /* __CMD_START_H */ diff --git a/src/cmd/isula/base/stop.h b/src/cmd/isula/base/stop.h index f2f1dbc61ab6288e28f8b0d906fc18cc6c2e01f9..9b6fdcbd0fee42f85538c46415882670924b77a3 100644 --- a/src/cmd/isula/base/stop.h +++ b/src/cmd/isula/base/stop.h @@ -17,10 +17,14 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define STOP_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_BOOL, false, "force", 'f', &(cmdargs).force, "Stop by force killing", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "time", 't', &(cmdargs).time, \ - "Seconds to wait for stop before killing it (default 10)", command_convert_int } + "Seconds to wait for stop before killing it (default 10)", command_convert_int } extern const char g_cmd_stop_desc[]; extern const char g_cmd_stop_usage[]; @@ -28,5 +32,9 @@ extern struct client_arguments g_cmd_stop_args; int cmd_stop_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_STOP_H */ diff --git a/src/cmd/isula/commands.h b/src/cmd/isula/commands.h index 7ed3b979d8d6b81a0800f4c1b0f650e610ee4904..06f6cf3293c3bc2ca1dbdc4b253671d4c7243786 100644 --- a/src/cmd/isula/commands.h +++ b/src/cmd/isula/commands.h @@ -18,6 +18,10 @@ #include "arguments.h" #include +#ifdef __cplusplus +extern "C" { +#endif + #define CLIENT_RUNDIR "/var/run/isula" // A command is described by: @@ -69,5 +73,10 @@ int commmand_default_help(const char * const program_name, const char **argv); int run_command(struct command *commands, int argc, const char **argv); + +#ifdef __cplusplus +} +#endif + #endif /* __COMMAND_H */ diff --git a/src/cmd/isula/extend/events.h b/src/cmd/isula/extend/events.h index 76f498217c2e2a90bda0a4f9d8070b99d3de25a8..09435265ef94465a9c2821ec6251b1b24ec052d7 100644 --- a/src/cmd/isula/extend/events.h +++ b/src/cmd/isula/extend/events.h @@ -17,18 +17,26 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define EVENTS_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_STRING, false, "name", 'n', &(cmdargs).name, \ "Name of the container", NULL }, \ { CMD_OPT_TYPE_STRING, false, "since", 'S', &(cmdargs).since, \ - "Show all events created since this timestamp", NULL }, \ + "Show all events created since this timestamp", NULL }, \ { CMD_OPT_TYPE_STRING, false, "until", 'U', &(cmdargs).until, \ - "Show all events created until this timestamp", NULL } + "Show all events created until this timestamp", NULL } extern const char g_cmd_events_desc[]; extern const char g_cmd_events_usage[]; extern struct client_arguments g_cmd_events_args; int cmd_events_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_EVENT_H */ diff --git a/src/cmd/isula/extend/export.h b/src/cmd/isula/extend/export.h index 5209504a7019b5a5bc80cfc2e4896782b09f3b4a..dada33f4e7c7613447a231b4b76525e7d059b51e 100644 --- a/src/cmd/isula/extend/export.h +++ b/src/cmd/isula/extend/export.h @@ -17,6 +17,10 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define EXPORT_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_STRING, false, "output", 'o', &(cmdargs).file, "Write to a file", NULL } @@ -25,5 +29,9 @@ extern const char g_cmd_export_usage[]; extern struct client_arguments g_cmd_export_args; int cmd_export_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/cmd/isula/extend/pause.h b/src/cmd/isula/extend/pause.h index 8b758072bcc8708a1adff7d4184319ea653eca2e..1facb0ee8459ab2feb8b4e2cea491d4b251f8873 100644 --- a/src/cmd/isula/extend/pause.h +++ b/src/cmd/isula/extend/pause.h @@ -17,10 +17,18 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + extern const char g_cmd_pause_desc[]; extern const char g_cmd_pause_usage[]; extern struct client_arguments g_cmd_pause_args; int cmd_pause_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/cmd/isula/extend/resume.h b/src/cmd/isula/extend/resume.h index 655b3fea9506f4f40b6f1ed0e672a9d9d842e420..1aff63483605ba6389c6fffb74cf1337f2fa9d57 100644 --- a/src/cmd/isula/extend/resume.h +++ b/src/cmd/isula/extend/resume.h @@ -17,10 +17,18 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + extern const char g_cmd_resume_desc[]; extern const char g_cmd_resume_usage[]; extern struct client_arguments g_cmd_resume_args; int cmd_resume_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/cmd/isula/extend/stats.h b/src/cmd/isula/extend/stats.h index 253511698aa0521fe4f78d051b81d408ffce87b0..5634d3b73f43544f07894842406267fbd190d994 100644 --- a/src/cmd/isula/extend/stats.h +++ b/src/cmd/isula/extend/stats.h @@ -17,16 +17,24 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define STATUS_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_BOOL, false, "all", 'a', &(cmdargs).showall, \ "Show all containers (default shows just running)", NULL }, \ { CMD_OPT_TYPE_BOOL, false, "no-stream", 0, &(cmdargs).nostream, \ - "Disable streaming stats and only pull the first result", NULL } + "Disable streaming stats and only pull the first result", NULL } extern const char g_cmd_stats_desc[]; extern const char g_cmd_stats_usage[]; extern struct client_arguments g_cmd_stats_args; int cmd_stats_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_STATS_H */ diff --git a/src/cmd/isula/extend/update.h b/src/cmd/isula/extend/update.h index 9628f04a3cacda5e3b4283f4c732e3eba177cec8..b026800aa62b134d13028e132083350b5ad21a9a 100644 --- a/src/cmd/isula/extend/update.h +++ b/src/cmd/isula/extend/update.h @@ -17,27 +17,31 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define UPDATE_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_CALLBACK, false, "cpu-shares", 0, &(cmdargs).cr.cpu_shares, \ "CPU shares (relative weight)", command_convert_llong }, \ { CMD_OPT_TYPE_CALLBACK, false, "cpu-period", 0, &(cmdargs).cr.cpu_period, \ - "Limit CPU CFS (Completely Fair Scheduler) period", command_convert_llong }, \ + "Limit CPU CFS (Completely Fair Scheduler) period", command_convert_llong }, \ { CMD_OPT_TYPE_CALLBACK, false, "cpu-quota", 0, &(cmdargs).cr.cpu_quota, \ - "Limit CPU CFS (Completely Fair Scheduler) quota", command_convert_llong }, \ + "Limit CPU CFS (Completely Fair Scheduler) quota", command_convert_llong }, \ { CMD_OPT_TYPE_STRING, false, "cpuset-cpus", 0, &(cmdargs).cr.cpuset_cpus, \ - "CPUs in which to allow execution (0-3, 0,1)", NULL }, \ + "CPUs in which to allow execution (0-3, 0,1)", NULL }, \ { CMD_OPT_TYPE_STRING, false, "cpuset-mems", 0, &(cmdargs).cr.cpuset_mems, \ - "MEMs in which to allow execution (0-3, 0,1)", NULL }, \ + "MEMs in which to allow execution (0-3, 0,1)", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "kernel-memory", 0, &(cmdargs).cr.kernel_memory_limit, \ - "Kernel memory limit", command_convert_membytes }, \ + "Kernel memory limit", command_convert_membytes }, \ { CMD_OPT_TYPE_CALLBACK, false, "memory", 'm', &(cmdargs).cr.memory_limit, \ - "Memory limit", command_convert_membytes }, \ + "Memory limit", command_convert_membytes }, \ { CMD_OPT_TYPE_CALLBACK, false, "memory-reservation", 0, &(cmdargs).cr.memory_reservation, \ - "Memory soft limit", command_convert_membytes }, \ + "Memory soft limit", command_convert_membytes }, \ { CMD_OPT_TYPE_CALLBACK, false, "memory-swap", 0, &(cmdargs).cr.memory_swap, \ - "Swap limit equal to memory plus swap: '-1' to enable unlimited swap", command_convert_memswapbytes }, \ + "Swap limit equal to memory plus swap: '-1' to enable unlimited swap", command_convert_memswapbytes }, \ { CMD_OPT_TYPE_STRING, false, "restart", 0, &(cmdargs).restart, \ - "Restart policy to apply when a container exits", NULL } + "Restart policy to apply when a container exits", NULL } extern const char g_cmd_update_desc[]; extern const char g_cmd_update_usage[]; @@ -45,5 +49,9 @@ extern struct client_arguments g_cmd_update_args; int cmd_update_main(int argc, const char **argv); int update_checker(const struct client_arguments *args); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_UPDATE_H */ diff --git a/src/cmd/isula/images/images.h b/src/cmd/isula/images/images.h index 5fd55ddd80f634fade2f1b04ae7469f576bd03fd..9e46bbedd6d75c044321a4dfe35b9d54b57959d1 100644 --- a/src/cmd/isula/images/images.h +++ b/src/cmd/isula/images/images.h @@ -17,10 +17,18 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + extern const char g_cmd_images_desc[]; extern const char g_cmd_images_usage[]; extern struct client_arguments g_cmd_images_args; int cmd_images_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_IMAGES_LIST_H */ diff --git a/src/cmd/isula/images/load.h b/src/cmd/isula/images/load.h index e6f5555d8356e45cca8cf245d7ce1bd1a9781480..372716b4b6e8ea4b0aecb3ba7e6e73c322014032 100644 --- a/src/cmd/isula/images/load.h +++ b/src/cmd/isula/images/load.h @@ -17,10 +17,14 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define LOAD_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_STRING, false, "input", 'i', &(cmdargs).file, "Read from a manifest or an archive", NULL }, \ { CMD_OPT_TYPE_STRING, false, "tag", 0, &(cmdargs).tag, \ - "Name and optionally a tag in the 'name:tag' format, valid if type is docker", NULL } + "Name and optionally a tag in the 'name:tag' format, valid if type is docker", NULL } #define EMBEDDED_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_STRING, false, "type", 't', &(cmdargs).type, "Image type, embedded or docker(default)", NULL } @@ -29,5 +33,9 @@ extern const char g_cmd_load_desc[]; extern struct client_arguments g_cmd_load_args; int cmd_load_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_LOAD_H */ diff --git a/src/cmd/isula/images/login.h b/src/cmd/isula/images/login.h index e50c28ebad1ff5a548dabea667780c72afbab0f3..d2503341ebf8d2b102219f334b157c11247c32e7 100644 --- a/src/cmd/isula/images/login.h +++ b/src/cmd/isula/images/login.h @@ -16,11 +16,15 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define LOGIN_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_STRING, false, "username", 'u', &(cmdargs).username, "Username", NULL }, \ { CMD_OPT_TYPE_STRING, false, "password", 'p', &(cmdargs).password, "Password", NULL }, \ { CMD_OPT_TYPE_BOOL, false, "password-stdin", 0, &(cmdargs).password_stdin, \ - "Take the password from stdin", NULL }, \ + "Take the password from stdin", NULL }, \ extern const char g_cmd_login_desc[]; @@ -28,5 +32,9 @@ extern const char g_cmd_login_usage[]; extern struct client_arguments g_cmd_login_args; int cmd_login_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_LOGIN_H */ diff --git a/src/cmd/isula/images/logout.h b/src/cmd/isula/images/logout.h index 7100f837cf2d93fca4a639579e08aec49f8ea135..d3ee77bae78c541af8bb6fe322f928327d4319fc 100644 --- a/src/cmd/isula/images/logout.h +++ b/src/cmd/isula/images/logout.h @@ -16,10 +16,18 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + extern const char g_cmd_logout_desc[]; extern const char g_cmd_logout_usage[]; extern struct client_arguments g_cmd_logout_args; int cmd_logout_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_LOGOUT_H */ diff --git a/src/cmd/isula/images/pull.h b/src/cmd/isula/images/pull.h index 728ec4ea9b9e69e216984af3fb6d7e1d24a8ff6c..3cab4e4b6ecb8a74d716fba51251960c6f8ea14f 100644 --- a/src/cmd/isula/images/pull.h +++ b/src/cmd/isula/images/pull.h @@ -18,6 +18,10 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + extern const char g_cmd_pull_desc[]; extern const char g_cmd_pull_usage[]; extern struct client_arguments g_cmd_pull_args; @@ -25,5 +29,9 @@ int client_pull(const struct client_arguments *args); int cmd_pull_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_PULL_IMAGE_H */ diff --git a/src/cmd/isula/images/rmi.h b/src/cmd/isula/images/rmi.h index bc8ec8018432e1a94452b53c179babba2fbd6a7b..d2962e7ab72f3331f9b5d15eb4c4199f58df235c 100644 --- a/src/cmd/isula/images/rmi.h +++ b/src/cmd/isula/images/rmi.h @@ -17,6 +17,10 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define RMI_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_BOOL, false, "force", 'f', &(cmdargs).force, "Force removal of the image", NULL } @@ -25,5 +29,9 @@ extern const char g_cmd_rmi_usage[]; extern struct client_arguments g_cmd_rmi_args; int cmd_rmi_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_REMOVE_IMAGE_H */ diff --git a/src/cmd/isula/information/health.h b/src/cmd/isula/information/health.h index e9d490881e0ecf588105375b5fa0abf1de688bbe..bc6919ae70a4f69b27dcc69c745d1adba47309eb 100644 --- a/src/cmd/isula/information/health.h +++ b/src/cmd/isula/information/health.h @@ -17,6 +17,10 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define HEALTH_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_STRING, false, "service", 'S', &(cmdargs).service, "GRPC service name", NULL } @@ -25,5 +29,9 @@ extern const char g_cmd_health_check_usage[]; extern struct client_arguments g_cmd_health_check_args; int cmd_health_check_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/cmd/isula/information/info.h b/src/cmd/isula/information/info.h index f358f9ddca9457be52c57107384fdbdf7b766ae1..19eb05583c22f4acead586e23b663960aada4a65 100644 --- a/src/cmd/isula/information/info.h +++ b/src/cmd/isula/information/info.h @@ -17,10 +17,18 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + extern const char g_cmd_info_desc[]; extern const char g_cmd_info_usage[]; extern struct client_arguments g_cmd_info_args; int cmd_info_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_INFO_H */ diff --git a/src/cmd/isula/information/inspect.h b/src/cmd/isula/information/inspect.h index c83d3ec1fbea5ee78c94bb062ba79b5b303faee2..dfe4252765fa0f2d1f91ced7383dffc53ed6a599 100644 --- a/src/cmd/isula/information/inspect.h +++ b/src/cmd/isula/information/inspect.h @@ -17,16 +17,24 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define INSPECT_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_STRING, false, "format", 'f', &(cmdargs).format, \ "Format the output using the given go template", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "time", 't', &(cmdargs).time, \ - "Seconds to wait for inspect timeout (default 120)", command_convert_int } + "Seconds to wait for inspect timeout (default 120)", command_convert_int } extern const char g_cmd_inspect_desc[]; extern const char g_cmd_inspect_usage[]; extern struct client_arguments g_cmd_inspect_args; int cmd_inspect_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_INSPECT_H */ diff --git a/src/cmd/isula/information/logs.h b/src/cmd/isula/information/logs.h index c92314bf10253fdd42c8839663145b21e25a0e26..dfcfb112ca8d59a969fac29b584340fe83295984 100644 --- a/src/cmd/isula/information/logs.h +++ b/src/cmd/isula/information/logs.h @@ -17,10 +17,14 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define LOGS_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_BOOL, false, "follow", 'f', &(cmdargs).follow, "Follow log output", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "tail", 0, &(cmdargs).tail, \ - "Number of lines to show from the end of the logs", callback_tail } + "Number of lines to show from the end of the logs", callback_tail } extern const char g_cmd_logs_desc[]; extern const char g_cmd_logs_usage[]; @@ -28,5 +32,10 @@ extern struct client_arguments g_cmd_logs_args; int callback_tail(command_option_t *option, const char *arg); int cmd_logs_main(int argc, const char **argv); + +#ifdef __cplusplus +} +#endif + #endif /* __CMD_LOGS_H */ diff --git a/src/cmd/isula/information/ps.h b/src/cmd/isula/information/ps.h index 65b77d00cef69c61940467dd5f834ed6c2e8ddff..1e76c6b97b0ee48bfc1bcd61d08fe8be05e0a5f3 100644 --- a/src/cmd/isula/information/ps.h +++ b/src/cmd/isula/information/ps.h @@ -17,21 +17,29 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + #define LIST_OPTIONS(cmdargs) \ { CMD_OPT_TYPE_BOOL, false, "all", 'a', &(cmdargs).list_all, \ "Display all containers (default shows just running)", NULL }, \ { CMD_OPT_TYPE_BOOL, false, "quiet", 'q', &(cmdargs).dispname, "Only display numeric IDs", NULL }, \ { CMD_OPT_TYPE_CALLBACK, false, "filter", 'f', &(cmdargs).filters, \ - "Filter output based on conditions provided", command_append_array }, \ + "Filter output based on conditions provided", command_append_array }, \ { CMD_OPT_TYPE_BOOL, false, "no-trunc", 0, &(cmdargs).no_trunc, \ - "Don't truncate output", NULL }, \ + "Don't truncate output", NULL }, \ { CMD_OPT_TYPE_STRING, false, "format", 0, &(cmdargs).format, \ - "Format the output using the given go template", NULL } + "Format the output using the given go template", NULL } extern const char g_cmd_list_desc[]; extern const char g_cmd_list_usage[]; extern struct client_arguments g_cmd_list_args; int cmd_list_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_LIST_H */ diff --git a/src/cmd/isula/information/top.h b/src/cmd/isula/information/top.h index f96d780e4ea3a0841c808b89686e7c6e13f2db35..6078195f815b1c1fc45539a42c70d5ff9653a32e 100644 --- a/src/cmd/isula/information/top.h +++ b/src/cmd/isula/information/top.h @@ -17,10 +17,18 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + extern const char g_cmd_top_desc[]; extern const char g_cmd_top_usage[]; extern struct client_arguments g_cmd_top_args; int cmd_top_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_TOP_H */ diff --git a/src/cmd/isula/information/version.h b/src/cmd/isula/information/version.h index e8bab52b471182c35d86692d9cbdaa6330d08c8e..be23446b8707094bc701dfe04a3da8cd15f5f980 100644 --- a/src/cmd/isula/information/version.h +++ b/src/cmd/isula/information/version.h @@ -17,10 +17,18 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + extern const char g_cmd_version_desc[]; extern const char g_cmd_version_usage[]; extern struct client_arguments g_cmd_version_args; int cmd_version_main(int argc, const char **argv); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_VERSION_H */ diff --git a/src/cmd/isula/information/wait.h b/src/cmd/isula/information/wait.h index b9f89c277ba3bc25e71a0397c62416ee4b8ed4f2..594d5381044308d6672ced795fe0205856bad3e1 100644 --- a/src/cmd/isula/information/wait.h +++ b/src/cmd/isula/information/wait.h @@ -17,11 +17,19 @@ #include "arguments.h" +#ifdef __cplusplus +extern "C" { +#endif + extern const char g_cmd_wait_desc[]; extern const char g_cmd_wait_usage[]; extern struct client_arguments g_cmd_wait_args; int cmd_wait_main(int argc, const char **argv); int client_wait(const struct client_arguments *args, unsigned int *exit_code); +#ifdef __cplusplus +} +#endif + #endif /* __CMD_WAIT_H */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index baea137e47a357f3e77ad6b003c39d1d5c1dfa9b..82c82bd7ea3cc6b0de281cf663e4d8332a2ffb33 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,9 +1,43 @@ project(iSulad_LLT) +function(gmock_find_library _name) + find_library(${_name} + NAMES ${ARGN} + HINTS + $ENV{GMOCK_ROOT} + ${GMOCK_ROOT} + ) + mark_as_advanced(${_name}) +endfunction() + +find_path(GMOCK_INCLUDE_DIR gmock/gmock.h + HINTS + $ENV{GMOCK_ROOT}/include + ${GMOCK_ROOT}/include +) +mark_as_advanced(GMOCK_INCLUDE_DIR) + +gmock_find_library(GMOCK_LIBRARY gmock) +gmock_find_library(GMOCK_LIBRARY_DEBUG gmockd) +gmock_find_library(GMOCK_MAIN_LIBRARY gmock_main) +gmock_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_maind) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMock DEFAULT_MSG GMOCK_LIBRARY GMOCK_INCLUDE_DIR GMOCK_MAIN_LIBRARY) + +if(GMOCK_FOUND) + set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIR}) + set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES}) +endif() + # setup testing find_package(Threads REQUIRED) find_package(GTest REQUIRED) +include_directories(${GTEST_INCLUDE_DIR}) +include_directories(${GMOCK_INCLUDE_DIRS}) + add_subdirectory(cutils) add_subdirectory(image) add_subdirectory(path) +add_subdirectory(cmd) diff --git a/test/cmd/CMakeLists.txt b/test/cmd/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..69a7c3d6ad230a6d888d91e06fef206a7dc9f811 --- /dev/null +++ b/test/cmd/CMakeLists.txt @@ -0,0 +1,3 @@ +project(iSulad_LLT) + +add_subdirectory(isula) diff --git a/test/cmd/isula/CMakeLists.txt b/test/cmd/isula/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..56952aebd212069540313a413d001d44bdda5325 --- /dev/null +++ b/test/cmd/isula/CMakeLists.txt @@ -0,0 +1,3 @@ +project(iSulad_LLT) + +add_subdirectory(infomation) diff --git a/test/cmd/isula/infomation/CMakeLists.txt b/test/cmd/isula/infomation/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0e186779fb0f74019bb0c3ee71670a0269dd953f --- /dev/null +++ b/test/cmd/isula/infomation/CMakeLists.txt @@ -0,0 +1,3 @@ +project(iSulad_LLT) + +add_subdirectory(ps) diff --git a/test/cmd/isula/infomation/ps/CMakeLists.txt b/test/cmd/isula/infomation/ps/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..31af7c5d399181ebf55b6a08b07895fa796bb4a9 --- /dev/null +++ b/test/cmd/isula/infomation/ps/CMakeLists.txt @@ -0,0 +1,54 @@ +project(iSulad_LLT) + +SET(EXE ps_llt) + +add_executable(${EXE} + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/log.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_string.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_array.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_file.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_convert.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_verify.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_regex.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/sha256/sha256.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/path.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cmd/commander.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/console/console.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cmd/isula/arguments.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/libisulad.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/libisula.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/types_def.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/mainloop.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/container_def.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/error.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/connect/client/isula_connect.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/json/schema/src/read_file.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cmd/isula/information/ps.c + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks/grpc_client_mock.cc + ${CMAKE_BINARY_DIR}/json/json_common.c + ${CMAKE_BINARY_DIR}/json/host_config.c + ${CMAKE_BINARY_DIR}/json/container_path_stat.c + ${CMAKE_BINARY_DIR}/json/timestamp.c + ps_llt.cc) + +target_include_directories(${EXE} PUBLIC + ${GTEST_INCLUDE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../include + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/json + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/sha256 + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/connect/client + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cmd + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/http + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/console + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cmd/isula + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cmd/isula/information + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/connect/client/grpc + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/json/schema/src + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../mocks + ${CMAKE_BINARY_DIR}/json + ${CMAKE_BINARY_DIR}/conf + ) +target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} -lgrpc++ -lprotobuf -lcrypto -lyajl -lsecurec -lz) diff --git a/test/cmd/isula/infomation/ps/ps_llt.cc b/test/cmd/isula/infomation/ps/ps_llt.cc new file mode 100644 index 0000000000000000000000000000000000000000..e5e863b9c79ec450e57d7e5cc1bf50489e21e95e --- /dev/null +++ b/test/cmd/isula/infomation/ps/ps_llt.cc @@ -0,0 +1,224 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2019-2020. All rights reserved. + * Description: ps llt + * Author: wujing + * Create: 2019-12-19 + */ +#include "ps.h" +#include +#include +#include +#include +#include +#include "grpc_client_mock.h" +#include "utils.h" + +using ::testing::Args; +using ::testing::ByRef; +using ::testing::SetArgPointee; +using ::testing::DoAll; +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::NotNull; +using ::testing::AtLeast; +using ::testing::Invoke; +using ::testing::_; + +using namespace std; + +class ContainerListUnitTest : public testing::Test { +public: + void SetUp() override + { + GrpcClient_SetMock(&m_grpcClient); + ::testing::Mock::AllowLeak(&m_grpcClient); + } + void TearDown() override + { + GrpcClient_SetMock(nullptr); + } + + NiceMock m_grpcClient; +}; + +namespace { +unsigned generate_random_pid() +{ + constexpr int pid_start = 10000; + constexpr int pid_end = 10000; + static default_random_engine e(time(0)); + static uniform_int_distribution u(pid_start, pid_end); + return u(e); +} + +long long generate_random_created() +{ + // unix nanos: 2019-01-01T00:00:00.000000000+08:00 + constexpr int64_t start = 1546272000000000000ll; + // unix nanos: 2019-12-31T00:00:00.000000000+08:00 + constexpr int64_t end = 1577721600000000000ll; + + static default_random_engine e(time(0)); + static uniform_int_distribution u(start, end); + return u(e); +} + +string generate_random_string(int length) +{ + static string chset = "abcdefghijklmnopqrstuvwxyz1234567890"; + string result; + result.resize(length); + + srand(time(NULL)); + for (int i = 0; i < length; i++) { + static default_random_engine e(time(0)); + static uniform_int_distribution u(0, chset.size() - 1); + result[i] = chset[u(e) % chset.length()]; + } + return result; +} + +int set_container_summary(struct isula_list_response *response, int index) +{ + constexpr int id_len = 64; + constexpr int name_len = 8; + + response->container_summary[index] = (struct isula_container_summary_info *)util_common_calloc_s( + sizeof(struct isula_container_summary_info)); + if (response->container_summary[index] == nullptr) { + return -1; + } + response->container_summary[index]->id = util_strdup_s(generate_random_string(id_len).c_str()); + response->container_summary[index]->name = util_strdup_s(generate_random_string(name_len).c_str()); + response->container_summary[index]->runtime = util_strdup_s("lcr"); + response->container_summary[index]->pid = generate_random_pid(); + response->container_summary[index]->status = (Container_Status)CONTAINER_STATUS_RUNNING; + response->container_summary[index]->image = util_strdup_s("busybox:latest"); + response->container_summary[index]->command = util_strdup_s("/bin/sh"); + response->container_summary[index]->startat = util_strdup_s("2019-12-31T23:55:50.867369507+08:00"); + response->container_summary[index]->finishat = util_strdup_s("2020-01-01T23:55:50.867369507+08:00"); + response->container_summary[index]->exit_code = 0; + response->container_summary[index]->restart_count = 0; + response->container_summary[index]->created = generate_random_created(); + response->container_summary[index]->health_state = util_strdup_s("(healthy)"); + response->container_num++; + + return 0; +} +} // namespace + +int ContainerList(const struct isula_list_request *request, + struct isula_list_response *response, void *arg) +{ + (void)request; + (void)arg; + constexpr int container_cnt = 5; + response->cc = 0; + response->server_errono = 0; + response->errmsg = nullptr; + response->container_summary = (struct isula_container_summary_info **)util_common_calloc_s( + sizeof(struct isula_container_summary_info *) * container_cnt); + if (response->container_summary == nullptr) { + return -1; + } + for (size_t i {}; i < container_cnt; ++i) { + if (set_container_summary(response, i)) { + return -1; + } + } + + return 0; +} + +int invokeGrpcOpsInit(isula_connect_ops *ops) +{ + if (ops == nullptr) { + return -1; + } + ops->container.list = &ContainerList; + return 0; +} + +TEST_F(ContainerListUnitTest, test_cmd_list_main_all) +{ + const char *argv[] = {"isula", "ps", "-a"}; + const char *argv_failure[] = {"isula", "ps", "-k"}; + isula_connect_ops ops; + + ops.container.list = &ContainerList; + EXPECT_CALL(m_grpcClient, GrpcOpsInit(_)) + .WillOnce(Return(-1)) + .WillOnce(DoAll(SetArgPointee<0>(ByRef(ops)), Return(0))); + ASSERT_EQ(connect_client_ops_init(), -1); + ASSERT_EQ(connect_client_ops_init(), 0); + EXPECT_EXIT(cmd_list_main(sizeof(argv) / sizeof(argv[0]), const_cast(argv)), + testing::ExitedWithCode(0), ""); + + EXPECT_CALL(m_grpcClient, GrpcOpsInit(_)).WillRepeatedly(Invoke(invokeGrpcOpsInit)); + ASSERT_EQ(connect_client_ops_init(), 0); + EXPECT_EXIT(cmd_list_main(sizeof(argv) / sizeof(argv[0]), const_cast(argv)), + testing::ExitedWithCode(0), ""); + EXPECT_EXIT(cmd_list_main(sizeof(argv_failure) / sizeof(argv_failure[0]), const_cast(argv_failure)), + testing::ExitedWithCode(125), "Unkown flag found"); + testing::Mock::VerifyAndClearExpectations(&m_grpcClient); +} + +TEST_F(ContainerListUnitTest, test_cmd_list_main_format) +{ + const char *argv[] = { + "isula", "ps", "-a", "--format", "\"table XXX{{.ID}}AAA{{.Image}}" + " {{.Status}} {{.Pid}} {{.Command}} {{.Created}} {{.Ports}} {{.ExitCode}} " + "{{.RestartCount}} {{.StartAt}} {{.FinishAt}} {{.Runtime}} \t{{.Names}} \n{{.State}}\"" + }; + const char *argv_failure[] = {"isula", "ps", "--format", "\"{{.ID}} {{.XXX}}"}; + + EXPECT_CALL(m_grpcClient, GrpcOpsInit(_)).WillRepeatedly(Invoke(invokeGrpcOpsInit)); + ASSERT_EQ(connect_client_ops_init(), 0); + EXPECT_EXIT(cmd_list_main(sizeof(argv) / sizeof(argv[0]), const_cast(argv)), + testing::ExitedWithCode(0), ""); + EXPECT_EXIT(cmd_list_main(sizeof(argv_failure) / sizeof(argv_failure[0]), const_cast(argv_failure)), + testing::ExitedWithCode(1), "not support the field"); + testing::Mock::VerifyAndClearExpectations(&m_grpcClient); +} + +TEST_F(ContainerListUnitTest, test_cmd_list_main_notrunc) +{ + const char *argv[] = {"isula", "ps", "-q", "--no-trunc"}; + testing::internal::CaptureStdout(); + + EXPECT_CALL(m_grpcClient, GrpcOpsInit(_)).WillRepeatedly(Invoke(invokeGrpcOpsInit)); + ASSERT_EQ(connect_client_ops_init(), 0); + EXPECT_EXIT(cmd_list_main(sizeof(argv) / sizeof(argv[0]), const_cast(argv)), + testing::ExitedWithCode(0), ""); + std::string output = testing::internal::GetCapturedStdout(); + if (output.find("CONTAINER ID") != std::string::npos) { + ADD_FAILURE() << "the output of command('isula ps -q --no-trunc') should not include table headers"; + } + std::cout << "Gtest Captured Stdout:" << std::endl << output; + testing::Mock::VerifyAndClearExpectations(&m_grpcClient); +} + +TEST_F(ContainerListUnitTest, test_cmd_list_main_debug) +{ + const char *argv[] = {"isula", "ps", "-a", "-D"}; + testing::internal::CaptureStdout(); + + EXPECT_CALL(m_grpcClient, GrpcOpsInit(_)).WillRepeatedly(Invoke(invokeGrpcOpsInit)); + ASSERT_EQ(connect_client_ops_init(), 0); + EXPECT_EXIT(cmd_list_main(sizeof(argv) / sizeof(argv[0]), const_cast(argv)), + testing::ExitedWithCode(0), ""); + std::string output = testing::internal::GetCapturedStdout(); + std::vector tableItems {"CONTAINER ID", "IMAGE", "COMMAND", "CREATED", "STATUS", "PORTS", "NAMES"}; + for (const auto &elem : tableItems) { + if (output.find(elem) == std::string::npos) { + ADD_FAILURE() << "container list info should include " << elem; + } + } + if (output.find("healthy") == std::string::npos) { + FAIL() << "container list info should include healthy"; + } + std::cout << "Gtest Captured Stdout:" << std::endl << output; + testing::Mock::VerifyAndClearExpectations(&m_grpcClient); + SUCCEED() << "test isula ps --debug success"; +} + diff --git a/test/mocks/grpc_client_mock.cc b/test/mocks/grpc_client_mock.cc new file mode 100644 index 0000000000000000000000000000000000000000..95502e9b0c9f92b998f688e4c9430afbc7792323 --- /dev/null +++ b/test/mocks/grpc_client_mock.cc @@ -0,0 +1,25 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. + * Description: grpc client mock + * Author: wujing + * Create: 2019-12-19 + */ +#include "grpc_client_mock.h" + +namespace { +MockGrpcClient *g_grpc_client_mock = NULL; +} + +void GrpcClient_SetMock(MockGrpcClient* mock) +{ + g_grpc_client_mock = mock; +} + +int grpc_ops_init(isula_connect_ops *ops) +{ + if (g_grpc_client_mock != nullptr) { + return g_grpc_client_mock->GrpcOpsInit(ops); + } + return 0; +} + diff --git a/test/mocks/grpc_client_mock.h b/test/mocks/grpc_client_mock.h new file mode 100644 index 0000000000000000000000000000000000000000..7fac8c47391913d8d0a0fb9adbe07cbedc3a8c7f --- /dev/null +++ b/test/mocks/grpc_client_mock.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. + * Description: grpc client mock + * Author: wujing + * Create: 2019-12-19 + */ + +#ifndef GRPC_CLIENT_MOCK_H_ +#define GRPC_CLIENT_MOCK_H_ + +#include +#include "grpc_client.h" + +class MockGrpcClient { +public: + virtual ~MockGrpcClient() = default; + MOCK_METHOD1(GrpcOpsInit, int(isula_connect_ops *ops)); +}; + +void GrpcClient_SetMock(MockGrpcClient* mock); + +#endif // GRPC_CLIENT_MOCK_H_