diff options
author | Michal Zidek <mzidek@redhat.com> | 2013-08-21 15:26:36 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-08-22 19:42:31 +0200 |
commit | 1f7fb30cc25765e54841e5d5f4192c12e3b29a16 (patch) | |
tree | f4e642f45178ff22cefd3b81d979f2c6aa5b0a4d /src/responder | |
parent | 884b1305806847e2e05a07988b77d3b5f77a37bc (diff) | |
download | sssd-1f7fb30cc25765e54841e5d5f4192c12e3b29a16.tar.gz sssd-1f7fb30cc25765e54841e5d5f4192c12e3b29a16.tar.bz2 sssd-1f7fb30cc25765e54841e5d5f4192c12e3b29a16.zip |
mmap_cache: Use sss_atomic_write_s instead of write.
Use sss_atomic_write_s() instead of write() in
sss_mc_save_corrupted(). Also unlink() the file if no data
were written.
It is better to use sss_atomic_write_s instead of write
Diffstat (limited to 'src/responder')
-rw-r--r-- | src/responder/nss/nsssrv_mmap_cache.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/responder/nss/nsssrv_mmap_cache.c b/src/responder/nss/nsssrv_mmap_cache.c index fced018e..1f584a29 100644 --- a/src/responder/nss/nsssrv_mmap_cache.c +++ b/src/responder/nss/nsssrv_mmap_cache.c @@ -99,7 +99,7 @@ static void sss_mc_save_corrupted(struct sss_mc_ctx *mc_ctx) { int err; int fd = -1; - ssize_t written; + ssize_t written = -1; char *file = NULL; TALLOC_CTX *tmp_ctx; @@ -132,7 +132,7 @@ static void sss_mc_save_corrupted(struct sss_mc_ctx *mc_ctx) goto done; } - written = write(fd, mc_ctx->mmap_base, mc_ctx->mmap_size); + written = sss_atomic_write_s(fd, mc_ctx->mmap_base, mc_ctx->mmap_size); if (written != mc_ctx->mmap_size) { if (written == -1) { err = errno; @@ -151,6 +151,15 @@ static void sss_mc_save_corrupted(struct sss_mc_ctx *mc_ctx) done: if (fd != -1) { close(fd); + if (written == -1) { + err = unlink(file); + if (err != 0) { + err = errno; + DEBUG(SSSDBG_CRIT_FAILURE, + ("Failed to remove file '%s': %s.\n", file, + strerror(err))); + } + } } talloc_free(tmp_ctx); } |