156 lines
6.4 KiB
Diff
156 lines
6.4 KiB
Diff
From b51181f15bab3db7e4391b8eccad047221947baa Mon Sep 17 00:00:00 2001
|
|
From: LiFeng <lifeng68@huawei.com>
|
|
Date: Thu, 4 Jul 2019 05:10:00 -0400
|
|
Subject: [PATCH 114/140] lxc: fix code errors
|
|
|
|
Signed-off-by: LiFeng <lifeng68@huawei.com>
|
|
---
|
|
src/lxc/attach.c | 14 +++++---------
|
|
src/lxc/conf.c | 11 ++++++-----
|
|
src/lxc/confile.c | 8 ++------
|
|
src/lxc/terminal.c | 6 ++----
|
|
4 files changed, 15 insertions(+), 24 deletions(-)
|
|
|
|
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
|
|
index ac4bd39..1f14eb4 100644
|
|
--- a/src/lxc/attach.c
|
|
+++ b/src/lxc/attach.c
|
|
@@ -841,7 +841,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
|
|
}
|
|
|
|
/* isulad: set workdir */
|
|
- if (init_ctx && init_ctx->container && init_ctx->container->lxc_conf && init_ctx->container->lxc_conf->init_cwd) {
|
|
+ if (init_ctx->container->lxc_conf->init_cwd) {
|
|
char *init_cwd;
|
|
init_cwd = init_ctx->container->lxc_conf->init_cwd;
|
|
/* try to create workdir if not exist */
|
|
@@ -933,8 +933,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
|
|
goto on_error;
|
|
}
|
|
|
|
- if ((init_ctx->container && init_ctx->container->lxc_conf &&
|
|
- init_ctx->container->lxc_conf->no_new_privs) ||
|
|
+ if ((init_ctx->container->lxc_conf->no_new_privs) ||
|
|
(options->attach_flags & LXC_ATTACH_NO_NEW_PRIVS)) {
|
|
ret = prctl(PR_SET_NO_NEW_PRIVS, prctl_arg(1), prctl_arg(0),
|
|
prctl_arg(0), prctl_arg(0));
|
|
@@ -958,8 +957,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
|
|
TRACE("Set %s LSM label to \"%s\"", lsm_name(), init_ctx->lsm_label);
|
|
}
|
|
|
|
- if (init_ctx->container && init_ctx->container->lxc_conf &&
|
|
- init_ctx->container->lxc_conf->seccomp) {
|
|
+ if (init_ctx->container->lxc_conf->seccomp) {
|
|
ret = lxc_seccomp_load(init_ctx->container->lxc_conf);
|
|
if (ret < 0)
|
|
goto on_error;
|
|
@@ -1028,8 +1026,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
|
|
goto on_error;
|
|
}
|
|
|
|
- if (init_ctx->container && init_ctx->container->lxc_conf &&
|
|
- !lxc_setgroups(init_ctx->container->lxc_conf->init_groups_len,
|
|
+ if (!lxc_setgroups(init_ctx->container->lxc_conf->init_groups_len,
|
|
init_ctx->container->lxc_conf->init_groups))
|
|
goto on_error;
|
|
|
|
@@ -1041,8 +1038,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
|
|
goto on_error;
|
|
}
|
|
|
|
- if (init_ctx->container && init_ctx->container->lxc_conf &&
|
|
- lxc_drop_caps(init_ctx->container->lxc_conf) != 0) {
|
|
+ if (lxc_drop_caps(init_ctx->container->lxc_conf) != 0) {
|
|
ERROR("Failed to drop caps.");
|
|
goto on_error;
|
|
}
|
|
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
|
|
index 3ecccbd..e22e13e 100644
|
|
--- a/src/lxc/conf.c
|
|
+++ b/src/lxc/conf.c
|
|
@@ -4790,6 +4790,7 @@ static int run_ocihook_buffer(struct oci_hook_conf *oconf, const char *inmsg)
|
|
err = pthread_create(&ptid, &attr, wait_ocihook_timeout, conf);
|
|
if (err != 0) {
|
|
ERROR("Create wait timeout thread failed");
|
|
+ free(conf);
|
|
goto on_error;
|
|
}
|
|
|
|
@@ -4804,17 +4805,17 @@ static int run_ocihook_buffer(struct oci_hook_conf *oconf, const char *inmsg)
|
|
goto print_hook;
|
|
} else if (WIFEXITED(ret) && WEXITSTATUS(ret) != 0) {
|
|
ERROR("Script exited with status %d. output: %s", WEXITSTATUS(ret), output);
|
|
- lxc_write_error_message(conf->errfd, "%s:%d: running %s hook caused \"error running hook: exit status %d, output: %s\".",
|
|
+ lxc_write_error_message(oconf->errfd, "%s:%d: running %s hook caused \"error running hook: exit status %d, output: %s\".",
|
|
__FILE__, __LINE__,
|
|
- (conf->which >= NUM_LXC_HOOKS) ? "invalid type" : lxchook_names[conf->which],
|
|
+ (oconf->which >= NUM_LXC_HOOKS) ? "invalid type" : lxchook_names[oconf->which],
|
|
WEXITSTATUS(ret), output);
|
|
|
|
goto print_hook;
|
|
} else if (WIFSIGNALED(ret)) {
|
|
ERROR("Script terminated by signal %d.", WTERMSIG(ret));
|
|
- lxc_write_error_message(conf->errfd, "%s:%d: running %s hook caused \"error running hook: Script terminated by signal %d\".",
|
|
+ lxc_write_error_message(oconf->errfd, "%s:%d: running %s hook caused \"error running hook: Script terminated by signal %d\".",
|
|
__FILE__, __LINE__,
|
|
- (conf->which >= NUM_LXC_HOOKS) ? "invalid type" : lxchook_names[conf->which],
|
|
+ (oconf->which >= NUM_LXC_HOOKS) ? "invalid type" : lxchook_names[oconf->which],
|
|
WTERMSIG(ret));
|
|
|
|
goto print_hook;
|
|
@@ -4836,7 +4837,7 @@ print_hook:
|
|
err_envs_msg = lxc_string_join(" ", (const char **)oconf->ocihook->env, false);
|
|
ERROR("Hook script command: \"%s\", args: \"%s\", envs: \"%s\", timeout: %d.",
|
|
buffer, err_args_msg ? err_args_msg : "",
|
|
- err_envs_msg ? err_envs_msg : "", conf->timeout);
|
|
+ err_envs_msg ? err_envs_msg : "", oconf->ocihook->timeout);
|
|
|
|
free(err_args_msg);
|
|
free(err_envs_msg);
|
|
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
|
|
index a75e023..0537ebc 100644
|
|
--- a/src/lxc/confile.c
|
|
+++ b/src/lxc/confile.c
|
|
@@ -3828,9 +3828,7 @@ static int get_config_prlimit(const char *key, char *retv, int inlen,
|
|
struct lxc_limit *lim = it->elem;
|
|
|
|
if (lim->limit.rlim_cur == RLIM_INFINITY) {
|
|
- if (memcpy(buf, "unlimited", STRLITERALLEN("unlimited") + 1) == NULL) {
|
|
- return -1;
|
|
- }
|
|
+ (void)memcpy(buf, "unlimited", STRLITERALLEN("unlimited") + 1);
|
|
partlen = STRLITERALLEN("unlimited");
|
|
} else {
|
|
partlen = snprintf(buf, MAX_LIMIT_BUF_LEN, "%" PRIu64, (uint64_t)lim->limit.rlim_cur);
|
|
@@ -3841,9 +3839,7 @@ static int get_config_prlimit(const char *key, char *retv, int inlen,
|
|
|
|
if (lim->limit.rlim_cur != lim->limit.rlim_max) {
|
|
if (lim->limit.rlim_max == RLIM_INFINITY) {
|
|
- if (memcpy(buf + partlen, ":unlimited", STRLITERALLEN(":unlimited") + 1) == NULL) {
|
|
- return -1;
|
|
- }
|
|
+ (void)memcpy(buf + partlen, ":unlimited", STRLITERALLEN(":unlimited") + 1);
|
|
} else {
|
|
nret = snprintf(buf + partlen, (MAX_LIMIT_BUF_LEN - partlen), ":%" PRIu64, (uint64_t)lim->limit.rlim_max);
|
|
if (nret < 0) {
|
|
diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c
|
|
index 1fee651..32c69a4 100644
|
|
--- a/src/lxc/terminal.c
|
|
+++ b/src/lxc/terminal.c
|
|
@@ -289,10 +289,8 @@ static int lxc_terminal_rotate_log_file(struct lxc_terminal *terminal)
|
|
ERROR("Out of memory");
|
|
return -1;
|
|
}
|
|
- if (memset(tmp, 0, len) != NULL) {
|
|
- ERROR("Memset failed");
|
|
- goto free_out;
|
|
- }
|
|
+
|
|
+ (void)memset(tmp, 0, len);
|
|
|
|
ret = snprintf(tmp, len, "%s.1", terminal->log_path);
|
|
if (ret < 0 || (size_t)ret >= len) {
|
|
--
|
|
1.8.3.1
|
|
|