From b722b49e9e857edbcc88cda0a94ddef87458e896 Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Sat, 29 Jun 2013 13:31:15 -0400 Subject: 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 --- src/udev/udev-ctrl.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/udev') 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 +#include #include #include #include @@ -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) { -- cgit v1.2.3-54-g00ecf