summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Zidek <mzidek@redhat.com>2012-11-07 11:12:36 +0100
committerJakub Hrozek <jhrozek@redhat.com>2012-11-08 11:43:34 +0100
commite9086c9178b06ff396b958dcc2a1e5baa0693f5c (patch)
tree65f48cc9f852157258c7b079ae4452ff2791b92e
parent9ab30382e69fbe7b3a8f0183d3c017b41a43c54d (diff)
downloadsssd-e9086c9178b06ff396b958dcc2a1e5baa0693f5c.tar.gz
sssd-e9086c9178b06ff396b958dcc2a1e5baa0693f5c.tar.xz
sssd-e9086c9178b06ff396b958dcc2a1e5baa0693f5c.zip
util_lock.c: sss_br_lock_file accepted invalid parameter value
Return EINVAL if number of tries is <= 0. Also the parameter retries was renamed to num_tries, so it is more obvious that it also includes the first try.
-rw-r--r--src/util/util.h2
-rw-r--r--src/util/util_lock.c8
2 files changed, 7 insertions, 3 deletions
diff --git a/src/util/util.h b/src/util/util.h
index d9315aefe..b6ecfc2c9 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -561,7 +561,7 @@ struct sss_domain_info *copy_subdomain(TALLOC_CTX *mem_ctx,
/* from util_lock.c */
errno_t sss_br_lock_file(int fd, size_t start, size_t len,
- int retries, useconds_t wait);
+ int num_tries, useconds_t wait);
/* Endianness-compatibility for systems running older versions of glibc */
diff --git a/src/util/util_lock.c b/src/util/util_lock.c
index c2d7fac77..8db35a8cf 100644
--- a/src/util/util_lock.c
+++ b/src/util/util_lock.c
@@ -29,19 +29,23 @@
#include "util/util.h"
errno_t sss_br_lock_file(int fd, size_t start, size_t len,
- int retries, useconds_t wait)
+ int num_tries, useconds_t wait)
{
int ret;
struct flock lock;
int retries_left;
+ if (num_tries <= 0) {
+ return EINVAL;
+ }
+
lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET;
lock.l_start = start;
lock.l_len = len;
lock.l_pid = 0;
- for (retries_left = retries; retries_left > 0; retries_left--) {
+ for (retries_left = num_tries; retries_left > 0; retries_left--) {
ret = fcntl(fd, F_SETLK, &lock);
if (ret == -1) {
ret = errno;