Blob Blame History Raw
From ce5063550ef45f7abb3ec2ec3cb52a190bb38af5 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn@redhat.com>
Date: Mon, 25 Jul 2016 09:11:08 +0200
Subject: [PATCH 36/44] Amend debug messages after failure of unlink
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Some messages did not have errno or name of problematic file.
There was also improper use of negative value.
The function strerror was called with -1 instead of errno

Reviewed-by: Petr Čech <pcech@redhat.com>
---
 src/providers/ipa/ipa_init.c            | 5 +++--
 src/responder/common/responder_common.c | 3 ++-
 src/responder/secrets/local.c           | 1 +
 src/sbus/sssd_dbus_server.c             | 9 +++++----
 src/tools/files.c                       | 3 ++-
 src/tools/tools_mc_util.c               | 7 ++++---
 src/util/util.c                         | 6 ++++--
 7 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/providers/ipa/ipa_init.c b/src/providers/ipa/ipa_init.c
index 959cdb4a7c40c1be03dd1e7c66dee6e65ca76607..c31e195f48b2f369de1b78b38a0f3522d73d8dce 100644
--- a/src/providers/ipa/ipa_init.c
+++ b/src/providers/ipa/ipa_init.c
@@ -440,9 +440,10 @@ static void cleanup_ipa_preauth_indicator(void)
 
     ret = unlink(PAM_PREAUTH_INDICATOR);
     if (ret != EOK) {
+        ret = errno;
         DEBUG(SSSDBG_OP_FAILURE,
-              "Failed to remove preauth indicator file [%s].\n",
-              PAM_PREAUTH_INDICATOR);
+              "Failed to remove preauth indicator file [%s] %d [%s].\n",
+              PAM_PREAUTH_INDICATOR, ret, sss_strerror(ret));
     }
 }
 
diff --git a/src/responder/common/responder_common.c b/src/responder/common/responder_common.c
index 02a64368cad60990436497865aa0c772a39cde5a..7f6264ae70e5073063b5cfcd73098eefad2ce653 100644
--- a/src/responder/common/responder_common.c
+++ b/src/responder/common/responder_common.c
@@ -629,7 +629,8 @@ int create_pipe_fd(const char *sock_name, int *_fd, mode_t umaskval)
     if (ret != 0 && errno != ENOENT) {
         ret = errno;
         DEBUG(SSSDBG_MINOR_FAILURE,
-              "Cannot remove old socket (errno=%d), bind might fail!\n", ret);
+              "Cannot remove old socket (errno=%d [%s]), bind might fail!\n",
+              ret, sss_strerror(ret));
     }
 
     if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
diff --git a/src/responder/secrets/local.c b/src/responder/secrets/local.c
index 2a85ac06945322265fbd1012c9697728c37b77a0..470aec0e195a54dd2af2b929ff1b7a304331a214 100644
--- a/src/responder/secrets/local.c
+++ b/src/responder/secrets/local.c
@@ -627,6 +627,7 @@ int generate_master_key(const char *filename, size_t size)
         ret = unlink(filename);
         /* non-fatal failure */
         if (ret != EOK) {
+            ret = errno;
             DEBUG(SSSDBG_MINOR_FAILURE,
                   "Failed to remove file: %s - %d [%s]!\n",
                   filename, ret, sss_strerror(ret));
diff --git a/src/sbus/sssd_dbus_server.c b/src/sbus/sssd_dbus_server.c
index 0a1cace415b3514a6904e92a2d879538ce51a593..6cc4172a07118ff99bb6f122c3a1de25cee18c8c 100644
--- a/src/sbus/sssd_dbus_server.c
+++ b/src/sbus/sssd_dbus_server.c
@@ -103,8 +103,9 @@ create_socket_symlink(const char *filename, const char *symlink_filename)
         ret = unlink(symlink_filename);
         if (ret != 0) {
             ret = errno;
-            DEBUG(SSSDBG_CRIT_FAILURE, "Cannot remove old symlink: [%d][%s].\n",
-                      ret, strerror(ret));
+            DEBUG(SSSDBG_CRIT_FAILURE,
+                  "Cannot remove old symlink '%s': [%d][%s].\n",
+                  symlink_filename, ret, strerror(ret));
             return EIO;
         }
         errno = 0;
@@ -351,8 +352,8 @@ done:
         if (tmp_ret != EOK) {
             tmp_ret = errno;
             DEBUG(SSSDBG_MINOR_FAILURE,
-                  "Failed to remove symbolic link: %d [%s]!\n",
-                  tmp_ret, sss_strerror(tmp_ret));
+                  "Failed to remove symbolic link '%s': %d [%s]!\n",
+                  symlink_filename, tmp_ret, sss_strerror(tmp_ret));
         }
     }
     talloc_free(tmp_ctx);
diff --git a/src/tools/files.c b/src/tools/files.c
index 5364f5c0dd53aad71452e18b8d7f1f04532132a4..8f1aa68beeb2676b56733f49550de170b404c789 100644
--- a/src/tools/files.c
+++ b/src/tools/files.c
@@ -225,7 +225,8 @@ static int remove_tree_with_ctx(TALLOC_CTX *mem_ctx,
             if (ret != 0) {
                 ret = errno;
                 DEBUG(SSSDBG_CRIT_FAILURE,
-                        "Removing file failed: [%d][%s]\n", ret, strerror(ret));
+                      "Removing file failed '%s': [%d][%s]\n",
+                      result->d_name, ret, strerror(ret));
                 goto fail;
             }
         }
diff --git a/src/tools/tools_mc_util.c b/src/tools/tools_mc_util.c
index ce899eb3c674afe8271be526dc83aa909cbecf89..2516a1981ddd965d4cae8c469ed79aaef8fa7193 100644
--- a/src/tools/tools_mc_util.c
+++ b/src/tools/tools_mc_util.c
@@ -117,10 +117,11 @@ done:
         if (ret == EOK) {
             pret = unlink(mc_filename);
             if (pret == -1) {
+                pret = errno;
                 DEBUG(SSSDBG_MINOR_FAILURE,
-                      "Failed to unlink file %s. "
-                       "Will be unlinked later by sssd_nss.\n",
-                       mc_filename);
+                      "Failed to unlink file %s, %d [%s]. "
+                      "Will be unlinked later by sssd_nss.\n",
+                      mc_filename, pret, strerror(pret));
             }
         }
     }
diff --git a/src/util/util.c b/src/util/util.c
index 89abfe734873161008dc9a7a42e7a87364f8074a..d4878bfaf4f0e92672756f12137d79ec65ef48f6 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -990,13 +990,15 @@ static int unlink_dbg(const char *filename)
 
     ret = unlink(filename);
     if (ret != 0) {
-        if (errno == 2) {
+        ret = errno;
+        if (ret == ENOENT) {
             DEBUG(SSSDBG_TRACE_INTERNAL,
                   "File already removed: [%s]\n", filename);
             return 0;
         } else {
             DEBUG(SSSDBG_CRIT_FAILURE,
-                  "Cannot remove temporary file [%s]\n", filename);
+                  "Cannot remove temporary file [%s] %d [%s]\n",
+                  filename, ret, strerror(ret));
             return -1;
         }
     }
-- 
2.4.11