URL: https://github.com/SSSD/sssd/pull/5758
Author: alexey-tikhonov
 Title: #5758: file utils: reduce log level in remove_tree_with_ctx()
Action: opened

PR body:
"""
Users of this function are responsible to decide if fail is critical.
"""

To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/5758/head:pr5758
git checkout pr5758
From 7cc584917e1e512305de77f1a3b111fd77920284 Mon Sep 17 00:00:00 2001
From: Alexey Tikhonov <atikh...@redhat.com>
Date: Mon, 23 Aug 2021 15:34:33 +0200
Subject: [PATCH] file utils: reduce log level in remove_tree_with_ctx() Users
 of this function are responsible to decide if fail is critical.

---
 src/util/files.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/util/files.c b/src/util/files.c
index 6c57359082..5b7fbc8c38 100644
--- a/src/util/files.c
+++ b/src/util/files.c
@@ -185,12 +185,18 @@ static int remove_tree_with_ctx(TALLOC_CTX *mem_ctx,
     DIR *rootdir = NULL;
     int ret, err;
     int dir_fd;
+    int log_level;
 
     dir_fd = sss_openat_cloexec(parent_fd, dir_name,
                             O_RDONLY | O_DIRECTORY | O_NOFOLLOW, &ret);
     if (dir_fd == -1) {
         ret = errno;
-        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot open %s: [%d]: %s\n",
+        if (ret == ENOENT) {
+            log_level = SSSDBG_TRACE_FUNC;
+        } else {
+            log_level = SSSDBG_MINOR_FAILURE;
+        }
+        DEBUG(log_level, "Cannot open %s: [%d]: %s\n",
               dir_name, ret, strerror(ret));
         return ret;
     }
@@ -198,7 +204,7 @@ static int remove_tree_with_ctx(TALLOC_CTX *mem_ctx,
     rootdir = fdopendir(dir_fd);
     if (rootdir == NULL) {
         ret = errno;
-        DEBUG(SSSDBG_CRIT_FAILURE,
+        DEBUG(SSSDBG_MINOR_FAILURE,
               "Cannot open directory: [%d][%s]\n", ret, strerror(ret));
         close(dir_fd);
         goto fail;
@@ -214,7 +220,7 @@ static int remove_tree_with_ctx(TALLOC_CTX *mem_ctx,
                       &statres, AT_SYMLINK_NOFOLLOW);
         if (ret != 0) {
             ret = errno;
-            DEBUG(SSSDBG_CRIT_FAILURE,
+            DEBUG(SSSDBG_MINOR_FAILURE,
                   "stat failed: [%d][%s]\n", ret, strerror(ret));
             goto fail;
         }
@@ -222,7 +228,7 @@ static int remove_tree_with_ctx(TALLOC_CTX *mem_ctx,
         if (S_ISDIR(statres.st_mode)) {
             /* if directory, recursively descend, but check if on the same FS */
             if (parent_dev && parent_dev != statres.st_dev) {
-                DEBUG(SSSDBG_CRIT_FAILURE,
+                DEBUG(SSSDBG_MINOR_FAILURE,
                       "Directory %s is on different filesystem, "
                        "will not follow\n", result->d_name);
                 ret = EFAULT;
@@ -232,7 +238,7 @@ static int remove_tree_with_ctx(TALLOC_CTX *mem_ctx,
             ret = remove_tree_with_ctx(mem_ctx, dir_fd, result->d_name,
                                        statres.st_dev, false);
             if (ret != EOK) {
-                DEBUG(SSSDBG_CRIT_FAILURE,
+                DEBUG(SSSDBG_MINOR_FAILURE,
                       "Removing subdirectory failed: [%d][%s]\n",
                        ret, strerror(ret));
                 goto fail;
@@ -241,7 +247,7 @@ static int remove_tree_with_ctx(TALLOC_CTX *mem_ctx,
             ret = unlinkat(dir_fd, result->d_name, 0);
             if (ret != 0) {
                 ret = errno;
-                DEBUG(SSSDBG_CRIT_FAILURE,
+                DEBUG(SSSDBG_MINOR_FAILURE,
                       "Removing file failed '%s': [%d][%s]\n",
                       result->d_name, ret, strerror(ret));
                 goto fail;
@@ -269,7 +275,7 @@ static int remove_tree_with_ctx(TALLOC_CTX *mem_ctx,
     if (rootdir) {  /* clean up on abnormal exit but retain return code */
         err = closedir(rootdir);
         if (err) {
-            DEBUG(SSSDBG_CRIT_FAILURE, "closedir failed, bad dirp?\n");
+            DEBUG(SSSDBG_MINOR_FAILURE, "closedir failed, bad dirp?\n");
         }
     }
     return ret;
_______________________________________________
sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org
To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/sssd-devel@lists.fedorahosted.org
Do not reply to spam on the list, report it: 
https://pagure.io/fedora-infrastructure

Reply via email to