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

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