From 67b68ada1cb9ef6604dc0839f4610d57dca86306 Mon Sep 17 00:00:00 2001 From: changhan Date: Sat, 19 Apr 2025 14:39:02 +0000 Subject: [PATCH] libsemanage: simplify file deletion Signed-off-by: changhan --- ...t-libsemanage-simplify-file-deletion.patch | 63 +++++++++++++++++++ libsemanage.spec | 6 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 backport-libsemanage-simplify-file-deletion.patch diff --git a/backport-libsemanage-simplify-file-deletion.patch b/backport-libsemanage-simplify-file-deletion.patch new file mode 100644 index 0000000..2962082 --- /dev/null +++ b/backport-libsemanage-simplify-file-deletion.patch @@ -0,0 +1,63 @@ +From 46b6d4593fd0bf3286977a9fe7d48f849524543c Mon Sep 17 00:00:00 2001 +From: changhan +Date: Fri, 18 Apr 2025 16:43:48 +0800 +Subject: [PATCH] libsemanage-simplify-file-deletion + +Reference: https://github.com/SELinuxProject/selinux/commit/d3a5ae39bee42eac520a3d07f252251a2167a323 + +--- + src/direct_api.c | 24 +++++++++--------------- + 1 file changed, 9 insertions(+), 15 deletions(-) + +diff --git a/src/direct_api.c b/src/direct_api.c +index 025b26e..03fc6ad 100644 +--- a/src/direct_api.c ++++ b/src/direct_api.c +@@ -2738,7 +2738,6 @@ static int semanage_direct_install_info(semanage_handle_t *sh, + int status = 0; + int ret = 0; + int type; +- struct stat sb; + + char path[PATH_MAX]; + mode_t mask = umask(0077); +@@ -2839,13 +2838,11 @@ static int semanage_direct_install_info(semanage_handle_t *sh, + goto cleanup; + } + +- if (stat(path, &sb) == 0) { +- ret = unlink(path); +- if (ret != 0) { +- ERR(sh, "Error while removing cached CIL file %s.", path); +- status = -3; +- goto cleanup; +- } ++ ret = unlink(path); ++ if (ret != 0 && errno != ENOENT) { ++ ERR(sh, "Error while removing cached CIL file %s.", path); ++ status = -3; ++ goto cleanup; + } + } + +@@ -2942,13 +2939,10 @@ static int semanage_direct_remove_key(semanage_handle_t *sh, + goto cleanup; + } + +- struct stat sb; +- if (stat(path, &sb) == 0) { +- ret = unlink(path); +- if (ret != 0) { +- status = -1; +- goto cleanup; +- } ++ ret = unlink(path); ++ if (ret != 0 && errno != ENOENT) { ++ status = -1; ++ goto cleanup; + } + } + else { +-- +2.33.0 + diff --git a/libsemanage.spec b/libsemanage.spec index ce417e5..660f173 100644 --- a/libsemanage.spec +++ b/libsemanage.spec @@ -3,7 +3,7 @@ Name: libsemanage Version: 3.5 -Release: 4 +Release: 5 License: LGPLv2+ Summary: SELinux binary policy manipulation library URL: https://github.com/SELinuxProject/selinux/wiki @@ -23,6 +23,7 @@ Patch6009: backport-libsemanage-check-closing-written-files.patch Patch6010: backport-libsemanage-handle-cil_set_handle_unknown-failure.patch Patch6011: backport-libsemanage-handle-shell-allocation-failure.patch Patch6012: backport-libsemanage-drop-duplicate-newlines-and-error-descriptions-in-error-messages.patch +Patch6013: backport-libsemanage-simplify-file-deletion.patch Patch9000: fix-test-failure-with-secilc.patch @@ -118,6 +119,9 @@ make test %changelog +* Sat Apr 19 2025 changhan - 3.5-5 +- backport libsemanage: simplify file deletion + * Fri Apr 18 2025 changhan - 3.5-4 - backport libsemanage: drop duplicate newlines and error descriptions in error messages -- Gitee