4 Copyright (C) Andrew Tridgell 2006
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "lib/events/events.h"
23 #include "system/filesys.h"
25 #include "system/wait.h"
27 static void block_signal(int signum)
31 memset(&act, 0, sizeof(act));
33 act.sa_handler = SIG_IGN;
34 sigemptyset(&act.sa_mask);
35 sigaddset(&act.sa_mask, signum);
36 sigaction(signum, &act, NULL);
43 int main(int argc, const char *argv[])
45 struct ctdb_context *ctdb;
46 const char *nlist = NULL;
47 const char *transport = "tcp";
48 const char *myaddress = NULL;
52 struct poptOption popt_options[] = {
54 { "nlist", 0, POPT_ARG_STRING, &nlist, 0, "node list file", "filename" },
55 { "listen", 0, POPT_ARG_STRING, &myaddress, 0, "address to listen on", "address" },
56 { "transport", 0, POPT_ARG_STRING, &transport, 0, "protocol transport", NULL },
57 { "self-connect", 0, POPT_ARG_NONE, &self_connect, 0, "enable self connect", "boolean" },
58 { "daemon", 0, POPT_ARG_NONE, &daemon_mode, 0, "spawn a ctdb daemon", "boolean" },
62 const char **extra_argv;
66 struct event_context *ev;
68 pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
70 while ((opt = poptGetNextOpt(pc)) != -1) {
73 fprintf(stderr, "Invalid option %s: %s\n",
74 poptBadOption(pc, 0), poptStrerror(opt));
79 /* setup the remaining options for the main program to use */
80 extra_argv = poptGetArgs(pc);
83 while (extra_argv[extra_argc]) extra_argc++;
86 if (nlist == NULL || myaddress == NULL) {
87 printf("You must provide a node list with --nlist and an address with --listen\n");
91 block_signal(SIGPIPE);
93 ev = event_context_init(NULL);
98 printf("Failed to init ctdb\n");
103 ctdb_set_flags(ctdb, CTDB_FLAG_SELF_CONNECT);
106 ctdb_set_flags(ctdb, CTDB_FLAG_DAEMON_MODE);
109 ret = ctdb_set_transport(ctdb, transport);
111 printf("ctdb_set_transport failed - %s\n", ctdb_errstr(ctdb));
115 /* tell ctdb what address to listen on */
116 ret = ctdb_set_address(ctdb, myaddress);
118 printf("ctdb_set_address failed - %s\n", ctdb_errstr(ctdb));
122 /* tell ctdb what nodes are available */
123 ret = ctdb_set_nlist(ctdb, nlist);
125 printf("ctdb_set_nlist failed - %s\n", ctdb_errstr(ctdb));
129 /* start the protocol running */
130 ret = ctdb_start(ctdb);