]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fix up ancient nonblock usage
authorAlan T. DeKok <aland@freeradius.org>
Tue, 17 Mar 2020 21:06:37 +0000 (17:06 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 17 Mar 2020 23:22:08 +0000 (19:22 -0400)
src/lib/server/exec.c

index 450de769fe0301852e2fb8b1db9688e79294d9f9..63cbd05178c7137130727ce28d6019c533129e9f 100644 (file)
@@ -403,29 +403,8 @@ int radius_readfrom_program(int fd, pid_t pid, fr_time_delta_t timeout,
        int done = 0;
        int status;
        fr_time_t start;
-#ifdef O_NONBLOCK
-       bool nonblock = true;
-#endif
-
-#ifdef O_NONBLOCK
-       /*
-        *      Try to set it non-blocking.
-        */
-       do {
-               int flags;
-
-               if ((flags = fcntl(fd, F_GETFL, NULL)) < 0)  {
-                       nonblock = false;
-                       break;
-               }
 
-               flags |= O_NONBLOCK;
-               if (fcntl(fd, F_SETFL, flags) < 0) {
-                       nonblock = false;
-                       break;
-               }
-       } while (0);
-#endif
+       fr_nonblock(fd);
 
        /*
         *      Minimum timeout period is one section
@@ -471,14 +450,14 @@ int radius_readfrom_program(int fd, pid_t pid, fr_time_delta_t timeout,
                 *      Read as many bytes as possible.  The kernel
                 *      will return the number of bytes available.
                 */
-               if (nonblock) {
-                       status = read(fd, answer + done, left);
-               } else
+               status = read(fd, answer + done, left);
+#else
+               /*
+                *      There's at least 1 byte ready: read it.
+                *      This is a terrible hack for non-blocking IO.
+                */
+               status = read(fd, answer + done, 1);
 #endif
-                       /*
-                        *      There's at least 1 byte ready: read it.
-                        */
-                       status = read(fd, answer + done, 1);
 
                /*
                 *      Nothing more to read: stop.