• [gentoo-dev] [PATCH] acct-user.eclass: include exit status in death mes

    From Mike Gilbert@21:1/5 to All on Sun Jun 25 20:00:01 2023
    Signed-off-by: Mike Gilbert <floppym@gentoo.org>
    ---
    eclass/acct-group.eclass | 2 +-
    eclass/acct-user.eclass | 6 +++---
    2 files changed, 4 insertions(+), 4 deletions(-)

    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 88d7d354c8e6..b03bf0f1ab28 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

    @@ -454,7 +454,7 @@ acct-user_pkg_postinst()
  • From =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?=@21:1/5 to All on Sun Jun 25 21:00:01 2023
    I think a better approach would be to always include $? in die messages
    in Portage.


    --
    Best regards,
    Michał Górny

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Oskari Pirhonen@21:1/5 to All on Sun Jun 25 22:20:01 2023
    On Sun, Jun 25, 2023 at 20:52:53 +0200, Michał Górny wrote:
    I think a better approach would be to always include $? in die messages
    in Portage.


    I'm not sure the exit code is useful in the general case. Something like
    rm(1) seems to give the same exit code despite failing for different
    reasons:

    $ rm /tmp/root_owned
    rm: remove write-protected regular empty file '/tmp/root_owned'? y
    rm: cannot remove '/tmp/root_owned': Operation not permitted
    $ echo $?
    1
    $ rm /tmp/nonexistent
    rm: cannot remove '/tmp/nonexistent': No such file or directory
    $ echo $?
    1

    On the other hand, groupadd(8) (at least) seems to have useful exit
    codes. From the man page:

    EXIT VALUES
    The groupadd command exits with the following values:

    0
    success

    2
    invalid command syntax

    3
    invalid argument to option

    4
    GID is already used (when called without -o)

    9
    group name is already used

    10
    can't update group file

    - Oskari

    -----BEGIN PGP SIGNATURE-----

    iHUEABYIAB0WIQQfOU+JeXjo4uxN6vCp8he9GGIfEQUCZJigTAAKCRCp8he9GGIf EfB2AP0btc9RWc0IDqV5/POkoSa8WEUci6ZGyWbpaRgT+eEf8gD/b8CkH88RYfpb KIt1H/jyMeJB9CprpGJtRW/qWhZnhAk=
    =2d/A
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Gilbert@21:1/5 to mgorny@gentoo.org on Mon Jun 26 00:20:01 2023
    On Sun, Jun 25, 2023 at 2:52 PM Michał Górny <mgorny@gentoo.org> wrote:

    I think a better approach would be to always include $? in die messages
    in Portage.

    It's a nice idea, but will not work in the case where die is not
    called immediately after the failing command.

    A couple of possible workarounds that could be used to reset $? before
    calling die:

    1. Exit in a subshell: (exit ${status})
    2. Return from a function: set_status() { return $1; }; set_status ${status}

    In any case, I would like to apply the acct-user.eclass patch soonish
    to help with debugging an error during stage building that releng
    reported to me in IRC. We can revisit changing the die function and
    possibly revert this patch later.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sam James@21:1/5 to Mike Gilbert on Mon Jun 26 04:10:01 2023
    Mike Gilbert <floppym@gentoo.org> writes:

    On Sun, Jun 25, 2023 at 2:52 PM Michał Górny <mgorny@gentoo.org> wrote:

    I think a better approach would be to always include $? in die messages
    in Portage.

    It's a nice idea, but will not work in the case where die is not
    called immediately after the failing command.

    A couple of possible workarounds that could be used to reset $? before calling die:

    1. Exit in a subshell: (exit ${status})
    2. Return from a function: set_status() { return $1; }; set_status ${status}

    In any case, I would like to apply the acct-user.eclass patch soonish
    to help with debugging an error during stage building that releng
    reported to me in IRC. We can revisit changing the die function and
    possibly revert this patch later.

    lgtm then

    --=-=-Content-Type: application/pgp-signature; name="signature.asc"

    -----BEGIN PGP SIGNATURE-----

    iOUEARYKAI0WIQQlpruI3Zt2TGtVQcJzhAn1IN+RkAUCZJjxKl8UgAAAAAAuAChp c3N1ZXItZnByQG5vdGF0aW9ucy5vcGVucGdwLmZpZnRoaG9yc2VtYW4ubmV0MjVB NkJCODhERDlCNzY0QzZCNTU0MUMyNzM4NDA5RjUyMERGOTE5MA8cc2FtQGdlbnRv by5vcmcACgkQc4QJ9SDfkZBLewEAuX9FjvJ++zOe86QJF2zXqpxmIRLY6xNvBHmM /D9fRdcA/jzzgfzt52aqOVOPfgbKc+sKLju5MtglkWeOgCrt7QQA
    =OTt2
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)