From: Andrew Tridgell Date: Mon, 14 May 2007 23:44:33 +0000 (+1000) Subject: added a -i switch to run ctdbd without forking X-Git-Tag: tevent-0.9.20~348^2~2730 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cf1056df94943ddcc3d547d4533b4bc04f57f265;p=thirdparty%2Fsamba.git added a -i switch to run ctdbd without forking (This used to be ctdb commit 327df14ecd58f405fbe8b38afa2ee54a8dd0a2e4) --- diff --git a/ctdb/common/ctdb_daemon.c b/ctdb/common/ctdb_daemon.c index 69c5005952b..28ee086cc4b 100644 --- a/ctdb/common/ctdb_daemon.c +++ b/ctdb/common/ctdb_daemon.c @@ -62,7 +62,10 @@ static void ctdb_main_loop(struct ctdb_context *ctdb) } /* start the transport running */ - ctdb->methods->start(ctdb); + if (ctdb->methods->start(ctdb) != 0) { + DEBUG(0,("transport failed to start!\n")); + ctdb_fatal(ctdb, "transport failed to start"); + } /* go into a wait loop to allow other nodes to complete */ event_loop_wait(ctdb->ev); @@ -603,11 +606,14 @@ static int ux_socket_bind(struct ctdb_context *ctdb) return -1; } +#if 0 + /* AIX doesn't like this :( */ if (fchown(ctdb->daemon.sd, geteuid(), getegid()) != 0 || fchmod(ctdb->daemon.sd, 0700) != 0) { DEBUG(0,("Unable to secure ctdb socket '%s', ctdb->daemon.name\n")); goto failed; } +#endif set_non_blocking(ctdb->daemon.sd); @@ -701,7 +707,7 @@ int ctdb_start(struct ctdb_context *ctdb) /* start the protocol going as a daemon */ -int ctdb_start_daemon(struct ctdb_context *ctdb) +int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork) { int res; struct fd_event *fde; @@ -717,13 +723,15 @@ int ctdb_start_daemon(struct ctdb_context *ctdb) exit(10); } - if (fork()) { + if (do_fork && fork()) { return 0; } tdb_reopen_all(False); - setsid(); + if (do_fork) { + setsid(); + } block_signal(SIGPIPE); block_signal(SIGCHLD); diff --git a/ctdb/direct/ctdbd.c b/ctdb/direct/ctdbd.c index 2ed1ce5ae6a..e60e1812af8 100644 --- a/ctdb/direct/ctdbd.c +++ b/ctdb/direct/ctdbd.c @@ -45,10 +45,12 @@ static void block_signal(int signum) int main(int argc, const char *argv[]) { struct ctdb_context *ctdb; + int interactive = 0; struct poptOption popt_options[] = { POPT_AUTOHELP POPT_CTDB_CMDLINE + { "interactive", 'i', POPT_ARG_NONE, &interactive, 0, "don't fork", NULL }, POPT_TABLEEND }; int opt; @@ -90,5 +92,5 @@ int main(int argc, const char *argv[]) } /* start the protocol running (as a child) */ - return ctdb_start_daemon(ctdb); + return ctdb_start_daemon(ctdb, interactive?False:True); } diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index 2508ea3e639..762f7dac753 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -112,7 +112,7 @@ int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist); start the ctdb protocol */ int ctdb_start(struct ctdb_context *ctdb); -int ctdb_start_daemon(struct ctdb_context *ctdb); +int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork); /* attach to a ctdb database