Clarify when GEOM utilities exit with success or failure.
authorKirk McKusick <mckusick@FreeBSD.org>
Sat, 16 Jul 2022 17:25:22 +0000 (10:25 -0700)
committerKirk McKusick <mckusick@FreeBSD.org>
Sat, 16 Jul 2022 17:26:51 +0000 (10:26 -0700)
commit90e29718cffcec987769ccbe39308357202c46d5
treeab12dff7add20e318193531bacb7a0b20e89583e
parent9917049b60f7cf7345a09d2bc22d51764a477984
Clarify when GEOM utilities exit with success or failure.

Historically, GEOM utilities (gpart(8), gstripe(8), gmirror(8),
etc) used the gctl_error() routine to report errors. If they called
gctl_error() they would exit with EXIT_FAILURE, otherwise they would
return with EXIT_SUCCESS. If they used gctl_error() to output an
informational message, for example when run with the -v (verbose)
option, they would mistakenly exit with EXIT_FAILURE. A further
limitation of the gctl_error() function was that it could only be
called once. Messages from any additional calls to gctl_error()
would be silently discarded.

To resolve these problems a new function, gctl_msg() has been added.
It can be called multiple times to output multiple messages. It
also has an additional errno argument which should be zero if it is
an informational message or an errno value (EINVAL, EBUSY, etc) if
it is an error. When done the gctl_post_messages() function should
be called to indicate that all messages have been posted. If any
of the messages had a non-zero errno, the utility will EXIT_FAILURE.
If only informational messages (with zero errno) were posted, the
utility will EXIT_SUCCESS.

Tested by:   Peter Holm
PR:          265184
MFC after:   1 week
lib/libgeom/geom_ctl.c
sbin/geom/core/geom.c
sys/geom/geom.h
sys/geom/geom_ctl.c
sys/geom/union/g_union.c