aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnoop C S <anoopcs@redhat.com>2018-03-01 10:39:20 +0530
committerAndreas Schneider <asn@samba.org>2018-05-02 14:23:34 +0200
commit10b6cc0ff0891b345d7f71dac44be963792ca32d (patch)
tree152ee9fab10e51d1fa7e1993b9d4d8e724ef604f /src
parentf55c1be920a989f4ec7f946eb7c17960fc3cf489 (diff)
downloadsocket_wrapper-10b6cc0ff0891b345d7f71dac44be963792ca32d.tar.gz
socket_wrapper-10b6cc0ff0891b345d7f71dac44be963792ca32d.tar.xz
socket_wrapper-10b6cc0ff0891b345d7f71dac44be963792ca32d.zip
swrap: Use helper functions to manage refcount
- swrap_get_refcount - swrap_alter_refcount Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'src')
-rw-r--r--src/socket_wrapper.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 8daa574..b25a33a 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1198,6 +1198,21 @@ static struct socket_info *swrap_get_socket_info(int si_index)
return (struct socket_info *)(&(sockets[si_index].info));
}
+static int swrap_get_refcount(struct socket_info *si)
+{
+ return si->refcount;
+}
+
+static void swrap_inc_refcount(struct socket_info *si)
+{
+ si->refcount += 1;
+}
+
+static void swrap_dec_refcount(struct socket_info *si)
+{
+ si->refcount -= 1;
+}
+
static const char *socket_wrapper_dir(void)
{
const char *s = getenv("SOCKET_WRAPPER_DIR");
@@ -1864,9 +1879,9 @@ static void swrap_remove_stale(int fd)
free(fi);
si = swrap_get_socket_info(si_index);
- si->refcount--;
+ swrap_dec_refcount(si);
- if (si->refcount > 0) {
+ if (swrap_get_refcount(si) > 0) {
return;
}
@@ -2923,7 +2938,7 @@ static int swrap_socket(int family, int type, int protocol)
* note: as side-effect, socket_wrapper_first_free_index
* zeroed the si, so we are starting from refcount 0
*/
- si->refcount++;
+ swrap_inc_refcount(si);
first_free = si->next_free;
si->next_free = 0;
@@ -3153,7 +3168,7 @@ static int swrap_accept(int s,
};
memcpy(&child_si->myname.sa.ss, &in_my_addr.sa.ss, in_my_addr.sa_socklen);
- si->refcount++;
+ swrap_inc_refcount(child_si);
first_free = child_si->next_free;
child_si->next_free = 0;
@@ -5666,9 +5681,9 @@ static int swrap_close(int fd)
ret = libc_close(fd);
si = swrap_get_socket_info(si_index);
- si->refcount--;
+ swrap_dec_refcount(si);
- if (si->refcount > 0) {
+ if (swrap_get_refcount(si) > 0) {
/* there are still references left */
return ret;
}
@@ -5727,7 +5742,7 @@ static int swrap_dup(int fd)
return -1;
}
- si->refcount++;
+ swrap_inc_refcount(si);
fi->si_index = src_fi->si_index;
/* Make sure we don't have an entry for the fd */
@@ -5788,7 +5803,7 @@ static int swrap_dup2(int fd, int newfd)
return -1;
}
- si->refcount++;
+ swrap_inc_refcount(si);
fi->si_index = src_fi->si_index;
/* Make sure we don't have an entry for the fd */
@@ -5836,7 +5851,7 @@ static int swrap_vfcntl(int fd, int cmd, va_list va)
return -1;
}
- si->refcount++;
+ swrap_inc_refcount(si);
fi->si_index = src_fi->si_index;
/* Make sure we don't have an entry for the fd */