163 lines
4.8 KiB
Diff
163 lines
4.8 KiB
Diff
From b1ef723b4f437aad3c0c0497174bc7d3444426cd Mon Sep 17 00:00:00 2001
|
|
From: wujing <wujing50@huawei.com>
|
|
Date: Mon, 20 Jul 2020 15:30:42 +0800
|
|
Subject: [PATCH 4/9] Removes the definition of the thread attributes object
|
|
|
|
Signed-off-by: wujing <wujing50@huawei.com>
|
|
---
|
|
src/lxc/attach.c | 1 +
|
|
src/lxc/conf.c | 1 +
|
|
src/lxc/lsm/selinux.c | 33 +++++++++++----------------------
|
|
src/lxc/start.c | 1 +
|
|
4 files changed, 14 insertions(+), 22 deletions(-)
|
|
|
|
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
|
|
index 068cc5f8e..b33ff6325 100644
|
|
--- a/src/lxc/attach.c
|
|
+++ b/src/lxc/attach.c
|
|
@@ -1188,6 +1188,7 @@ static int create_attach_timeout_thread(int64_t attach_timeout, pid_t pid)
|
|
pthread_attr_init(&attr);
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
ret = pthread_create(&ptid, &attr, wait_attach_timeout, timeout_conf);
|
|
+ pthread_attr_destroy(&attr);
|
|
if (ret != 0) {
|
|
ERROR("Create attach wait timeout thread failed");
|
|
free(timeout_conf);
|
|
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
|
|
index 7e4af0a95..6a25b96ac 100644
|
|
--- a/src/lxc/conf.c
|
|
+++ b/src/lxc/conf.c
|
|
@@ -4660,6 +4660,7 @@ static int run_ocihook_buffer(struct oci_hook_conf *oconf, const char *inmsg)
|
|
pthread_attr_init(&attr);
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
err = pthread_create(&ptid, &attr, wait_ocihook_timeout, conf);
|
|
+ pthread_attr_destroy(&attr);
|
|
if (err != 0) {
|
|
ERROR("Create wait timeout thread failed");
|
|
free(conf);
|
|
diff --git a/src/lxc/lsm/selinux.c b/src/lxc/lsm/selinux.c
|
|
index 864b16be7..ceac08891 100644
|
|
--- a/src/lxc/lsm/selinux.c
|
|
+++ b/src/lxc/lsm/selinux.c
|
|
@@ -100,8 +100,6 @@ static int selinux_process_label_set(const char *inlabel, struct lxc_conf *conf,
|
|
*/
|
|
static int selinux_file_label_set(const char *path, const char *label)
|
|
{
|
|
- int ret;
|
|
-
|
|
if (path == NULL || label == NULL || strcmp(label, "unconfined_t") == 0) {
|
|
return 0;
|
|
}
|
|
@@ -110,8 +108,7 @@ static int selinux_file_label_set(const char *path, const char *label)
|
|
return 0;
|
|
}
|
|
|
|
- ret = lsetfilecon(path, label);
|
|
- if (ret != 0) {
|
|
+ if (lsetfilecon(path, label) != 0) {
|
|
SYSERROR("Failed to setSELinux context to \"%s\": %s", label, path);
|
|
return -1;
|
|
}
|
|
@@ -176,7 +173,7 @@ static int bad_prefix(const char *fpath)
|
|
static int recurse_set_file_label(const char *basePath, const char *label)
|
|
{
|
|
int ret = 0;
|
|
- DIR *dir = NULL;
|
|
+ __do_closedir DIR *dir = NULL;
|
|
struct dirent *ptr = NULL;
|
|
char base[PATH_MAX] = { 0 };
|
|
|
|
@@ -188,7 +185,7 @@ static int recurse_set_file_label(const char *basePath, const char *label)
|
|
ret = lsetfilecon(basePath, label);
|
|
if (ret != 0) {
|
|
ERROR("Failed to set file label");
|
|
- goto out;
|
|
+ return ret;
|
|
}
|
|
|
|
while ((ptr = readdir(dir)) != NULL) {
|
|
@@ -198,28 +195,25 @@ static int recurse_set_file_label(const char *basePath, const char *label)
|
|
int nret = snprintf(base, sizeof(base), "%s/%s", basePath, ptr->d_name);
|
|
if (nret < 0 || nret >= sizeof(base)) {
|
|
ERROR("Failed to get path");
|
|
- ret = -1;
|
|
- goto out;
|
|
+ return -1;
|
|
}
|
|
if (ptr->d_type == DT_DIR) {
|
|
ret = recurse_set_file_label(base, label);
|
|
if (ret != 0) {
|
|
ERROR("Failed to set dir label");
|
|
- goto out;
|
|
+ return ret;
|
|
}
|
|
} else {
|
|
ret = lsetfilecon(base, label);
|
|
if (ret != 0) {
|
|
ERROR("Failed to set file label");
|
|
- goto out;
|
|
+ return ret;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
-out:
|
|
- closedir(dir);
|
|
- return ret;
|
|
+ return 0;
|
|
}
|
|
|
|
/*
|
|
@@ -277,8 +271,7 @@ static int selinux_chcon(const char *fpath, const char *label, bool recurse)
|
|
*/
|
|
static int selinux_relabel(const char *path, const char *label, bool shared)
|
|
{
|
|
- int ret = 0;
|
|
- char *tmp_file_label = NULL;
|
|
+ __do_free char *tmp_file_label = NULL;
|
|
|
|
if (label == NULL) {
|
|
return 0;
|
|
@@ -291,8 +284,7 @@ static int selinux_relabel(const char *path, const char *label, bool shared)
|
|
tmp_file_label = strdup(label);
|
|
if (is_exclude_relabel_path(path)) {
|
|
ERROR("SELinux relabeling of %s is not allowed", path);
|
|
- ret = -1;
|
|
- goto out;
|
|
+ return -1;
|
|
}
|
|
|
|
if (shared) {
|
|
@@ -305,13 +297,10 @@ static int selinux_relabel(const char *path, const char *label, bool shared)
|
|
|
|
if (selinux_chcon(path, tmp_file_label, true) != 0) {
|
|
ERROR("Failed to modify %s's selinux context: %s", path, tmp_file_label);
|
|
- ret = -1;
|
|
- goto out;
|
|
+ return -1;
|
|
}
|
|
|
|
-out:
|
|
- free(tmp_file_label);
|
|
- return ret;
|
|
+ return 0;
|
|
}
|
|
|
|
#endif
|
|
diff --git a/src/lxc/start.c b/src/lxc/start.c
|
|
index 51d13254b..ab47420f1 100644
|
|
--- a/src/lxc/start.c
|
|
+++ b/src/lxc/start.c
|
|
@@ -2484,6 +2484,7 @@ static int create_start_timeout_thread(struct lxc_conf *conf, unsigned int start
|
|
pthread_attr_init(&attr);
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
ret = pthread_create(&ptid, &attr, wait_start_timeout, timeout_conf);
|
|
+ pthread_attr_destroy(&attr);
|
|
if (ret != 0) {
|
|
ERROR("Create start wait timeout thread failed");
|
|
free(timeout_conf);
|
|
--
|
|
2.25.1
|
|
|