* [gentoo-dev] [PATCH] acct-user.eclass: include exit status in death message
@ 2023-06-25 17:51 Mike Gilbert
2023-06-25 18:52 ` Michał Górny
0 siblings, 1 reply; 5+ messages in thread
From: Mike Gilbert @ 2023-06-25 17:51 UTC (permalink / raw
To: gentoo-dev
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() {
eerror " usermod ${optsq[@]} ${ACCT_USER_NAME}"
else
eerror "$(<"${T}/usermod-error.log")"
- die "usermod failed"
+ die "usermod failed with status ${status}"
fi
fi
}
@@ -502,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
--
2.41.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [gentoo-dev] [PATCH] acct-user.eclass: include exit status in death message
2023-06-25 17:51 [gentoo-dev] [PATCH] acct-user.eclass: include exit status in death message Mike Gilbert
@ 2023-06-25 18:52 ` Michał Górny
2023-06-25 20:15 ` Oskari Pirhonen
2023-06-25 22:15 ` Mike Gilbert
0 siblings, 2 replies; 5+ messages in thread
From: Michał Górny @ 2023-06-25 18:52 UTC (permalink / raw
To: gentoo-dev
I think a better approach would be to always include $? in die messages
in Portage.
--
Best regards,
Michał Górny
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [gentoo-dev] [PATCH] acct-user.eclass: include exit status in death message
2023-06-25 18:52 ` Michał Górny
@ 2023-06-25 20:15 ` Oskari Pirhonen
2023-06-25 22:15 ` Mike Gilbert
1 sibling, 0 replies; 5+ messages in thread
From: Oskari Pirhonen @ 2023-06-25 20:15 UTC (permalink / raw
To: Michał Górny; +Cc: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 1186 bytes --]
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [gentoo-dev] [PATCH] acct-user.eclass: include exit status in death message
2023-06-25 18:52 ` Michał Górny
2023-06-25 20:15 ` Oskari Pirhonen
@ 2023-06-25 22:15 ` Mike Gilbert
2023-06-26 2:00 ` Sam James
1 sibling, 1 reply; 5+ messages in thread
From: Mike Gilbert @ 2023-06-25 22:15 UTC (permalink / raw
To: gentoo-dev
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [gentoo-dev] [PATCH] acct-user.eclass: include exit status in death message
2023-06-25 22:15 ` Mike Gilbert
@ 2023-06-26 2:00 ` Sam James
0 siblings, 0 replies; 5+ messages in thread
From: Sam James @ 2023-06-26 2:00 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 827 bytes --]
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 377 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-26 2:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-25 17:51 [gentoo-dev] [PATCH] acct-user.eclass: include exit status in death message Mike Gilbert
2023-06-25 18:52 ` Michał Górny
2023-06-25 20:15 ` Oskari Pirhonen
2023-06-25 22:15 ` Mike Gilbert
2023-06-26 2:00 ` Sam James
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox