]> git.itanic.dy.fi Git - rrdd/commitdiff
process.c: Move epoll initialization into init_jobcontrol()
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 12 May 2012 19:17:40 +0000 (22:17 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 12 May 2012 19:35:36 +0000 (22:35 +0300)
This is where the rest of the job control structures are initialized,
this should be initialized there too.

The missing epoll_ctl error handling is also now in.

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

index 6d309f671aa2ac97486411262c4334d79cd5d138..4b19b97e3ccfa1f589d5f2cc6d9dbd26682b70c6 100644 (file)
--- a/process.c
+++ b/process.c
@@ -12,6 +12,7 @@ static int child_count;
 static int parent_count;
 static int job_request_fd[2];
 static int job_get_permission_fd[2];
+static int epoll_fd;
 static unsigned int max_jobs;
 static unsigned int job_count;
 static unsigned int jobs_pending;
@@ -92,6 +93,20 @@ int init_jobcontrol(int max_jobs_requested)
        if (ret)
                return ret;
 
+       epoll_fd = epoll_create(1);
+       if (epoll_fd == -1) {
+               pr_err("Failed to epoll_create(): %m\n");
+               return -1;
+       }
+
+       ev.events = EPOLLIN;
+       ev.data.fd = job_request_fd[0];
+       ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, job_request_fd[0], &ev);
+       if (ret) {
+               pr_err("Failed to add epoll_fd: %m\n");
+               return -1;
+       }
+
        if (max_jobs_requested > 0) {
                max_jobs = max_jobs_requested;
                goto no_count_cpus;
@@ -152,28 +167,13 @@ static int grant_new_job(void)
 int poll_job_requests(int timeout)
 {
        struct epoll_event event;
-       static int epollfd;
        int ret;
        int pid;
 
-       if (!epollfd) {
-               struct epoll_event ev;
-
-               epollfd = epoll_create(1);
-               if (epollfd == -1) {
-                       pr_err("Failed to epoll_create(): %m\n");
-                       return -1;
-               }
-
-               ev.events = EPOLLIN;
-               ev.data.fd = job_request_fd[0];
-               epoll_ctl(epollfd, EPOLL_CTL_ADD, job_request_fd[0], &ev);
-       }
-
        /* Convert positive seconds to milliseconds */
        timeout = timeout > 0 ? 1000 * timeout : timeout;
 
-       ret = epoll_wait(epollfd, &event, 1, timeout);
+       ret = epoll_wait(epoll_fd, &event, 1, timeout);
 
        if (ret == -1) {
                if (errno != EINTR) {