git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] maintenance: compare output of pthread functions for inequality with 0

From
JHJeff Hostetler <git@jeffhostetler.com>
Date
Dec 2, 2022, 18:44 UTC
Message-ID
<d4a5bd6e-77bd-eb63-5c7f-8f3d46cc0418@jeffhostetler.com>
In-Reply-To
<221202.86k039fz7x.gmgdl@evledraar.gmail.com>
On 12/2/22 1:10 PM, Ævar Arnfjörð Bjarmason wrote:
Show 82 quoted lines
> 
> On Fri, Dec 02 2022, Rose via GitGitGadget wrote:
> 
>> From: Seija <doremylover123@gmail.com>
>>
>> The documentation for pthread_create and pthread_sigmask state that:
>>
>> "On success, pthread_create() returns 0;
>> on error, it returns an error number"
>>
>> As such, we ought to check for an error
>> by seeing if the output is not 0.
>>
>> Checking for "less than" is a mistake
>> as the error code numbers can be greater than 0.
>>
>> Signed-off-by: Seija <doremylover123@gmail.com>
>> ---
>>      maintenance: compare output of pthread functions for inequality with 0
>>      
>>      The documentation for pthread_create and pthread_sigmask state that "On
>>      success, pthread_create() returns 0; on error, it returns an error
>>      number, and the contents of *thread are undefined."
>>      
>>      As such, we ought to check for an error by seeing if the output is not
>>      0, rather than being less than 0, since nothing stops these functions
>>      from returning a positive number.
>>      
>>      Signed-off by: Seija doremylover123@gmail.com
>>
>> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1389%2FAtariDreams%2Faddress-v1
>> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1389/AtariDreams/address-v1
>> Pull-Request: https://github.com/git/git/pull/1389
>>
>>   builtin/fsmonitor--daemon.c | 4 ++--
>>   run-command.c               | 2 +-
>>   2 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
>> index 6f30a4f93a7..52a08bb3b57 100644
>> --- a/builtin/fsmonitor--daemon.c
>> +++ b/builtin/fsmonitor--daemon.c
>> @@ -1209,7 +1209,7 @@ static int fsmonitor_run_daemon_1(struct fsmonitor_daemon_state *state)
>>   	 * events.
>>   	 */
>>   	if (pthread_create(&state->listener_thread, NULL,
>> -			   fsm_listen__thread_proc, state) < 0) {
>> +			   fsm_listen__thread_proc, state)) {
>>   		ipc_server_stop_async(state->ipc_server_data);
>>   		err = error(_("could not start fsmonitor listener thread"));
>>   		goto cleanup;
>> @@ -1220,7 +1220,7 @@ static int fsmonitor_run_daemon_1(struct fsmonitor_daemon_state *state)
>>   	 * Start the health thread to watch over our process.
>>   	 */
>>   	if (pthread_create(&state->health_thread, NULL,
>> -			   fsm_health__thread_proc, state) < 0) {
>> +			   fsm_health__thread_proc, state)) {
>>   		ipc_server_stop_async(state->ipc_server_data);
>>   		err = error(_("could not start fsmonitor health thread"));
>>   		goto cleanup;
>> diff --git a/run-command.c b/run-command.c
>> index 48b9ba6d6f0..756f1839aab 100644
>> --- a/run-command.c
>> +++ b/run-command.c
>> @@ -1019,7 +1019,7 @@ static void *run_thread(void *data)
>>   		sigset_t mask;
>>   		sigemptyset(&mask);
>>   		sigaddset(&mask, SIGPIPE);
>> -		if (pthread_sigmask(SIG_BLOCK, &mask, NULL) < 0) {
>> +		if (pthread_sigmask(SIG_BLOCK, &mask, NULL)) {
>>   			ret = error("unable to block SIGPIPE in async thread");
>>   			return (void *)ret;
>>   		}
>>
>> base-commit: 805265fcf7a737664a8321aaf4a0587b78435184
> 
> This looks good to me, and skimming through the rest of the
> pthread_create() it seems the rest of the code in-tree is correct.
> 
> But (and especially if you're interested) we really should follow-up
> here and fix the "error()" etc. part of this. After this we have cases
> in-tree where we on failure:

But to be clear, the pthread_ changes are good by themselves and can be considered a single task that could be advanced without any extra stuff.

All of the following, if of interest to you or anyone else, should be done in one or more separate/later and independent series.

Show 15 quoted lines
> 
>   * Call die_errno() (good)
>   * Call die(), error() etc., but with a manual strerror() argument,
>     these should just use the *_errno() helper.
>   * Don't report on the errno at all, e.g. in this case shown here.
> 
> It seems to me that all of these should be using die_errno(),
> error_errno() etc.
> 
> Or maybe it's the other way around, and we should not rely on the global
> "errno", but always capture the return value, and give that to
> strerror() (or set "errno = ret", and call {die,error,warning}_errno()).
> 
> In any case, some low-hanging #leftoverbits there...
> 
Previous: Ævar Arnfjörð BjarmasonNext: brian m. carlson
Message 4 of 7 in “maintenance: compare output of pthread functions for inequality with 0”
  1. maintenance: compare output of pthread functions for inequality with 0Rose via GitGitGadget, Dec 2, 2022
  2. Jeff HostetlerDec 2, 2022
  3. Ævar Arnfjörð BjarmasonDec 2, 2022
  4. Jeff HostetlerDec 2, 2022
  5. brian m. carlsonDec 2, 2022
  6. Ævar Arnfjörð BjarmasonDec 2, 2022
  7. brian m. carlsonDec 3, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.