[SCM] Samba Shared Repository - branch master updated

Martin Schwenke martins at samba.org
Tue Jan 28 11:25:03 UTC 2020


The branch, master has been updated
       via  ea754bfdec9 ctdb-tests: Enable job control when keeping stdin open
       via  2380b13bf81 ctdb-tests: Don't close stdin when starting local daemons
       via  cf460bd9c4a ctdb-daemon: Shut down if interactive and stdin is closed
       via  d79e2dcfc84 ctdb-daemon: Only stop monitoring if it has been initialised
      from  0ad6a243b25 lib:util: Log mkdir error on correct debug levels

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit ea754bfdec9d537c500036d4d521bd41d34c0835
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Jan 14 10:58:15 2020 +1100

    ctdb-tests: Enable job control when keeping stdin open
    
    POSIX says:
    
      If job control is disabled (see set, -m), the standard input for an
      asynchronous list, before any explicit redirections are performed,
      shall be considered to be assigned to a file that has the same
      properties as /dev/null. This shall not happen if job control is
      enabled. In all cases, explicit redirection of standard input shall
      override this activity.
    
    ctdbd is backgrounded at startup, so the above causes stdin to be
    redirected from /dev/null.  Enable job control to work around this.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>
    
    Autobuild-User(master): Martin Schwenke <martins at samba.org>
    Autobuild-Date(master): Tue Jan 28 11:24:35 UTC 2020 on sn-devel-184

commit 2380b13bf81f0705d036a0b43c65e823dd0e3624
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon Jan 13 21:04:24 2020 +1100

    ctdb-tests: Don't close stdin when starting local daemons
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit cf460bd9c4ae1e0de871a6c4980a2c365e82550a
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon Jan 13 21:04:54 2020 +1100

    ctdb-daemon: Shut down if interactive and stdin is closed
    
    This allows a test environment to simply close its end of a pipe to
    cleanly shutdown ctdbd.  Like in smbd, this is only done if stdin is a
    pipe or a socket.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit d79e2dcfc84d937db3c6eb3d17520aaf6e7bba4c
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon Jan 13 21:13:32 2020 +1100

    ctdb-daemon: Only stop monitoring if it has been initialised
    
    This avoids a crash if ctdb_shutdown_sequence() is called before
    monitoring is initialised.
    
    Switch to using TALLOC_FREE() while touching this function.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

-----------------------------------------------------------------------

Summary of changes:
 ctdb/server/ctdb_daemon.c   | 59 +++++++++++++++++++++++++++++++++++++++++++++
 ctdb/server/ctdb_monitor.c  |  8 ++++--
 ctdb/tests/local_daemons.sh |  4 +--
 3 files changed, 67 insertions(+), 4 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c
index cc688b07e9c..c4ab2dbc3d3 100644
--- a/ctdb/server/ctdb_daemon.c
+++ b/ctdb/server/ctdb_daemon.c
@@ -1389,6 +1389,56 @@ static void ctdb_set_my_pnn(struct ctdb_context *ctdb)
 	D_NOTICE("PNN is %u\n", ctdb->pnn);
 }
 
+static void stdin_handler(struct tevent_context *ev,
+			  struct tevent_fd *fde,
+			  uint16_t flags,
+			  void *private_data)
+{
+	struct ctdb_context *ctdb = talloc_get_type_abort(
+		private_data, struct ctdb_context);
+	ssize_t nread;
+	char c;
+
+	nread = read(STDIN_FILENO, &c, 1);
+	if (nread != 1) {
+		D_ERR("stdin closed, exiting\n");
+		talloc_free(fde);
+		ctdb_shutdown_sequence(ctdb, EPIPE);
+	}
+}
+
+static int setup_stdin_handler(struct ctdb_context *ctdb)
+{
+	struct tevent_fd *fde;
+	struct stat st;
+	int ret;
+
+	ret = fstat(STDIN_FILENO, &st);
+	if (ret != 0) {
+		/* Problem with stdin, ignore... */
+		DBG_INFO("Can't fstat() stdin\n");
+		return 0;
+	}
+
+	if (!S_ISFIFO(st.st_mode)) {
+		DBG_INFO("Not a pipe...\n");
+		return 0;
+	}
+
+	fde = tevent_add_fd(ctdb->ev,
+			    ctdb,
+			    STDIN_FILENO,
+			    TEVENT_FD_READ,
+			    stdin_handler,
+			    ctdb);
+	if (fde == NULL) {
+		return ENOMEM;
+	}
+
+	DBG_INFO("Set up stdin handler\n");
+	return 0;
+}
+
 /*
   start the protocol going as a daemon
 */
@@ -1448,6 +1498,15 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
 		ctdb_set_child_logging(ctdb);
 	}
 
+	/* Exit if stdin is closed */
+	if (!do_fork) {
+		ret = setup_stdin_handler(ctdb);
+		if (ret != 0) {
+			DBG_ERR("Failed to setup stdin handler\n");
+			exit(1);
+		}
+	}
+
 	TALLOC_FREE(ctdb->srv);
 	if (srvid_init(ctdb, &ctdb->srv) != 0) {
 		DEBUG(DEBUG_CRIT,("Failed to setup message srvid context\n"));
diff --git a/ctdb/server/ctdb_monitor.c b/ctdb/server/ctdb_monitor.c
index cfa3a6a1bfa..5c694bde969 100644
--- a/ctdb/server/ctdb_monitor.c
+++ b/ctdb/server/ctdb_monitor.c
@@ -416,8 +416,12 @@ static void ctdb_check_health(struct tevent_context *ev,
 */
 void ctdb_stop_monitoring(struct ctdb_context *ctdb)
 {
-	talloc_free(ctdb->monitor->monitor_context);
-	ctdb->monitor->monitor_context = NULL;
+	if (ctdb->monitor == NULL) {
+		D_NOTICE("Monitoring not yet initialised\n");
+		return;
+	}
+
+	TALLOC_FREE(ctdb->monitor->monitor_context);
 
 	ctdb->monitor->next_interval = 5;
 	DEBUG(DEBUG_NOTICE,("Monitoring has been stopped\n"));
diff --git a/ctdb/tests/local_daemons.sh b/ctdb/tests/local_daemons.sh
index e45a79c3e82..4a653224b23 100755
--- a/ctdb/tests/local_daemons.sh
+++ b/ctdb/tests/local_daemons.sh
@@ -307,7 +307,7 @@ local_daemons_ssh ()
 	if $_close_stdin ; then
 		exec sh -c "$*" <&-
 	else
-		exec sh -c "$*"
+		exec sh -m -c "$*"
 	fi
 }
 
@@ -354,7 +354,7 @@ local_daemons_start ()
 
 	onnode_common
 
-	onnode "$_nodes" "${VALGRIND:-} ctdbd &"
+	onnode -i "$_nodes" "${VALGRIND:-} ctdbd &"
 }
 
 local_daemons_stop ()


-- 
Samba Shared Repository



More information about the samba-cvs mailing list