summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2012-12-09 15:16:44 +0100
committerJakub Hrozek <jhrozek@redhat.com>2012-12-11 15:36:48 +0100
commit8b7040df8bcfee8cb31903136562eea73232f3d0 (patch)
treeb828c62dc907d3e35a641c0d124e22d5b831adcd /src
parentb24712874c686977465a551a3129133cec884584 (diff)
downloadsssd-8b7040df8bcfee8cb31903136562eea73232f3d0.tar.gz
sssd-8b7040df8bcfee8cb31903136562eea73232f3d0.tar.bz2
sssd-8b7040df8bcfee8cb31903136562eea73232f3d0.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')
-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 c6c5a555..542c837c 100644
--- a/src/responder/nss/nsssrv_mmap_cache.c
+++ b/src/responder/nss/nsssrv_mmap_cache.c
@@ -671,7 +671,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;
@@ -704,28 +704,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;