1 Star 0 Fork 98

Mingtai/systemd_1

forked from src-openEuler/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-devnode-acl-use-_cleanup_-to-free-acl_t.patch 4.57 KB
一键复制 编辑 原始数据 按行查看 历史
From 541ada330879dd928b33b55f1fc437ec1bbd349f Mon Sep 17 00:00:00 2001
From: David Tardon <dtardon@redhat.com>
Date: Thu, 3 Mar 2022 15:58:24 +0100
Subject: [PATCH] devnode-acl: use _cleanup_ to free acl_t
(cherry picked from commit 203ea2c8f158288fea56c5be980715b2b7e002fe)
(cherry picked from commit 543c73300e3b9298e5316555bf4df6ff7dfc210f)
Conflict:NA
Reference:https://github.com/systemd/systemd/commit/541ada330879dd928b33b55f1fc437ec1bbd349f
---
src/shared/devnode-acl.c | 73 ++++++++++++++--------------------------
1 file changed, 25 insertions(+), 48 deletions(-)
diff --git a/src/shared/devnode-acl.c b/src/shared/devnode-acl.c
index 07e29e1019..394422b164 100644
--- a/src/shared/devnode-acl.c
+++ b/src/shared/devnode-acl.c
@@ -52,8 +52,8 @@ int devnode_acl(const char *path,
bool del, uid_t old_uid,
bool add, uid_t new_uid) {
- acl_t acl;
- int r = 0;
+ _cleanup_(acl_freep) acl_t acl = NULL;
+ int r;
bool changed = false;
assert(path);
@@ -66,7 +66,7 @@ int devnode_acl(const char *path,
r = flush_acl(acl);
if (r < 0)
- goto finish;
+ return r;
if (r > 0)
changed = true;
@@ -75,13 +75,11 @@ int devnode_acl(const char *path,
r = acl_find_uid(acl, old_uid, &entry);
if (r < 0)
- goto finish;
+ return r;
if (r > 0) {
- if (acl_delete_entry(acl, entry) < 0) {
- r = -errno;
- goto finish;
- }
+ if (acl_delete_entry(acl, entry) < 0)
+ return -errno;
changed = true;
}
@@ -94,68 +92,47 @@ int devnode_acl(const char *path,
r = acl_find_uid(acl, new_uid, &entry);
if (r < 0)
- goto finish;
+ return r;
if (r == 0) {
- if (acl_create_entry(&acl, &entry) < 0) {
- r = -errno;
- goto finish;
- }
+ if (acl_create_entry(&acl, &entry) < 0)
+ return -errno;
if (acl_set_tag_type(entry, ACL_USER) < 0 ||
- acl_set_qualifier(entry, &new_uid) < 0) {
- r = -errno;
- goto finish;
- }
+ acl_set_qualifier(entry, &new_uid) < 0)
+ return -errno;
}
- if (acl_get_permset(entry, &permset) < 0) {
- r = -errno;
- goto finish;
- }
+ if (acl_get_permset(entry, &permset) < 0)
+ return -errno;
rd = acl_get_perm(permset, ACL_READ);
- if (rd < 0) {
- r = -errno;
- goto finish;
- }
+ if (rd < 0)
+ return -errno;
wt = acl_get_perm(permset, ACL_WRITE);
- if (wt < 0) {
- r = -errno;
- goto finish;
- }
+ if (wt < 0)
+ return -errno;
if (!rd || !wt) {
- if (acl_add_perm(permset, ACL_READ|ACL_WRITE) < 0) {
- r = -errno;
- goto finish;
- }
+ if (acl_add_perm(permset, ACL_READ|ACL_WRITE) < 0)
+ return -errno;
changed = true;
}
}
if (!changed)
- goto finish;
-
- if (acl_calc_mask(&acl) < 0) {
- r = -errno;
- goto finish;
- }
-
- if (acl_set_file(path, ACL_TYPE_ACCESS, acl) < 0) {
- r = -errno;
- goto finish;
- }
+ return 0;
- r = 0;
+ if (acl_calc_mask(&acl) < 0)
+ return -errno;
-finish:
- acl_free(acl);
+ if (acl_set_file(path, ACL_TYPE_ACCESS, acl) < 0)
+ return -errno;
- return r;
+ return 0;
}
int devnode_acl_all(const char *seat,
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangmingtaip/systemd_1.git
git@gitee.com:yangmingtaip/systemd_1.git
yangmingtaip
systemd_1
systemd_1
master

搜索帮助