lib: Remove sys_waitpid
[metze/samba/wip.git] / source3 / lib / server_prefork.c
index 016f65c5c374cc0ae79954c44d52789fdf86fe2f..1d64db2af0c66467845a90736be2591c45f62322 100644 (file)
@@ -25,7 +25,7 @@
 #include "system/shmem.h"
 #include "system/filesys.h"
 #include "server_prefork.h"
-#include "../lib/util/util.h"
+#include "../lib/util/samba_util.h"
 #include "../lib/util/tevent_unix.h"
 
 struct prefork_pool {
@@ -83,6 +83,8 @@ bool prefork_create_pool(TALLOC_CTX *mem_ctx,
        }
        for (i = 0; i < listen_fd_size; i++) {
                pfp->listen_fds[i] = listen_fds[i];
+               /* force sockets in non-blocking mode */
+               set_blocking(listen_fds[i], false);
        }
        pfp->main_fn = main_fn;
        pfp->private_data = private_data;
@@ -90,7 +92,8 @@ bool prefork_create_pool(TALLOC_CTX *mem_ctx,
        pfp->pool_size = max_children;
        data_size = sizeof(struct pf_worker_data) * max_children;
 
-       pfp->pool = anonymous_shared_allocate(data_size);
+       pfp->pool = (struct pf_worker_data *)anonymous_shared_allocate(
+               data_size);
        if (pfp->pool == NULL) {
                DEBUG(1, ("Failed to mmap memory for prefork pool!\n"));
                talloc_free(pfp);
@@ -103,7 +106,7 @@ bool prefork_create_pool(TALLOC_CTX *mem_ctx,
                pfp->pool[i].allowed_clients = 1;
                pfp->pool[i].started = now;
 
-               pid = sys_fork();
+               pid = fork();
                switch (pid) {
                case -1:
                        DEBUG(1, ("Failed to prefork child n. %d !\n", i));
@@ -156,7 +159,8 @@ int prefork_expand_pool(struct prefork_pool *pfp, int new_max)
        old_size = sizeof(struct pf_worker_data) * pfp->pool_size;
        new_size = sizeof(struct pf_worker_data) * new_max;
 
-       pool = anonymous_shared_resize(&pfp->pool, new_size, false);
+       pool = (struct prefork_pool *)anonymous_shared_resize(
+               &pfp->pool, new_size, false);
        if (pool == NULL) {
                ret = errno;
                DEBUG(3, ("Failed to mremap memory (%d: %s)!\n",
@@ -190,7 +194,7 @@ int prefork_add_children(struct tevent_context *ev_ctx,
                pfp->pool[i].allowed_clients = 1;
                pfp->pool[i].started = now;
 
-               pid = sys_fork();
+               pid = fork();
                switch (pid) {
                case -1:
                        DEBUG(1, ("Failed to prefork child n. %d !\n", j));
@@ -273,7 +277,7 @@ int prefork_retire_children(struct messaging_context *msg_ctx,
                     (pfp->pool[i].num_clients < 1)) &&
                    (pfp->pool[i].started <= age_limit)) {
                        /* tell the child it's time to give up */
-                       DEBUG(5, ("Retiring pid %d!\n", pfp->pool[i].pid));
+                       DEBUG(5, ("Retiring pid %u!\n", (unsigned int)pfp->pool[i].pid));
                        pfp->pool[i].cmds = PF_SRV_MSG_EXIT;
                        messaging_send(msg_ctx,
                                        pid_to_procid(pfp->pool[i].pid),
@@ -325,7 +329,7 @@ static void prefork_cleanup_loop(struct prefork_pool *pfp)
                        continue;
                }
 
-               pid = sys_waitpid(pfp->pool[i].pid, &status, WNOHANG);
+               pid = waitpid(pfp->pool[i].pid, &status, WNOHANG);
                if (pid > 0) {
 
                        if (pfp->pool[i].status != PF_WORKER_EXITING) {
@@ -662,7 +666,9 @@ int prefork_listen_recv(struct tevent_req *req,
        if (state->error) {
                ret = state->error;
        } else {
-               tevent_req_is_unix_error(req, &ret);
+               if (!tevent_req_is_unix_error(req, &ret)) {
+                       ret = 0;
+               }
        }
 
        if (ret) {