summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2014-12-08 17:39:57 +0100
committerJakub Hrozek <jhrozek@redhat.com>2015-01-15 10:33:01 +0100
commitf3d91181d4ee9da3f8bbf4ddf8782951c0ae46c1 (patch)
treebac7a56e6bf8d336437396d937f01ed1d04ebd11 /src/util
parent0e8a48e38e467b05951d2719956f8c0d5aed76b3 (diff)
downloadsssd-f3d91181d4ee9da3f8bbf4ddf8782951c0ae46c1.tar.gz
sssd-f3d91181d4ee9da3f8bbf4ddf8782951c0ae46c1.tar.xz
sssd-f3d91181d4ee9da3f8bbf4ddf8782951c0ae46c1.zip
UTIL: Unify the fd_nonblocking implementation
The responder and child_common modules each had their own implementation. Unify it instead and add a unit test. Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/child_common.c23
-rw-r--r--src/util/util.c24
-rw-r--r--src/util/util.h12
3 files changed, 36 insertions, 23 deletions
diff --git a/src/util/child_common.c b/src/util/child_common.c
index 0afd3a617..b1af02337 100644
--- a/src/util/child_common.c
+++ b/src/util/child_common.c
@@ -518,29 +518,6 @@ int read_pipe_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
return EOK;
}
-/* The pipes to communicate with the child must be nonblocking */
-void fd_nonblocking(int fd)
-{
- int flags;
- int ret;
-
- flags = fcntl(fd, F_GETFL, 0);
- if (flags == -1) {
- ret = errno;
- DEBUG(SSSDBG_CRIT_FAILURE,
- "F_GETFL failed [%d][%s].\n", ret, strerror(ret));
- return;
- }
-
- if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
- ret = errno;
- DEBUG(SSSDBG_CRIT_FAILURE,
- "F_SETFL failed [%d][%s].\n", ret, strerror(ret));
- }
-
- return;
-}
-
static void child_invoke_callback(struct tevent_context *ev,
struct tevent_immediate *imm,
void *pvt);
diff --git a/src/util/util.c b/src/util/util.c
index 2acb8604a..613c559bb 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -880,3 +880,27 @@ done:
return ret;
}
+
+/* Set the nonblocking flag to the fd */
+errno_t sss_fd_nonblocking(int fd)
+{
+ int flags;
+ int ret;
+
+ flags = fcntl(fd, F_GETFL, 0);
+ if (flags == -1) {
+ ret = errno;
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "F_GETFL failed [%d][%s].\n", ret, strerror(ret));
+ return ret;
+ }
+
+ if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
+ ret = errno;
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "F_SETFL failed [%d][%s].\n", ret, strerror(ret));
+ return ret;
+ }
+
+ return EOK;
+}
diff --git a/src/util/util.h b/src/util/util.h
index 45efd1aef..60dbf9381 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -26,6 +26,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
+#include <fcntl.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
@@ -444,6 +445,17 @@ errno_t sss_hash_create_ex(TALLOC_CTX *mem_ctx,
errno_t add_strings_lists(TALLOC_CTX *mem_ctx, const char **l1, const char **l2,
bool copy_strings, char ***_new_list);
+/**
+ * @brief set file descriptor as nonblocking
+ *
+ * Set the O_NONBLOCK flag for the input fd
+ *
+ * @param[in] fd The file descriptor to set as nonblocking
+ *
+ * @return EOK on success, errno code otherwise
+ */
+errno_t sss_fd_nonblocking(int fd);
+
/* Copy a NULL-terminated string list
* Returns NULL on out of memory error or invalid input
*/