This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=25394351a4bea9cf2c35d9093a96e42146949273

commit 25394351a4bea9cf2c35d9093a96e42146949273
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Mon Oct 30 03:10:50 2023 +0100

    build: Add support for structured procfs via struct psinfo
    
    On AIX and recent versions of Solaris and derivatives such as Illumos,
    there is an API to access the process information via structured
    data from /proc files.
    
    On at least Solaris <= 11.3 this interface is not compatible with LFS, so
    we need to check whether the header is available and usable, and then for
    the code using structured procfs we need to disable LFS when needed.
---
 Makefile.am               |  1 +
 configure.ac              |  3 ++-
 m4/dpkg-headers.m4        | 32 ++++++++++++++++++++++++++++++++
 m4/dpkg-types.m4          | 21 +++++++++++++++++++--
 utils/start-stop-daemon.c | 19 ++++++++++++++-----
 5 files changed, 68 insertions(+), 8 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index daafc44cf..5e824cfe0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,6 +24,7 @@ dist_aclocal_DATA = \
        m4/dpkg-compiler.m4 \
        m4/dpkg-coverage.m4 \
        m4/dpkg-funcs.m4 \
+       m4/dpkg-headers.m4 \
        m4/dpkg-libs.m4 \
        m4/dpkg-linker.m4 \
        m4/dpkg-progs.m4 \
diff --git a/configure.ac b/configure.ac
index 4d1432d94..929ffbde9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -127,7 +127,6 @@ AC_CHECK_HEADERS([\
   sys/syscall.h \
   sys/user.h \
   sys/mkdev.h \
-  sys/procfs.h \
   sys/pstat.h \
   linux/fiemap.h \
 ])
@@ -143,6 +142,7 @@ AS_CASE([$host_os],
     ])
   ]
 )
+DPKG_CHECK_HEADER_SYS_PROCFS
 AC_CHECK_HEADERS([sys/proc.h], [], [], [
 #ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
@@ -164,6 +164,7 @@ AC_TYPE_MODE_T
 AC_TYPE_PID_T
 AC_TYPE_SIZE_T
 DPKG_TYPE_PTRDIFF_T
+DPKG_TYPE_STRUCT_PSINFO
 DPKG_DECL_SYS_SIGLIST
 DPKG_DECL_SYS_ERRLIST
 
diff --git a/m4/dpkg-headers.m4 b/m4/dpkg-headers.m4
new file mode 100644
index 000000000..a95c65f70
--- /dev/null
+++ b/m4/dpkg-headers.m4
@@ -0,0 +1,32 @@
+# serial 1
+# Copyright © 2023 Guillem Jover <guil...@debian.org>
+
+# DPKG_CHECK_HEADER_SYS_PROCFS
+# ----------------------------
+# Check for the <sys/procfs.h> header.
+AC_DEFUN([DPKG_CHECK_HEADER_SYS_PROCFS], [
+  # On at least Solaris <= 11.3 we cannot use the new structured procfs API
+  # while also using LFS, so we need to check whether including <sys/procfs.h>
+  # is usable, and otherwise undefine _FILE_OFFSET_BITS, but only for the
+  # code using this (that is s-s-d).
+  dpkg_structured_procfs_supports_lfs=1
+  AC_CHECK_HEADERS([sys/procfs.h], [], [
+    # We need to reset the cached value, otherwise we will not be able to
+    # check it again.
+    AS_UNSET([ac_cv_header_sys_procfs_h])
+    # If a bare include failed, check whether we need to disable LFS to be
+    # able to use structured procfs.
+    AC_CHECK_HEADERS([sys/procfs.h], [
+        dpkg_structured_procfs_supports_lfs=0
+      ], [], [[
+#undef _FILE_OFFSET_BITS
+#define _STRUCTURED_PROC 1
+    ]])
+  ], [[
+#define _STRUCTURED_PROC 1
+  ]])
+
+  AC_DEFINE_UNQUOTED([DPKG_STRUCTURED_PROCFS_SUPPORTS_LFS],
+    [$dpkg_structured_procfs_supports_lfs],
+    [Whether structured procfs supports LFS])
+])# DPKG_CHECK_HEADER_SYS_PROCFS
diff --git a/m4/dpkg-types.m4 b/m4/dpkg-types.m4
index a17a34568..1159967d9 100644
--- a/m4/dpkg-types.m4
+++ b/m4/dpkg-types.m4
@@ -1,6 +1,6 @@
-# serial 1
+# serial 2
 # Copyright © 2005 Scott James Remnant <sc...@netsplit.com>
-# Copyright © 2009-2011 Guillem Jover <guil...@debian.org>
+# Copyright © 2009-2023 Guillem Jover <guil...@debian.org>
 
 # DPKG_TYPE_PTRDIFF_T
 # -------------------
@@ -12,6 +12,23 @@ AC_DEFUN([DPKG_TYPE_PTRDIFF_T], [
   ])
 ])# DPKG_TYPE_PTRDIFF_T
 
