From 00757bf15f0eb42661625ed16888d00af9a79561 Mon Sep 17 00:00:00 2001
From: V3n3RiX <venerix@koprulu.sector>
Date: Tue, 27 Jun 2023 01:33:47 +0100
Subject: gentoo auto-resync : 27:06:2023 - 01:33:47

---
 eclass/Manifest.gz       | Bin 38151 -> 38159 bytes
 eclass/acct-group.eclass |   2 +-
 eclass/acct-user.eclass  |  32 +++++++++++++++++++++++++-------
 3 files changed, 26 insertions(+), 8 deletions(-)

(limited to 'eclass')

diff --git a/eclass/Manifest.gz b/eclass/Manifest.gz
index 006f15588d41..bf92e8902a88 100644
Binary files a/eclass/Manifest.gz and b/eclass/Manifest.gz differ
diff --git a/eclass/acct-group.eclass b/eclass/acct-group.eclass
index 8d2d3adb7221..a0ad86066309 100644
--- a/eclass/acct-group.eclass
+++ b/eclass/acct-group.eclass
@@ -179,7 +179,7 @@ acct-group_pkg_preinst() {
 	fi
 
 	elog "Adding group ${ACCT_GROUP_NAME}"
-	groupadd "${opts[@]}" "${ACCT_GROUP_NAME}" || die
+	groupadd "${opts[@]}" "${ACCT_GROUP_NAME}" || die "groupadd failed with status $?"
 }
 
 fi
diff --git a/eclass/acct-user.eclass b/eclass/acct-user.eclass
index f8a51ebf9c6b..f658aa0eabc3 100644
--- a/eclass/acct-user.eclass
+++ b/eclass/acct-user.eclass
@@ -362,7 +362,7 @@ acct-user_pkg_preinst() {
 		fi
 
 		elog "Adding user ${ACCT_USER_NAME}"
-		useradd "${opts[@]}" "${ACCT_USER_NAME}" || die
+		useradd "${opts[@]}" "${ACCT_USER_NAME}" || die "useradd failed with status $?"
 		_ACCT_USER_ADDED=1
 	fi
 
@@ -432,12 +432,30 @@ acct-user_pkg_postinst() {
 	fi
 
 	elog "Updating user ${ACCT_USER_NAME}"
-	if ! usermod "${opts[@]}" "${ACCT_USER_NAME}" 2>"${T}/usermod-error.log"; then
-		# usermod outputs a warning if unlocking the account would result in an
-		# empty password. Hide stderr in a text file and display it if usermod
-		# fails.
+	# usermod outputs a warning if unlocking the account would result in an
+	# empty password. Hide stderr in a text file and display it if usermod fails.
+	usermod "${opts[@]}" "${ACCT_USER_NAME}" 2>"${T}/usermod-error.log"
+	local status=$?
+	if [[ ${status} -ne 0 ]]; then
 		cat "${T}/usermod-error.log" >&2
-		die "usermod failed"
+		if [[ ${status} -eq 8 ]]; then
+			# usermod refused to update the home directory
+			# for a uid with active processes.
+			eerror "Failed to update user ${ACCT_USER_NAME}"
+			eerror "This user currently has one or more running processes."
+			eerror "Please update this user manually with the following command:"
+
+			# Surround opts with quotes.
+			# With bash-5 (EAPI 8), we can use "${opts[@]@Q}" instead.
+			local q="'"
+			local optsq=( "${opts[@]/#/${q}}" )
+			optsq=( "${optsq[@]/%/${q}}" )
+
+			eerror "  usermod ${optsq[*]} ${ACCT_USER_NAME}"
+		else
+			eerror "$(<"${T}/usermod-error.log")"
+			die "usermod failed with status ${status}"
+		fi
 	fi
 }
 
@@ -484,7 +502,7 @@ acct-user_pkg_prerm() {
 	fi
 
 	elog "Locking user ${ACCT_USER_NAME}"
-	usermod "${opts[@]}" "${ACCT_USER_NAME}" || die
+	usermod "${opts[@]}" "${ACCT_USER_NAME}" || die "usermod failed with status $?"
 }
 
 fi
-- 
cgit v1.2.3