summaryrefslogtreecommitdiff
path: root/src/udev/udev-ctrl.c
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2013-06-29 13:31:15 -0400
committerAnthony G. Basile <blueness@gentoo.org>2013-06-29 13:36:01 -0400
commitb722b49e9e857edbcc88cda0a94ddef87458e896 (patch)
tree1308af5ecf38ba14423570ac12d6f155be91b8e0 /src/udev/udev-ctrl.c
parent983cecd7952790c2d80fe77cc429c4fa762d990d (diff)
src/udev/udev-ctrl.c: restore accept4_fallback code
This code was accidentally removed in commit 601c4e8ce69338652b3c9178386cbc05de8bae8d We restore it here. Since most modern systems have accept4() this code will seldom be triggered. You can test by configuring as follows: ac_cv_have_decl_accept4="no" ./configure Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/udev/udev-ctrl.c')
-rw-r--r--src/udev/udev-ctrl.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c
index d8c57b216e..fe318586fc 100644
--- a/src/udev/udev-ctrl.c
+++ b/src/udev/udev-ctrl.c
@@ -10,6 +10,7 @@
*/
#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
@@ -177,6 +178,18 @@ int udev_ctrl_get_fd(struct udev_ctrl *uctrl)
return uctrl->sock;
}
+static inline accept4_fallback(int sockfd)
+{
+ int fd;
+
+ if ((fd = accept(sockfd, NULL, NULL)) >= 0) {
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+ fcntl(fd, F_SETFD, FD_CLOEXEC);
+ }
+
+ return fd;
+}
+
struct udev_ctrl_connection *udev_ctrl_get_connection(struct udev_ctrl *uctrl)
{
struct udev_ctrl_connection *conn;
@@ -192,8 +205,12 @@ struct udev_ctrl_connection *udev_ctrl_get_connection(struct udev_ctrl *uctrl)
#if HAVE_DECL_ACCEPT4
conn->sock = accept4(uctrl->sock, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK);
+
+ /* Fallback path when accept4() is unavailable */
+ if ( conn->sock < 0 && (errno == ENOSYS || errno == ENOTSUP) )
+ conn->sock = accept4_fallback(uctrl->sock);
#else
- conn->sock = accept(uctrl->sock, NULL, NULL);
+ conn->sock = accept4_fallback(uctrl->sock);
#endif
if (conn->sock < 0) {