+# DPKG_TYPE_STRUCT_PSINFO
+# -----------------------
+# Check for the struct psinfo type.
+AC_DEFUN([DPKG_TYPE_STRUCT_PSINFO], [
+  AC_REQUIRE([DPKG_CHECK_HEADER_SYS_PROCFS])
+
+  AC_CHECK_TYPES([struct psinfo], [], [], [[
+#if !DPKG_STRUCTURED_PROCFS_SUPPORTS_LFS
+#undef _FILE_OFFSET_BITS
+#endif
+#define _STRUCTURED_PROC 1
+#if HAVE_SYS_PROCFS_H
+#include <sys/procfs.h>
+#endif
+  ]])
+])# DPKG_TYPE_STRUCT_PSINFO
+
 # DPKG_DECL_SYS_SIGLIST
 # ---------------------
 # Check for the sys_siglist variable in either signal.h or unistd.h
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c
index 743afeee9..4d6dc34de 100644
--- a/utils/start-stop-daemon.c
+++ b/utils/start-stop-daemon.c
@@ -21,6 +21,10 @@
  */
 
 #include <config.h>
+/* On at least Solaris <= 11.3 procfs is not compatible with LFS. */
+#if !DPKG_STRUCTURED_PROCFS_SUPPORTS_LFS
+#undef _FILE_OFFSET_BITS
+#endif
 #include <compat.h>
 
 #include <dpkg/macros.h>
@@ -49,8 +53,13 @@
 #  error Unknown architecture - cannot build start-stop-daemon
 #endif
 
+#if defined(OS_NetBSD)
 /* NetBSD needs this to expose struct proc. */
 #define _KMEMUSER 1
+#elif defined(OS_Solaris)
+/* Solaris needs this to expose the new structured procfs API. */
+#define _STRUCTURED_PROC 1
+#endif
 
 #ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
@@ -1610,7 +1619,7 @@ proc_status_field(pid_t pid, const char *field)
 
        return value;
 }
-#elif defined(OS_AIX)
+#elif (defined(OS_Solaris) || defined(OS_AIX)) && HAVE_STRUCT_PSINFO
 static bool
 proc_get_psinfo(pid_t pid, struct psinfo *psinfo)
 {
@@ -1741,7 +1750,7 @@ pid_is_exec(pid_t pid, const struct stat *esb)
 
        return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);
 }
-#elif defined(OS_AIX)
+#elif (defined(OS_Solaris) || defined(OS_AIX)) && HAVE_STRUCT_PSINFO
 static bool
 pid_is_exec(pid_t pid, const struct stat *esb)
 {
@@ -1934,7 +1943,7 @@ pid_is_child(pid_t pid, pid_t ppid)
 
        return (pid_t)info.pbi_ppid == ppid;
 }
-#elif defined(OS_AIX)
+#elif (defined(OS_Solaris) || defined(OS_AIX)) && HAVE_STRUCT_PSINFO
 static bool
 pid_is_child(pid_t pid, pid_t ppid)
 {
@@ -2043,7 +2052,7 @@ pid_is_user(pid_t pid, uid_t uid)
 
        return info.pbi_ruid == uid;
 }
-#elif defined(OS_AIX)
+#elif (defined(OS_Solaris) || defined(OS_AIX)) && HAVE_STRUCT_PSINFO
 static bool
 pid_is_user(pid_t pid, uid_t uid)
 {
@@ -2168,7 +2177,7 @@ pid_is_cmd(pid_t pid, const char *name)
 
        return false;
 }
-#elif defined(OS_AIX)
+#elif (defined(OS_Solaris) || defined(OS_AIX)) && HAVE_STRUCT_PSINFO
 static bool
 pid_is_cmd(pid_t pid, const char *name)
 {

-- 
Dpkg.Org's dpkg

Reply via email to