• [gentoo-dev] [PATCH] acct-user.eclass: improve error message when userm

    From Mike Gilbert@21:1/5 to All on Sat Jun 24 19:10:01 2023
    usermod refuses to update the home directory for a user with running
    processes. Output a more helpful message and avoid calling die for this.

    For other usermod failures, output stderr as an eerror message and die.

    Example output:

    * Failed to update user portage
    * This user currently has one or more running processes.
    * Please update this user manually with the following command:
    * usermod '--comment' 'System user; portage' '--home' '/var/lib/portage/home' '--shell' '/bin/bash' '--gid' 'portage' '--groups' '' portage

    Bug: https://bugs.gentoo.org/888189
    Signed-off-by: Mike Gilbert <floppym@gentoo.org>
    ---
    eclass/acct-user.eclass | 28 +++++++++++++++++++++++-----
    1 file changed, 23 insertions(+), 5 deletions(-)

    diff --git a/eclass/acct-user.eclass b/eclass/acct-user.eclass
    index f8a51ebf9c6b..88d7d354c8e6 100644
    --- a/eclass/acct-user.eclass
    +++ b/eclass/acct-user.eclass
    @@ -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 re