diff options
author | Trond Myklebust <trond.myklebust@hammerspace.com> | 2020-05-08 09:59:26 -0400 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2020-05-08 10:07:19 -0400 |
commit | 4e9f95c336c4f1da0cf83a493d796543a8e7f4ea (patch) | |
tree | 77e6bb681eef11408d69e758c7eecff4961d1dbf | |
parent | 281244d2aacade273e4ac1f64ed8aff77a228b77 (diff) | |
download | nfs-utils-4e9f95c336c4f1da0cf83a493d796543a8e7f4ea.tar.gz |
mountd: Ensure dump_to_cache() sets errno appropriately
cache_write() will set errno if it returns -1, so that callers can
handle errors appropriately, however dump_to_cache() needs to do
so too.
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
-rw-r--r-- | utils/mountd/cache.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index 94e9e44b..0f323226 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -936,12 +936,13 @@ static void write_secinfo(char **bp, int *blen, struct exportent *ep, int flag_m } -static int dump_to_cache(int f, char *buf, int buflen, char *domain, +static int dump_to_cache(int f, char *buf, int blen, char *domain, char *path, struct exportent *exp, int ttl) { char *bp = buf; - int blen = buflen; time_t now = time(0); + size_t buflen; + ssize_t err; if (ttl <= 1) ttl = DEFAULT_TTL; @@ -974,8 +975,18 @@ static int dump_to_cache(int f, char *buf, int buflen, char *domain, } else qword_adduint(&bp, &blen, now + ttl); qword_addeol(&bp, &blen); - if (blen <= 0) return -1; - if (cache_write(f, buf, bp - buf) != bp - buf) return -1; + if (blen <= 0) { + errno = ENOBUFS; + return -1; + } + buflen = bp - buf; + err = cache_write(f, buf, buflen); + if (err < 0) + return err; + if ((size_t)err != buflen) { + errno = ENOSPC; + return -1; + } return 0; } |