s3:smbd: use tevent_loop_once() in the parent event loop
[kai/samba-autobuild/.git] / source3 / smbd / server.c
index 075e44d319827a0c116fec291fe848f216dc6c9d..d27f98281b388c527638eef087137a9be55f7731 100644 (file)
@@ -212,7 +212,7 @@ static void remove_child_pid(pid_t pid, bool unclean_shutdown)
                /* a child terminated uncleanly so tickle all processes to see 
                   if they can grab any of the pending locks
                */
-               DEBUG(3,(__location__ " Unclean shutdown of pid %u\n", pid));
+               DEBUG(3,(__location__ " Unclean shutdown of pid %u\n", (unsigned int)pid));
                messaging_send_buf(smbd_messaging_context(), procid_self(), 
                                   MSG_SMB_BRL_VALIDATE, NULL, 0);
                message_send_all(smbd_messaging_context(), 
@@ -447,7 +447,6 @@ static bool smbd_open_one_socket(struct smbd_parent_context *parent,
        if (s->fd == -1) {
                DEBUG(0,("smbd_open_once_socket: open_socket_in: "
                        "%s\n", strerror(errno)));
-                       close(s->fd);
                TALLOC_FREE(s);
                /*
                 * We ignore an error here, as we've done before
@@ -655,48 +654,16 @@ static void smbd_parent_loop(struct smbd_parent_context *parent)
 {
        /* now accept incoming connections - forking a new process
           for each incoming connection */
-       DEBUG(2,("waiting for a connection\n"));
+       DEBUG(2,("waiting for connections\n"));
        while (1) {
-               struct timeval now, idle_timeout;
-               fd_set r_fds, w_fds;
-               int maxfd = 0;
-               int num;
+               int ret;
                TALLOC_CTX *frame = talloc_stackframe();
 
-               if (run_events(smbd_event_context(), 0, NULL, NULL)) {
-                       TALLOC_FREE(frame);
-                       continue;
-               }
-
-               idle_timeout = timeval_zero();
-
-               FD_ZERO(&w_fds);
-               FD_ZERO(&r_fds);
-               GetTimeOfDay(&now);
-
-               event_add_to_select_args(smbd_event_context(), &now,
-                                        &r_fds, &w_fds, &idle_timeout,
-                                        &maxfd);
-
-               num = sys_select(maxfd+1,&r_fds,&w_fds,NULL,
-                                timeval_is_zero(&idle_timeout) ?
-                                NULL : &idle_timeout);
-
-               /* check if we need to reload services */
-               check_reload(time(NULL));
-
-               if (run_events(smbd_event_context(), num, &r_fds, &w_fds)) {
-                       TALLOC_FREE(frame);
-                       continue;
+               ret = tevent_loop_once(smbd_event_context());
+               if (ret != 0) {
+                       exit_server_cleanly("tevent_loop_once() error");
                }
 
-               /* If the idle timeout fired and we don't have any connected
-                * users, exit gracefully. We should be running under a process
-                * controller that will restart us if necessry.
-                */
-               if (num == 0 && count_all_current_connections() == 0) {
-                       exit_server_cleanly("idle timeout");
-               }
                TALLOC_FREE(frame);
        } /* end while 1 */
 
@@ -727,7 +694,7 @@ void reload_printers(void)
                        DEBUG(3, ("removing stale printer %s\n", pname));
 
                        if (is_printer_published(NULL, snum, NULL))
-                               nt_printer_publish(NULL, snum, SPOOL_DS_UNPUBLISH);
+                               nt_printer_publish(NULL, snum, DSPRINT_UNPUBLISH);
                        del_a_printer(pname);
                        lp_killservice(snum);
                }