summaryrefslogtreecommitdiffstats
path: root/src/socket_wrapper.c
diff options
context:
space:
mode:
authorAnoop C S <anoopcs@redhat.com>2017-08-29 12:40:35 +0530
committerAndreas Schneider <asn@samba.org>2018-05-02 14:23:34 +0200
commit9702a15c2560988fe87119aa45787f935bef66fd (patch)
treee69c9128b62d9983edd140e4d76b791f0ab734b2 /src/socket_wrapper.c
parent327cb50d8370833bad9d260b9dc8f5c70fb5e2ce (diff)
downloadsocket_wrapper-9702a15c2560988fe87119aa45787f935bef66fd.tar.gz
socket_wrapper-9702a15c2560988fe87119aa45787f935bef66fd.tar.xz
socket_wrapper-9702a15c2560988fe87119aa45787f935bef66fd.zip
swrap: Add new routines to handle socket creation
A new function named swrap_create_socket is introduced which cleanly performs all stuff related to creation of new socket file descriptors and updation of relevant metadata including the free-list and reference counter. 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/socket_wrapper.c')
-rw-r--r--src/socket_wrapper.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 8daa75e..a6d979b 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1396,6 +1396,56 @@ static int socket_wrapper_first_free_index(void)
return first_free;
}
+static int swrap_add_socket_info(struct socket_info *si_input)
+{
+ struct socket_info *si = NULL;
+ int si_index;
+
+ if (si_input == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (first_free == -1) {
+ errno = ENFILE;
+ return -1;
+ }
+
+ si_index = first_free;
+ si = swrap_get_socket_info(si_index);
+
+ first_free = swrap_get_next_free(si);
+ *si = *si_input;
+ swrap_inc_refcount(si);
+
+ return si_index;
+}
+
+static int swrap_create_socket(struct socket_info *si, int fd)
+{
+ struct socket_info_fd *fi = NULL;
+ int idx;
+
+ fi = (struct socket_info_fd *)calloc(1, sizeof(struct socket_info_fd));
+ if (fi == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ idx = swrap_add_socket_info(si);
+ if (idx == -1) {
+ free(fi);
+ return -1;
+ }
+
+ fi->fd = fd;
+ fi->si_index = idx;
+
+ SWRAP_DLIST_ADD(socket_fds, fi);
+
+ return idx;
+}
+
static int convert_un_in(const struct sockaddr_un *un, struct sockaddr *in, socklen_t *len)
{
unsigned int iface;