rfkilld

An rfkill daemon, which runs scripts according to rfkill events.
git clone git://r-36.net/rfkilld
Log | Files | Refs | LICENSE

commit 398d2905b1b9bef02c7b11c687a408036da2c212
parent 0c6b4c7a43f3ecec86d7d43f2cb81f3ebe5f5dec
Author: Christoph Lohmann <20h@r-36.net>
Date:   Tue,  1 Mar 2011 07:32:51 +0100

Set nonblocking for poll.

Diffstat:
rfkilld.c | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/rfkilld.c b/rfkilld.c @@ -18,6 +18,7 @@ #include <sys/wait.h> #include <sys/types.h> #include <sys/stat.h> +#include <fcntl.h> #include "arg.h" @@ -26,6 +27,20 @@ char *etcdir = "/etc/rfkilld"; int running = 1; int dolog = 0; +int +setnonblocking(int fd) +{ + int flags; + + flags = fcntl(fd, F_GETFL); + if (flags < 0) + return 1; + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) + return 1; + + return 0; +} + void runifexecutable(char *file, char *oname, char *ostate) { @@ -152,6 +167,10 @@ main(int argc, char *argv[]) fds[0].fd = udev_monitor_get_fd(mon); fds[0].events = POLLIN|POLLPRI; + if (setnonblocking(fds[0].fd)) { + perror("setnonblocking"); + exit(EXIT_FAILURE); + } while(running) { ret = poll(fds, 1, -1); if (ret > 0) {