summaryrefslogtreecommitdiffstats
path: root/ctdb/common/ctdb_daemon.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2007-04-29 16:19:40 +0200
committerAndrew Tridgell <tridge@samba.org>2007-04-29 16:19:40 +0200
commite21f69107f423f24f5407adb9323fb0bc8aa3f64 (patch)
treef357af261e07dde8822d0d178f7906c7e1cc9b33 /ctdb/common/ctdb_daemon.c
parent10910f52eb1e62bf5393952f4c3a7380bf2dc548 (diff)
downloadsamba-e21f69107f423f24f5407adb9323fb0bc8aa3f64.tar.gz
samba-e21f69107f423f24f5407adb9323fb0bc8aa3f64.tar.xz
samba-e21f69107f423f24f5407adb9323fb0bc8aa3f64.zip
yay! finally fixed the bug that volker, ronnie and I have been chasing
for 2 days. The main bug was in smbd, but there was a secondary (and more subtle) bug in ctdb that the bug in smbd exposed. When we get send a dmaster reply, we have to correctly update the dmaster in the recipient even if the original requst has timed out, otherwise ctdbd can get into a loop fighting over who will handle a key. This patch also cleans up the packet allocation, and makes ctdbd become a real daemon. (This used to be ctdb commit 59405e59ef522b97d8e20e4b14310a217141ac7c)
Diffstat (limited to 'ctdb/common/ctdb_daemon.c')
-rw-r--r--ctdb/common/ctdb_daemon.c52
1 files changed, 48 insertions, 4 deletions
diff --git a/ctdb/common/ctdb_daemon.c b/ctdb/common/ctdb_daemon.c
index d0d2c1a46d..a6d60fc00e 100644
--- a/ctdb/common/ctdb_daemon.c
+++ b/ctdb/common/ctdb_daemon.c
@@ -673,6 +673,48 @@ int ctdb_start(struct ctdb_context *ctdb)
return 0;
}
+
+/*
+ start the protocol going as a daemon
+*/
+int ctdb_start_daemon(struct ctdb_context *ctdb)
+{
+ int res;
+ struct fd_event *fde;
+ const char *domain_socket_name;
+
+ /* get rid of any old sockets */
+ unlink(ctdb->daemon.name);
+
+ /* create a unix domain stream socket to listen to */
+ res = ux_socket_bind(ctdb);
+ if (res!=0) {
+ DEBUG(0,(__location__ " Failed to open CTDB unix domain socket\n"));
+ exit(10);
+ }
+
+ if (fork()) {
+ return 0;
+ }
+
+ tdb_reopen_all(False);
+
+ setsid();
+ block_signal(SIGPIPE);
+ block_signal(SIGCHLD);
+
+ /* ensure the socket is deleted on exit of the daemon */
+ domain_socket_name = talloc_strdup(talloc_autofree_context(), ctdb->daemon.name);
+ talloc_set_destructor(domain_socket_name, unlink_destructor);
+
+ ctdb->ev = event_context_init(NULL);
+ fde = event_add_fd(ctdb->ev, ctdb, ctdb->daemon.sd, EVENT_FD_READ,
+ ctdb_accept_client, ctdb);
+ ctdb_main_loop(ctdb);
+
+ return 0;
+}
+
/*
allocate a packet for use in client<->daemon communication
*/
@@ -685,6 +727,7 @@ struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
int size;
struct ctdb_req_header *hdr;
size = ((length+1)+(CTDB_DS_ALIGNMENT-1)) & ~(CTDB_DS_ALIGNMENT-1);
+
hdr = (struct ctdb_req_header *)talloc_size(mem_ctx, size);
if (hdr == NULL) {
DEBUG(0,("Unable to allocate packet for operation %u of length %u\n",
@@ -692,11 +735,12 @@ struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
return NULL;
}
talloc_set_name_const(hdr, type);
- memset(hdr, 0, slength);
+ memset(hdr, 0, size);
hdr->operation = operation;
- hdr->length = length;
+ hdr->length = size;
hdr->ctdb_magic = CTDB_MAGIC;
hdr->ctdb_version = CTDB_VERSION;
+ hdr->srcnode = ctdb->vnn;
if (ctdb->vnn_map) {
hdr->generation = ctdb->vnn_map->generation;
}
@@ -724,9 +768,9 @@ struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
return NULL;
}
talloc_set_name_const(hdr, type);
- memset(hdr, 0, slength);
+ memset(hdr, 0, size);
hdr->operation = operation;
- hdr->length = length;
+ hdr->length = size;
hdr->ctdb_magic = CTDB_MAGIC;
hdr->ctdb_version = CTDB_VERSION;
hdr->generation = ctdb->vnn_map->generation;