summaryrefslogtreecommitdiffstats
path: root/common/dbus.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/dbus.c')
-rw-r--r--common/dbus.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/common/dbus.c b/common/dbus.c
index 7837aeba..92a86e73 100644
--- a/common/dbus.c
+++ b/common/dbus.c
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <errno.h>
+#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
@@ -643,3 +644,31 @@ DBusHandlerResult simple_introspect(DBusConnection *conn,
return send_message_and_unref(conn, reply);
}
+
+int set_nonblocking(int fd, int *err)
+{
+ long arg;
+
+ arg = fcntl(fd, F_GETFL);
+ if (arg < 0) {
+ if (err)
+ *err = errno;
+ error("fcntl(F_GETFL): %s (%d)", strerror(errno), errno);
+ return -1;
+ }
+
+ /* Return if already nonblocking */
+ if (arg & O_NONBLOCK)
+ return 0;
+
+ arg |= O_NONBLOCK;
+ if (fcntl(fd, F_SETFL, arg) < 0) {
+ if (err)
+ *err = errno;
+ error("fcntl(F_SETFL, O_NONBLOCK): %s (%d)",
+ strerror(errno), errno);
+ return -1;
+ }
+
+ return 0;
+}