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

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