NetBSD Problem Report #57214

From bruno@netbsd9.bruno.haible.de  Sat Feb  4 02:43:20 2023
Return-Path: <bruno@netbsd9.bruno.haible.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id CC5EC1A9239
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  4 Feb 2023 02:43:19 +0000 (UTC)
Message-Id: <20230204012526.4ACB0B5764@netbsd9.bruno.haible.de>
Date: Sat,  4 Feb 2023 02:25:26 +0100 (CET)
From: bruno@clisp.org
Reply-To: bruno@clisp.org
To: gnats-bugs@NetBSD.org
Subject: pthread_sigmask return value wrong when libpthread is not in use
X-Send-Pr-Version: 3.95

>Number:         57214
>Category:       lib
>Synopsis:       The return value of pthread_sigmask is not standards compliant
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 04 02:45:00 +0000 2023
>Closed-Date:    Fri Apr 05 08:39:12 +0000 2024
>Last-Modified:  Fri Apr 05 08:39:12 +0000 2024
>Originator:     bruno@clisp.org
>Release:        NetBSD 9.0
>Organization:
GNU
>Environment:
System: NetBSD netbsd9.bruno.haible.de 9.0 NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
When a program that is not linked with libpthread uses the pthread_sigmask
function, its return value can be wrong.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_sigmask.html
section "RETURN VALUE".
>How-To-Repeat:
Compile this program
==================== foo.c ================
#include <errno.h>
#include <signal.h>
#include <stdio.h>

int main ()
{
  sigset_t set;
  int ret;

  sigemptyset (&set);
  sigaddset (&set, SIGINT);

  ret = sigprocmask (1729, &set, NULL);
  if (ret == 0)
    printf ("sigprocmask succeeded!\n");
  else
    printf ("sigprocmask -> %d, errno=%d\n", ret, errno);

  ret = pthread_sigmask (1729, &set, NULL);
  if (ret == 0)
    printf ("pthread_sigmask succeeded!\n");
  else
    printf ("pthread_sigmask -> %d\n", ret);

  return 0;
}
=============================================
$ gcc -Wall foo.c
$ ./a.out

Expected output:
sigprocmask -> -1, errno=22
pthread_sigmask -> 22

Actual output:
sigprocmask -> -1, errno=22
pthread_sigmask -> -1

>Fix:

>Release-Note:

>Audit-Trail:
From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/57214: pthread_sigmask return value wrong when libpthread is
 not in use
Date: Sat, 4 Feb 2023 16:27:17 +0300

 On Sat, Feb 04, 2023 at 02:45:01 +0000, bruno@clisp.org wrote:

 > $ gcc -Wall foo.c
 > $ ./a.out
 > 
 > Expected output:
 > sigprocmask -> -1, errno=22
 > pthread_sigmask -> 22

 Hmm, this *is* the output I get on a -10'ish system

 $ cc -o sigmask sigmask.c
 $ ldd sigmask
 sigmask:
         -lc.12 => /usr/lib/libsparc_v8.so.0
         -lc.12 => /usr/lib/libc.so.12
 $ ./sigmask
 sigprocmask -> -1, errno=22
 pthread_sigmask -> 22


 This seems to have been fixed by kamil in response to your previous
 reprot but never pulled up.

 lib/libc/thread-stub/thread-stub.c 

 revision 1.30
 date: 2020-01-14 21:18:59 +0300;  author: kamil;  state: Exp;  lines: +5 -3;  commitid: Ba40xip2Q883DGSB;
 Adjust the error return value of pthread_sigmask for !libpthread usage

 Instead of returning -1, return errno on error.

 Catch up after the fix in libpthread by Andrew Doran in 2008
 in lib/libpthread/pthread_misc.c r.1.9.

 It's an open question whether this function shall be used without linked
 in the POSIX thread library.

 Detected by Bruno Haible (GNU) and documented in gnulib in commit
 "pthread_sigmask: Avoid test failure on NetBSD 8.0. " r. 4d16a83b0c1fcb6c.

 -uwe

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/57214: pthread_sigmask return value wrong when libpthread is
 not in use
Date: Sat, 4 Feb 2023 17:33:36 +0300

 [pullup-9 #1583]

 -uwe

State-Changed-From-To: open->closed
State-Changed-By: nia@NetBSD.org
State-Changed-When: Fri, 05 Apr 2024 08:39:12 +0000
State-Changed-Why:
fixed and pulled up


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.