git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Elia Pinto <gitter.spiros@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 00/41] use the stdlib EXIT_SUCCESS or EXIT_FAILURE exit status
Date: Tue, 22 Mar 2022 09:26:39 +0100	[thread overview]
Message-ID: <220322.86r16unzer.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <20220321225523.724509-1-gitter.spiros@gmail.com>


On Mon, Mar 21 2022, Elia Pinto wrote:

> EXIT_SUCCESS or EXIT_FAILURE are already used in some functions in git but
> not everywhere. Also in branch.c there is a returns exit(-1), ie 255, when
> exit(1) might be more appropriate.

On existing use: That's quite the overstatement :)

We use EXIT_{SUCCESS,FAILURE} only in:

 * contrib/credential/ code.
 * sh-i18n--envsubst.c
 * EXIT_FAILURE in one stray test helper

So out of "real git" that users see only sh-i18n--envsubst.c will ever
run by default, and the reason it uses these is because it's as-is
imported GNU code.

I'd think if anything we'd be better off doing this the other way
around, and always hardcoding either 0 or 1.

I'm not aware of any platform where EXIT_SUCCESS is non-zero, although
that's probably left open by the C standard.

For EXIT_FAILURE there *are* platforms where it's non-1, but I don't
know if we're ported to any of those, e.g. on z/OS it's[1]:

    The argument status can have a value from 0 to 255 inclusive or be
    one of the macros EXIT_SUCCESS or EXIT_FAILURE. The value of
    EXIT_SUCCESS is defined in stdlib.h as 0; the value of EXIT_FAILURE
    is 8.

Now, I don't know z/OS at all, but e.g. if a shellscripts calls a C
program there would $? be 1 if we hardcode 1, but 8 on EXIT_FAILURE?

We also document for some of these programs that on failure we'll return
1 specifically, not whatever EXIT_FAILURE is.

These patches also miss cases where we'll set 0 or 1 in a variable, and
then exit(ret). See e.g. builtin/rm.c. You just changed the hardcoded
exit(1), but missed where we'll return a hardcoded 0 or 1 via a
variable.

And then there's changing exit(-1) to exit(1). That's existing
non-portable use that we really should fix. But I know that you missed a
lot there, since I instrumented git.c recently to intercept those for
testing (it came up in some thread). We have a lot more than you spotted
(and some will error if mapped to 1 IIRC). Most of those also want to
exit 128, not 1.

Anyway:

All in all I think we should just double down on the hardcoding instead,
but we should fix the exit(-1) cases, and that's best done with some new
GIT_TEST_ASSERT_NO_UNPORTABLE_EXIT testing or whatever.

A lot of these codepaths are also paths we should fix, but not because
we exit(N) with a hardcoded N, but because we invoke exit(N) there at
all. See 338abb0f045 (builtins + test helpers: use return instead of
exit() in cmd_*, 2021-06-08) for how some of those should be changed.

I think we'd be much better off with something like this in
git-compat-util.h:

    #ifndef BYPASS_EXIT_SANITY
    #ifdef EXIT_SUCCESS
    #if EXIT_SUCCESS != 0
    #error "git assumes EXIT_SUCCESS is 0, not whatever yours is, please report this. Build with -DBYPASS_EXIT_SANITY to continue building at your own risk"
    #endif
    #endif
    #ifdef EXIT_FAILURE
    #if EXIT_FAILURE != 0
    #error "git assumes EXIT_FAILRE is 1, not whatever yours is, please report this. Build with -DBYPASS_EXIT_SANITY to continue building at your own risk"
    #endif
    #endif
    #endif

Or *if* we're going to pursue this a twist on that (I really don't think
this is worthwhile, just saying) where we'd re-define EXIT_SUCCESS and
EXIT_FAILURE to some sentinel values like 123 and 124.

Then run our entire test suite and roundtrip-assert that at least we
ourselves handled that properly. I.e. whenever run_command() runs and we
check for success we check 123, not 0, and a "normal failure" is 124,
not 1.

I know we'll get a *lot of* failures if we do that, so I'm not arguing
that we *should*, just that it's rather easy for you to test that and
see the resulting test suite dumpster fire.

So I don't see how a *partial conversion* is really getting us anywhere,
even if we take the pedantic C portability view of things.

All we'd have accomplished is a false sense of portability on most OS's,
as these will be 0 and 1 anyway. And on any stray odd OS's like z/OS
we'll just need to deal with e.g. both 1 and 8 for EXIT_FAILURE, since
we *will* miss a lot of cases.

1. https://www.ibm.com/docs/en/zos/2.1.0?topic=functions-exit-end-program

  parent reply	other threads:[~2022-03-22  8:51 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-21 22:54 [PATCH 00/41] use the stdlib EXIT_SUCCESS or EXIT_FAILURE exit status Elia Pinto
2022-03-21 22:54 ` [PATCH 01/41] archive.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 02/41] branch.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 03/41] am.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 04/41] blame.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 05/41] commit.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 06/41] credential-cache--daemon.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 07/41] help.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 08/41] init-db.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 09/41] mailsplit.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 10/41] merge-index.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 11/41] merge.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 12/41] pull.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 13/41] rebase.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 14/41] remote-ext.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 15/41] rev-parse.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 16/41] rm.c: " Elia Pinto
2022-03-21 22:54 ` [PATCH 17/41] shortlog.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 18/41] show-branch.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 19/41] stash.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 20/41] tag.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 21/41] unpack-objects.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 22/41] update-index.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 23/41] obstack.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 24/41] git-credential-osxkeychain.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 25/41] git-credential-wincred.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 26/41] daemon.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 27/41] git.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 28/41] help.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 29/41] http-backend.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 30/41] parse-options.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 31/41] path.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 32/41] remote-curl.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 33/41] run-command.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 34/41] setup.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 35/41] shell.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 36/41] test-json-writer.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 37/41] test-reach.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 38/41] test-submodule-config.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 39/41] test-submodule-nested-repo-config.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 40/41] upload-pack.c: " Elia Pinto
2022-03-21 22:55 ` [PATCH 41/41] exit.cocci: " Elia Pinto
2022-03-22  6:49 ` [PATCH 00/41] " Bagas Sanjaya
2022-03-22  8:45   ` Elia Pinto
2022-03-22 11:21   ` Bagas Sanjaya
2022-03-22  8:26 ` Ævar Arnfjörð Bjarmason [this message]
2022-03-22 17:47   ` Elia Pinto
2022-03-23 11:13   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=220322.86r16unzer.gmgdl@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitter.spiros@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).