rpc.gssd: don't call poll(2) twice a second
authorChuck Lever <chuck.lever@oracle.com>
Mon, 6 Aug 2012 13:08:53 +0000 (09:08 -0400)
committerSteve Dickson <steved@redhat.com>
Mon, 6 Aug 2012 13:11:27 +0000 (09:11 -0400)
Use ppoll() instead.

[ cel Wed Aug  1 11:44:46 EDT 2012 - autoconfiscated Bruce's version ]

Related clean-up: Since we're pulling the poll/ppoll call out into a
separate function, note that the second argument of poll(2) and
ppoll(2) is not an int, it's an unsigned long.  The nfds_t typedef
is a recent invention, so use the raw type for compatibility with
older glibc headers.

Acked-by: J. Bruce Fields" <bfields@redhat.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
configure.ac
utils/gssd/gssd_main_loop.c
utils/gssd/gssd_proc.c

index b408f1b..18ee11a 100644 (file)
@@ -392,7 +392,7 @@ AC_CHECK_FUNCS([alarm atexit dup2 fdatasync ftruncate getcwd \
                gethostbyaddr gethostbyname gethostname getmntent \
                getnameinfo getrpcbyname getifaddrs \
                gettimeofday hasmntopt inet_ntoa innetgr memset mkdir pathconf \
-               realpath rmdir select socket strcasecmp strchr strdup \
+               ppoll realpath rmdir select socket strcasecmp strchr strdup \
                strerror strrchr strtol strtoul sigprocmask])
 
 
index 142c8c5..ccf7fe5 100644 (file)
@@ -55,7 +55,7 @@
 #include "err_util.h"
 
 extern struct pollfd *pollarray;
-extern int pollsize;
+extern unsigned long pollsize;
 
 #define POLL_MILLISECS 500
 
@@ -101,7 +101,7 @@ scan_poll_results(int ret)
                                break;
                }
        }
-};
+}
 
 static int
 topdirs_add_entry(struct dirent *dent)
@@ -179,10 +179,46 @@ out_err:
        return -1;
 }
 
+#ifdef HAVE_PPOLL
+static void gssd_poll(struct pollfd *fds, unsigned long nfds)
+{
+       sigset_t emptyset;
+       int ret;
+
+       sigemptyset(&emptyset);
+       ret = ppoll(fds, nfds, NULL, &emptyset);
+       if (ret < 0) {
+               if (errno != EINTR)
+                       printerr(0, "WARNING: error return from poll\n");
+       } else if (ret == 0) {
+               printerr(0, "WARNING: unexpected timeout\n");
+       } else {
+               scan_poll_results(ret);
+       }
+}
+#else  /* !HAVE_PPOLL */
+static void gssd_poll(struct pollfd *fds, unsigned long nfds)
+{
+       int ret;
+
+       /* race condition here: dir_changed could be set before we
+        * enter the poll, and we'd never notice if it weren't for the
+        * timeout. */
+       ret = poll(fds, nfds, POLL_MILLISECS);
+       if (ret < 0) {
+               if (errno != EINTR)
+                       printerr(0, "WARNING: error return from poll\n");
+       } else if (ret == 0) {
+               /* timeout */
+       } else { /* ret > 0 */
+               scan_poll_results(ret);
+       }
+}
+#endif /* !HAVE_PPOLL */
+
 void
 gssd_run()
 {
-       int                     ret;
        struct sigaction        dn_act = {
                .sa_handler = dir_notify_handler
        };
@@ -210,19 +246,7 @@ gssd_run()
                                exit(1);
                        }
                }
-               /* race condition here: dir_changed could be set before we
-                * enter the poll, and we'd never notice if it weren't for the
-                * timeout. */
-               ret = poll(pollarray, pollsize, POLL_MILLISECS);
-               if (ret < 0) {
-                       if (errno != EINTR)
-                               printerr(0,
-                                        "WARNING: error return from poll\n");
-               } else if (ret == 0) {
-                       /* timeout */
-               } else { /* ret > 0 */
-                       scan_poll_results(ret);
-               }
+               gssd_poll(pollarray, pollsize);
        }
        topdirs_free_list();
 
index 2861d06..e393d59 100644 (file)
 
 struct pollfd * pollarray;
 
-int pollsize;  /* the size of pollaray (in pollfd's) */
+unsigned long pollsize;  /* the size of pollaray (in pollfd's) */
 
 /*
  * convert a presentation address string to a sockaddr_storage struct. Returns