summaryrefslogtreecommitdiffstats
path: root/src/responder/nss
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2012-12-09 15:16:44 +0100
committerJakub Hrozek <jhrozek@redhat.com>2012-12-14 17:45:18 +0100
commit0f1998981de0a242b1400bb0dfc84a2952df50a6 (patch)
tree08f10ad6f3e0725f48fd32924ce77db3910565da /src/responder/nss
parenta4273341a11a0f32b25564d2a23eafa1c3f78c26 (diff)
downloadsssd-0f1998981de0a242b1400bb0dfc84a2952df50a6.tar.gz
sssd-0f1998981de0a242b1400bb0dfc84a2952df50a6.tar.xz
sssd-0f1998981de0a242b1400bb0dfc84a2952df50a6.zip
NSS: Fix the error handler in sss_mc_create_file
https://fedorahosted.org/sssd/ticket/1704 The function is short enough so that we can simply stick with return and release resources before returning as appropriate.
Diffstat (limited to 'src/responder/nss')
-rw-r--r--src/responder/nss/nsssrv_mmap_cache.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/responder/nss/nsssrv_mmap_cache.c b/src/responder/nss/nsssrv_mmap_cache.c
index 8e8be9409..a352abf3d 100644
--- a/src/responder/nss/nsssrv_mmap_cache.c
+++ b/src/responder/nss/nsssrv_mmap_cache.c
@@ -661,7 +661,7 @@ static errno_t sss_mc_create_file(struct sss_mc_ctx *mc_ctx)
{
mode_t old_mask;
int ofd;
- int ret;
+ int ret, uret;
useconds_t t = 50000;
int retries = 3;
@@ -694,28 +694,34 @@ static errno_t sss_mc_create_file(struct sss_mc_ctx *mc_ctx)
* by everyone for now */
old_mask = umask(0022);
- ret = 0;
+ errno = 0;
mc_ctx->fd = open(mc_ctx->file, O_CREAT | O_EXCL | O_RDWR, 0644);
+ umask(old_mask);
if (mc_ctx->fd == -1) {
ret = errno;
DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to open mmap file %s: %d(%s)\n",
mc_ctx->file, ret, strerror(ret)));
- goto done;
+ return ret;
}
ret = sss_br_lock_file(mc_ctx->fd, 0, 1, retries, t);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE,
("Failed to lock file %s.\n", mc_ctx->file));
- goto done;
- }
+ close(mc_ctx->fd);
-done:
- /* reset mask back */
- umask(old_mask);
+ /* Report on unlink failures but don't overwrite the errno
+ * from sss_br_lock_file
+ */
+ errno = 0;
+ uret = unlink(mc_ctx->file);
+ if (uret == -1) {
+ uret = errno;
+ DEBUG(SSSDBG_TRACE_FUNC, ("Failed to rm mmap file %s: %d(%s)\n",
+ mc_ctx->file, uret, strerror(uret)));
+ }
- if (ret) {
- close(mc_ctx->fd);
+ return ret;
}
return ret;