]> git.itanic.dy.fi Git - rrdd/commitdiff
process.c: Factor out job request handling
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sun, 13 May 2012 15:06:45 +0000 (18:06 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sun, 13 May 2012 15:06:45 +0000 (18:06 +0300)
Separate the epoll_wait handling and the actual file descriptor
handling. This is preparation for signald_fd handling.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
process.c

index 4b19b97e3ccfa1f589d5f2cc6d9dbd26682b70c6..0632e6c6697abad5aa5ff4a88c9592b3ab12507e 100644 (file)
--- a/process.c
+++ b/process.c
@@ -164,36 +164,11 @@ static int grant_new_job(void)
        return 0;
 }
 
-int poll_job_requests(int timeout)
+static int handle_job_request(void)
 {
-       struct epoll_event event;
-       int ret;
-       int pid;
-
-       /* Convert positive seconds to milliseconds */
-       timeout = timeout > 0 ? 1000 * timeout : timeout;
-
-       ret = epoll_wait(epoll_fd, &event, 1, timeout);
+       int ret, pid;
 
-       if (ret == -1) {
-               if (errno != EINTR) {
-                       pr_err("epoll_wait: %m\n");
-                       return -1;
-               }
-
-               /*
-                * If epoll_wait() was interrupted, better start
-                * everything again from the beginning
-                */
-               return 0;
-       }
-
-       if (ret == 0) {
-               pr_info("Timed out\n");
-               goto out;
-       }
-
-       ret = read(event.data.fd, &pid, sizeof(pid));
+       ret = read(job_request_fd[0], &pid, sizeof(pid));
        if (ret < 0) {
                pr_err("Failed to read: %m\n");
                return -1;
@@ -209,7 +184,7 @@ int poll_job_requests(int timeout)
                        jobs_pending++;
                } else {
                        ret = grant_new_job();
-                       goto out;
+                       return 0;
                }
        } else if (pid < 0) {
                if (job_count > max_jobs)
@@ -221,10 +196,46 @@ int poll_job_requests(int timeout)
                if (jobs_pending) {
                        jobs_pending--;
                        ret = grant_new_job();
-                       goto out;
+                       return 0;
+               }
+       }
+
+       return 0;
+}
+
+int poll_job_requests(int timeout)
+{
+       struct epoll_event event;
+       int ret;
+
+       /* Convert positive seconds to milliseconds */
+       timeout = timeout > 0 ? 1000 * timeout : timeout;
+
+       ret = epoll_wait(epoll_fd, &event, 1, timeout);
+
+       if (ret == -1) {
+               if (errno != EINTR) {
+                       pr_err("epoll_wait: %m\n");
+                       return -1;
                }
+
+               /*
+                * If epoll_wait() was interrupted, better start
+                * everything again from the beginning
+                */
+               return 0;
        }
 
+       if (ret == 0) {
+               pr_info("Timed out\n");
+               goto out;
+       }
+
+       if (event.data.fd == job_request_fd[0])
+               handle_job_request();
+       else
+               pr_err("Unknown fd: %d\n", event.data.fd);
+
 out:
        pr_info("Jobs active: %u, pending: %u\n", job_count, jobs_pending);
        return ret;