From: Martin Schwenke Date: Thu, 26 Apr 2018 10:32:30 +0000 (+1000) Subject: ctdb-daemon: Use a local variable instead of repeating getenv() X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=518be6d5a26771040801f76db1279912128f3bc1;p=metze%2Fsamba%2Fwip.git ctdb-daemon: Use a local variable instead of repeating getenv() Makes the error handling easier and the code more compact. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/server/ctdbd.c b/ctdb/server/ctdbd.c index 38a5f9d39358..4a3c5f65b305 100644 --- a/ctdb/server/ctdbd.c +++ b/ctdb/server/ctdbd.c @@ -141,6 +141,7 @@ int main(int argc, const char *argv[]) const char **extra_argv; poptContext pc; struct tevent_context *ev; + const char *ctdb_base; /* Environment variable overrides default */ ctdbd_pidfile = getenv("CTDB_PIDFILE"); @@ -280,10 +281,14 @@ int main(int argc, const char *argv[]) /* Default value for CTDB_BASE - don't override */ setenv("CTDB_BASE", CTDB_ETCDIR, 0); + ctdb_base = getenv("CTDB_BASE"); + if (ctdb_base == NULL) { + D_ERR("CTDB_BASE not set\n"); + exit(1); + } /* tell ctdb what nodes are available */ - ctdb->nodes_file = - talloc_asprintf(ctdb, "%s/nodes", getenv("CTDB_BASE")); + ctdb->nodes_file = talloc_asprintf(ctdb, "%s/nodes", ctdb_base); if (ctdb->nodes_file == NULL) { DEBUG(DEBUG_ERR,(__location__ " Out of memory\n")); exit(1); @@ -301,7 +306,7 @@ int main(int argc, const char *argv[]) ctdb->event_script_dir = talloc_asprintf(ctdb, "%s/events.d", - getenv("CTDB_BASE")); + ctdb_base); if (ctdb->event_script_dir == NULL) { DBG_ERR("Out of memory\n"); exit(1);