summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/nmbd/nmbd.c27
-rw-r--r--source3/nmbd/nmbd_packets.c33
2 files changed, 52 insertions, 8 deletions
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index 6e0de362b9..f328673a55 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/nmbd/nmbd.c
@@ -40,6 +40,27 @@ BOOL found_lm_clients = False;
time_t StartupTime = 0;
+struct event_context *nmbd_event_context(void)
+{
+ static struct event_context *ctx;
+
+ if (!ctx && !(ctx = event_context_init(NULL))) {
+ smb_panic("Could not init nmbd event context\n");
+ }
+ return ctx;
+}
+
+struct messaging_context *nmbd_messaging_context(void)
+{
+ static struct messaging_context *ctx;
+
+ if (!ctx && !(ctx = messaging_init(NULL, server_id_self(),
+ nmbd_event_context()))) {
+ smb_panic("Could not init nmbd messaging context\n");
+ }
+ return ctx;
+}
+
/**************************************************************************** **
Handle a SIGTERM in band.
**************************************************************************** */
@@ -732,6 +753,11 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port)
setpgid( (pid_t)0, (pid_t)0 );
#endif
+ message_init();
+ if (nmbd_messaging_context() == NULL) {
+ return 1;
+ }
+
#ifndef SYNC_DNS
/* Setup the async dns. We do it here so it doesn't have all the other
stuff initialised and thus chewing memory and sockets */
@@ -745,7 +771,6 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port)
}
pidfile_create("nmbd");
- message_init();
message_register(MSG_FORCE_ELECTION, nmbd_message_election, NULL);
#if 0
/* Until winsrepl is done. */
diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c
index d34beb7ff6..2fbf2f4146 100644
--- a/source3/nmbd/nmbd_packets.c
+++ b/source3/nmbd/nmbd_packets.c
@@ -1730,7 +1730,8 @@ BOOL listen_for_packets(BOOL run_election)
int i;
static int maxfd = 0;
- fd_set fds;
+ fd_set r_fds;
+ fd_set w_fds;
int selrtn;
struct timeval timeout;
#ifndef SYNC_DNS
@@ -1745,12 +1746,13 @@ BOOL listen_for_packets(BOOL run_election)
rescan_listen_set = False;
}
- memcpy((char *)&fds, (char *)listen_set, sizeof(fd_set));
+ memcpy((char *)&r_fds, (char *)listen_set, sizeof(fd_set));
+ FD_ZERO(&w_fds);
#ifndef SYNC_DNS
dns_fd = asyncdns_fd();
if (dns_fd != -1) {
- FD_SET(dns_fd, &fds);
+ FD_SET(dns_fd, &r_fds);
maxfd = MAX( maxfd, dns_fd);
}
#endif
@@ -1765,11 +1767,24 @@ BOOL listen_for_packets(BOOL run_election)
timeout.tv_sec = (run_election||num_response_packets) ? 1 : NMBD_SELECT_LOOP;
timeout.tv_usec = 0;
+ {
+ struct timeval now = timeval_current();
+ event_add_to_select_args(nmbd_event_context(), &now,
+ &r_fds, &w_fds, &timeout, &maxfd);
+ }
+
+ if (timeval_is_zero(&timeout)) {
+ /* Process a timed event now... */
+ if (run_events(nmbd_event_context(), 0, NULL, NULL)) {
+ return False;
+ }
+ }
+
/* Prepare for the select - allow certain signals. */
BlockSignals(False, SIGTERM);
- selrtn = sys_select(maxfd+1,&fds,NULL,NULL,&timeout);
+ selrtn = sys_select(maxfd+1,&r_fds,&w_fds,NULL,&timeout);
/* We can only take signals when we are in the select - block them again here. */
@@ -1779,8 +1794,12 @@ BOOL listen_for_packets(BOOL run_election)
return False;
}
+ if (run_events(nmbd_event_context(), selrtn, &r_fds, &w_fds)) {
+ return False;
+ }
+
#ifndef SYNC_DNS
- if (dns_fd != -1 && FD_ISSET(dns_fd,&fds)) {
+ if (dns_fd != -1 && FD_ISSET(dns_fd,&r_fds)) {
run_dns_queue();
}
#endif
@@ -1788,7 +1807,7 @@ BOOL listen_for_packets(BOOL run_election)
for(i = 0; i < listen_number; i++) {
if (i < (listen_number/2)) {
/* Processing a 137 socket. */
- if (FD_ISSET(sock_array[i],&fds)) {
+ if (FD_ISSET(sock_array[i],&r_fds)) {
struct packet_struct *packet = read_packet(sock_array[i], NMB_PACKET);
if (packet) {
/*
@@ -1815,7 +1834,7 @@ BOOL listen_for_packets(BOOL run_election)
}
} else {
/* Processing a 138 socket. */
- if (FD_ISSET(sock_array[i],&fds)) {
+ if (FD_ISSET(sock_array[i],&r_fds)) {
struct packet_struct *packet = read_packet(sock_array[i], DGRAM_PACKET);
if (packet) {
/*