[PATCH] sysconf: Add _SC_NSIG

Tavian Barnes tavianator@tavianator.com
Fri Jan 24 16:28:14 GMT 2025


POSIX.1-2024 introduces a portable way to get the highest possible
signal number (plus one): sysconf(_SC_NSIG).  This is equivalent to
glibc's non-portable NSIG macro.

Link: https://www.austingroupbugs.net/view.php?id=741
Signed-off-by: Tavian Barnes <tavianator@tavianator.com>

---

There is also a new NSIG_MAX constant, but I'm less sure how to expose
that.  That is supposed to be the highest possible signal number (plus
one) that sigset_t could support, so that new signals can be added
without breaking ABI.  If that's not a concern, we could just do

    #define NSIG_MAX NSIG

Otherwise, it would have to be something like

    #define NSIG_MAX (CHAR_BIT * sizeof(sigset_t) + 1)

but that's not usable in preprocessor conditionals.  (I'm not sure it
has to be, but most of the *_MAX macros are I think.)

---
 bits/confname.h         | 5 ++++-
 posix/getconf.c         | 2 ++
 posix/sysconf.c         | 2 ++
 posix/tst-getconf.sh    | 1 +
 sysdeps/posix/sysconf.c | 7 +++++++
 5 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/bits/confname.h b/bits/confname.h
index 2eaf8a2eb2..9084e3ac90 100644
--- a/bits/confname.h
+++ b/bits/confname.h
@@ -531,8 +531,11 @@ enum
     _SC_MINSIGSTKSZ,
 #define	_SC_MINSIGSTKSZ			_SC_MINSIGSTKSZ
 
-    _SC_SIGSTKSZ
+    _SC_SIGSTKSZ,
 #define	_SC_SIGSTKSZ			_SC_SIGSTKSZ
+
+    _SC_NSIG
+#define	_SC_NSIG			_SC_NSIG
   };
 
 /* Values for the NAME argument to `confstr'.  */
diff --git a/posix/getconf.c b/posix/getconf.c
index 4ba9c0dee8..29933ceeb5 100644
--- a/posix/getconf.c
+++ b/posix/getconf.c
@@ -405,6 +405,8 @@ static const struct conf vars[] =
     { "_POSIX_IPV6", _SC_IPV6, SYSCONF },
     { "_POSIX_RAW_SOCKETS", _SC_RAW_SOCKETS, SYSCONF },
 
+    { "NSIG", _SC_NSIG, SYSCONF },
+
     { NULL, 0, SYSCONF }
   };
 
diff --git a/posix/sysconf.c b/posix/sysconf.c
index c3bf3b78fa..0f93305fe9 100644
--- a/posix/sysconf.c
+++ b/posix/sysconf.c
@@ -269,6 +269,8 @@ __sysconf (int name)
     case _SC_MINSIGSTKSZ:
     case _SC_SIGSTKSZ:
 
+    case _SC_NSIG:
+
       break;
     }
 
diff --git a/posix/tst-getconf.sh b/posix/tst-getconf.sh
index eeb4c51d84..30f442b83a 100644
--- a/posix/tst-getconf.sh
+++ b/posix/tst-getconf.sh
@@ -56,6 +56,7 @@ _NPROCESSORS_CONF
 NPROCESSORS_CONF
 _NPROCESSORS_ONLN
 NPROCESSORS_ONLN
+NSIG
 MQ_OPEN_MAX
 MQ_PRIO_MAX
 OPEN_MAX
diff --git a/sysdeps/posix/sysconf.c b/sysdeps/posix/sysconf.c
index 8f9a0adab2..853fd42a23 100644
--- a/sysdeps/posix/sysconf.c
+++ b/sysdeps/posix/sysconf.c
@@ -1209,6 +1209,13 @@ __sysconf (int name)
 #else
       return -1;
 #endif
+
+    case _SC_NSIG:
+#ifdef NSIG
+      return NSIG;
+#else
+      return -1;
+#endif
     }
 }
 
-- 
2.48.1



More information about the Libc-alpha mailing list