svn commit: samba r19056 - in branches/tmp/vl-messaging/source/lib:
.
ab at samba.org
ab at samba.org
Tue Oct 3 12:21:04 GMT 2006
Author: ab
Date: 2006-10-03 12:21:02 +0000 (Tue, 03 Oct 2006)
New Revision: 19056
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=19056
Log:
Care about socket errors. Now smbd doesn't hang up when lockd exits and lockd honours SIGTERM. Patch from Aleksey Fedoseev
Modified:
branches/tmp/vl-messaging/source/lib/messages_dgram.c
branches/tmp/vl-messaging/source/lib/messages_socket.c
branches/tmp/vl-messaging/source/lib/messages_stream.c
Changeset:
Modified: branches/tmp/vl-messaging/source/lib/messages_dgram.c
===================================================================
--- branches/tmp/vl-messaging/source/lib/messages_dgram.c 2006-10-03 02:38:08 UTC (rev 19055)
+++ branches/tmp/vl-messaging/source/lib/messages_dgram.c 2006-10-03 12:21:02 UTC (rev 19056)
@@ -35,7 +35,7 @@
Send a message through the dgram socket
****************************************************************************/
-void send_on_socket_dgram(int socket_fd, struct message_list **queue)
+BOOL send_on_socket_dgram(int socket_fd, struct message_list **queue)
{
struct message_list* li = *queue;
struct sockaddr_un sunaddr;
@@ -43,7 +43,7 @@
if(li == NULL) {
DEBUG(0, ("No message available\n"));
- return ;
+ return False;
}
ZERO_STRUCT(sunaddr);
@@ -61,6 +61,7 @@
}
DLIST_REMOVE((*queue), li);
TALLOC_FREE(li);
+ return True;
} else {
if (errno == EMSGSIZE) {
DEBUG(5, ("Message (%d bytes) too large\n",
@@ -70,6 +71,7 @@
"socket %s: %s\n", li->msg->len,
sunaddr.sun_path, strerror(errno)));
}
+ return False;
}
}
@@ -118,28 +120,28 @@
Receive a message through the dgram socket
****************************************************************************/
-void receive_on_socket_dgram(int socket_fd, struct message_list **queue)
+BOOL receive_on_socket_dgram(int socket_fd, struct message_list **queue)
{
DATA_BLOB dgram = read_from_dgram_socket(socket_fd);
struct message_rec *msg;
struct message_list *li;
if (dgram.data == NULL) {
- return;
+ return False;
}
msg = (struct message_rec *)dgram.data;
if (dgram.length < sizeof(msg->len)) {
DEBUG(5, ("Message too short: %d\n", dgram.length));
data_blob_free(&dgram);
- return;
+ return False;
}
if (msg->len != dgram.length) {
DEBUG(5, ("Invalid message length received, got %d, "
"expected %d\n", msg->len, dgram.length));
data_blob_free(&dgram);
- return;
+ return False;
}
/* save the received message */
@@ -147,18 +149,20 @@
if (!(li = TALLOC_ZERO_P(NULL, struct message_list))) {
DEBUG(0, ("talloc failed\n"));
data_blob_free(&dgram);
- return;
+ return False;
}
if (!(li->msg = (struct message_rec*)TALLOC(li, msg->len))) {
DEBUG(0, ("talloc failed\n"));
TALLOC_FREE(li);
data_blob_free(&dgram);
- return;
+ return False;
}
memcpy(li->msg, msg, msg->len);
data_blob_free(&dgram);
DLIST_ADD_END((*queue), li, struct message_list*);
+
+ return True;
}
Modified: branches/tmp/vl-messaging/source/lib/messages_socket.c
===================================================================
--- branches/tmp/vl-messaging/source/lib/messages_socket.c 2006-10-03 02:38:08 UTC (rev 19055)
+++ branches/tmp/vl-messaging/source/lib/messages_socket.c 2006-10-03 12:21:02 UTC (rev 19056)
@@ -32,8 +32,8 @@
#include "includes.h"
/* main messaging functions - pointer to the selected implementation */
-static void (*receive_on_socket_func)(int socket_fd, struct message_list **queue);
-static void (*send_on_socket_func)(int socket_fd, struct message_list **queue);
+static BOOL (*receive_on_socket_func)(int socket_fd, struct message_list **queue);
+static BOOL (*send_on_socket_func)(int socket_fd, struct message_list **queue);
static struct process_id socket_pid;
static int socket_fd = -1;
@@ -61,7 +61,7 @@
{
struct message_list *p;
- if(wait_send) {
+ if(wait_send && socket_fd > 0) {
time_t start_time;
size_t timeout;
@@ -272,11 +272,13 @@
void message_select_setup_socket(int *maxfd, fd_set *rfds, fd_set *wfds)
{
- FD_SET(socket_fd, rfds);
- if(sent_messages) {
- FD_SET(socket_fd, wfds);
+ if(socket_fd > 0) {
+ FD_SET(socket_fd, rfds);
+ if(sent_messages) {
+ FD_SET(socket_fd, wfds);
+ }
+ *maxfd = MAX(*maxfd, socket_fd);
}
- *maxfd = MAX(*maxfd, socket_fd);
if ((enum messaging_type)lp_messaging_type() == MESSAGING_TYPE_STREAM) {
message_select_setup_stream(maxfd, rfds, wfds);
@@ -290,19 +292,32 @@
unsigned int message_receive_socket(fd_set *rfds, fd_set *wfds)
{
unsigned int affected = 0;
+ BOOL closed = False;
+ enum messaging_type mtype = lp_messaging_type();
if (FD_ISSET(socket_fd, rfds)) {
- receive_on_socket_func(socket_fd, &received_messages);
+ if(!receive_on_socket_func(socket_fd, &received_messages)) {
+ closed = True;
+ }
affected++;
}
if (FD_ISSET(socket_fd, wfds)) {
- send_on_socket_func(socket_fd, &sent_messages);
+ if(!send_on_socket_func(socket_fd, &sent_messages)) {
+ closed = True;
+ }
affected++;
}
- if ((enum messaging_type)lp_messaging_type() == MESSAGING_TYPE_STREAM) {
+ if (mtype == MESSAGING_TYPE_STREAM) {
affected += message_receive_stream(rfds, wfds, &received_messages);
+ } else if (mtype == MESSAGING_TYPE_DISPATCHER) {
+ /* stutdown messaging socket if messaging daemon exited */
+ if(closed) {
+ shutdown_sockets(False);
+ }
}
+
+
return affected;
}
Modified: branches/tmp/vl-messaging/source/lib/messages_stream.c
===================================================================
--- branches/tmp/vl-messaging/source/lib/messages_stream.c 2006-10-03 02:38:08 UTC (rev 19055)
+++ branches/tmp/vl-messaging/source/lib/messages_stream.c 2006-10-03 12:21:02 UTC (rev 19056)
@@ -211,7 +211,7 @@
Incoming unix connection
****************************************************************************/
-void receive_on_socket_stream(int listener, struct message_list **queue)
+BOOL receive_on_socket_stream(int listener, struct message_list **queue)
{
struct messaging_client *c;
int fd;
@@ -221,21 +221,21 @@
fd = accept(listener, (struct sockaddr *)&addr, &addrlen);
if (fd < 0) {
DEBUG(5, ("accept failed: %s\n", strerror(errno)));
- return;
+ return False;
}
if (addr.sun_family != AF_UNIX) {
DEBUG(5, ("Expected AF_UNIX(%d) in accept, got %d\n",
AF_UNIX, addr.sun_family));
close(fd);
- return;
+ return False;
}
c = TALLOC_P(NULL, struct messaging_client);
if (c == NULL) {
DEBUG(0, ("talloc failed\n"));
close(fd);
- return;
+ return False;
}
/* Drop clients only when there is no dispatcher */
@@ -258,7 +258,7 @@
c->incoming = allocate_container(c, NULL, 0);
if (c->incoming == NULL) {
TALLOC_FREE(c);
- return ;
+ return False;
}
c->outgoing = NULL;
c->connected = True;
@@ -266,6 +266,8 @@
DEBUG(10, ("Adding new client\n"));
DLIST_ADD(clients_cache, c);
+
+ return True;
}
/****************************************************************************
@@ -376,9 +378,10 @@
Dummy function
****************************************************************************/
-void send_on_socket_stream(int listener, struct message_list **queue)
+BOOL send_on_socket_stream(int listener, struct message_list **queue)
{
DEBUG(0, ("Hmm... sending on a listening socket!\n"));
+ return False;
}
/****************************************************************************
@@ -979,6 +982,13 @@
selret = sys_select(maxfd+1, &rfds, &wfds, NULL, NULL);
if (selret <= 0) {
+ if(errno == EINTR) {
+ DEBUG(5, ("Locking daemon was interrupted\n"));
+ close(*parent);
+ *parent = -1;
+ } else {
+ DEBUG(0, ("select failed\n"));
+ }
return;
}
@@ -1291,23 +1301,25 @@
Send a message through the dispatcher
****************************************************************************/
-void send_on_socket_dispatcher(int socket_fd, struct message_list **queue)
+BOOL send_on_socket_dispatcher(int socket_fd, struct message_list **queue)
{
if(!send_one_message(socket_fd, queue)) {
DEBUG(0, ("Can't send a message through the daemon\n"));
+ return False;
}
+ return True;
}
/****************************************************************************
Receive a message through the dispatcher
****************************************************************************/
-void receive_on_socket_dispatcher(int socket_fd, struct message_list **queue)
+BOOL receive_on_socket_dispatcher(int socket_fd, struct message_list **queue)
{
BOOL received = False;
if(!receive_one_message(socket_fd, NULL, disp_incoming, &received)) {
DEBUG(0, ("Can't receive a message through the daemon\n"));
- return ;
+ return False;
}
if(received) {
@@ -1318,7 +1330,7 @@
li = TALLOC_ZERO_P(NULL, struct message_list);
if(li == NULL) {
DEBUG(0, ("talloc failed\n"));
- return ;
+ return False;
}
li->msg = (struct message_rec*)TALLOC_ARRAY(
li, uint8_t,
@@ -1326,7 +1338,7 @@
if(li->msg == NULL) {
DEBUG(0, ("talloc failed\n"));
TALLOC_FREE(li);
- return ;
+ return False;
}
memcpy(li->msg, disp_incoming->msg,
@@ -1336,4 +1348,6 @@
disp_incoming->processed = (size_t)-1;
}
+
+ return True;
}
More information about the samba-cvs
mailing list