Blame SOURCES/bz1937142-azure-lb-redirect-to-avoid-nc-dying-EPIPE-error.patch

0c4b27
From 760680df771b6e2a9fbcd2f6d9862df4ec1a86de Mon Sep 17 00:00:00 2001
0c4b27
From: Reid Wahl <nrwahl@protonmail.com>
0c4b27
Date: Tue, 9 Mar 2021 18:25:52 -0800
0c4b27
Subject: [PATCH 1/2] azure-lb: Be quiet during stop operation
0c4b27
0c4b27
Currently, it logs "kill (<pid>) No such process" to stderr during stops.
0c4b27
0c4b27
A stop operation is expected to run `kill -s 0 $pid` for a nonexistent
0c4b27
PID, so log that at debug level.
0c4b27
0c4b27
A start or monitor operation's `kill -s 0 $pid` should always succeed,
0c4b27
so any output is unexpected and an error.
0c4b27
0c4b27
Also remove "local" bashism.
0c4b27
0c4b27
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
0c4b27
---
0c4b27
 heartbeat/azure-lb | 22 ++++++++++++++--------
0c4b27
 1 file changed, 14 insertions(+), 8 deletions(-)
0c4b27
0c4b27
diff --git a/heartbeat/azure-lb b/heartbeat/azure-lb
0c4b27
index 65a12235b..863132744 100755
0c4b27
--- a/heartbeat/azure-lb
0c4b27
+++ b/heartbeat/azure-lb
0c4b27
@@ -93,12 +93,18 @@ getpid() {
0c4b27
 
0c4b27
 lb_monitor() {
0c4b27
 	if test -f "$pidfile"; then
0c4b27
-		if pid=`getpid $pidfile` && [ "$pid" ] && kill -s 0 $pid; then
0c4b27
-			return $OCF_SUCCESS
0c4b27
-		else
0c4b27
-			# pidfile w/o process means the process died
0c4b27
-			return $OCF_ERR_GENERIC
0c4b27
+		[ "$__OCF_ACTION" = "stop" ] && level="debug" || level="err"
0c4b27
+
0c4b27
+		if pid=$(getpid "$pidfile") && [ -n "$pid" ]; then
0c4b27
+			output=$(kill -s 0 "$pid" 2>&1)
0c4b27
+			mon_rc=$?
0c4b27
+
0c4b27
+			[ -n "$output" ] && ocf_log "$level" "$output"
0c4b27
+			[ "$mon_rc" -eq 0 ] && return $OCF_SUCCESS
0c4b27
 		fi
0c4b27
+
0c4b27
+		# pidfile w/o process means the process died
0c4b27
+		return $OCF_ERR_GENERIC
0c4b27
 	else
0c4b27
 		return $OCF_NOT_RUNNING
0c4b27
 	fi
0c4b27
@@ -131,7 +137,7 @@ lb_start() {
0c4b27
 }
0c4b27
 
0c4b27
 lb_stop() {
0c4b27
-	local rc=$OCF_SUCCESS
0c4b27
+	stop_rc=$OCF_SUCCESS
0c4b27
 
0c4b27
         if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then
0c4b27
                 # Allow 2/3 of the action timeout for the orderly shutdown
0c4b27
@@ -160,7 +166,7 @@ lb_stop() {
0c4b27
                 while :; do
0c4b27
                         if ! lb_monitor; then
0c4b27
                                 ocf_log warn "SIGKILL did the job."
0c4b27
-                                rc=$OCF_SUCCESS
0c4b27
+                                stop_rc=$OCF_SUCCESS
0c4b27
                                 break
0c4b27
                         fi
0c4b27
                         ocf_log info "The job still hasn't stopped yet. Waiting..."
0c4b27
@@ -168,7 +174,7 @@ lb_stop() {
0c4b27
                 done
0c4b27
 	fi
0c4b27
 	rm -f $pidfile 
0c4b27
-	return $rc
0c4b27
+	return $stop_rc
0c4b27
 }
0c4b27
 
0c4b27
 lb_validate() {
0c4b27
0c4b27
From 10f39e90d6b04c28752a4f9adc94dfc03d9d61b8 Mon Sep 17 00:00:00 2001
0c4b27
From: Reid Wahl <nrwahl@protonmail.com>
0c4b27
Date: Tue, 9 Mar 2021 18:32:45 -0800
0c4b27
Subject: [PATCH 2/2] azure-lb: Redirect stdout and stderr to /dev/null
0c4b27
0c4b27
This fixes a regression introduced in commit d22700fc.
0c4b27
0c4b27
When the nc listener process created by an azure-lb resource attempts to
0c4b27
write to stdout, it dies with an EPIPE error.
0c4b27
0c4b27
This can happen when random/garbage input is sent to the nc listener, as
0c4b27
may happen during a port scan. For example, if the listener is on port
0c4b27
62000, and a client sends some text (e.g., `echo test | nc node1
0c4b27
62000`), then the listener attempts to echo "test" to its stdout. This
0c4b27
fails with an EPIPE.
0c4b27
0c4b27
Prior to commit d22700fc, all output was redirected to the pid file.
0c4b27
This caused its own problems, but it prevented this particular behavior.
0c4b27
0c4b27
The fix is to redirect the listener's stdout and stderr to /dev/null.
0c4b27
0c4b27
Resolves: RHBZ#1937142
0c4b27
Resolves: RHBZ#1937151
0c4b27
0c4b27
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
0c4b27
---
0c4b27
 heartbeat/azure-lb | 2 +-
0c4b27
 1 file changed, 1 insertion(+), 1 deletion(-)
0c4b27
0c4b27
diff --git a/heartbeat/azure-lb b/heartbeat/azure-lb
0c4b27
index 863132744..ade1b4577 100755
0c4b27
--- a/heartbeat/azure-lb
0c4b27
+++ b/heartbeat/azure-lb
0c4b27
@@ -119,7 +119,7 @@ lb_start() {
0c4b27
 	if ! lb_monitor; then
0c4b27
 		ocf_log debug "Starting $process: $cmd"
0c4b27
 		# Execute the command as created above
0c4b27
-		$cmd &
0c4b27
+		$cmd >/dev/null 2>&1 &
0c4b27
 		echo $! > $pidfile
0c4b27
 		if lb_monitor; then
0c4b27
 			ocf_log debug "$process: $cmd started successfully, calling monitor"