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=127d25ed1220221f03d9bf11b906f89a065fcfad

The following commit(s) were added to refs/heads/main by this push:
     new 127d25ed1 libdpkg: Fix execname support on GNU/Hurd
127d25ed1 is described below

commit 127d25ed1220221f03d9bf11b906f89a065fcfad (HEAD -> main)
Author: Guillem Jover <[email protected]>
AuthorDate: Wed Jul 17 11:40:49 2024 +0200

    libdpkg: Fix execname support on GNU/Hurd
    
    Implement the missing code, and handle fcntl() returning -1 for the
    locked pid.
    
    We need to link against Hurd's libps and add it to libdpkg.pc, for the
    process functions.
    
    We need to protect the <dpkg/file.h> inclusion when including <hurd.h>
    as they have conflicting symbols for file_lock(), where the dpkg header
    is only needed on Solaris-based systems.
    
    Fixes: commit d6a9bb6951166a7254ab2b4f887c69c4bd4fb1a7
---
 lib/dpkg/Makefile.am   |  1 +
 lib/dpkg/execname.c    | 26 +++++++++++++++++++++++---
 lib/dpkg/libdpkg.pc.in |  2 +-
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/lib/dpkg/Makefile.am b/lib/dpkg/Makefile.am
index 862562c8f..dcf3d463c 100644
--- a/lib/dpkg/Makefile.am
+++ b/lib/dpkg/Makefile.am
@@ -48,6 +48,7 @@ EXTRA_libdpkg_la_DEPENDENCIES += \
 endif
 
 libdpkg_la_LIBADD = \
+       $(PS_LIBS) \
        $(Z_LIBS) \
        $(LZMA_LIBS) \
        $(ZSTD_LIBS) \
diff --git a/lib/dpkg/execname.c b/lib/dpkg/execname.c
index 6529fcfd0..b43ab9910 100644
--- a/lib/dpkg/execname.c
+++ b/lib/dpkg/execname.c
@@ -37,12 +37,19 @@
 #include <stdio.h>
 #include <unistd.h>
 
+#if defined(__GNU__)
+#include <hurd.h>
+#include <ps.h>
+#endif
+
 #if defined(__APPLE__) && defined(__MACH__)
 #include <libproc.h>
 #endif
 
 #include <dpkg/dpkg.h>
+#if defined(__sun)
 #include <dpkg/file.h>
+#endif
 #include <dpkg/execname.h>
 
 #if defined(_AIX) && defined(HAVE_STRUCT_PSINFO)
@@ -96,15 +103,26 @@ dpkg_get_pid_execname(pid_t pid)
        lcontents[nread] = '\0';
        execname = lcontents;
 #elif defined(__GNU__)
+       struct ps_context *pc;
        struct proc_stat *ps;
+       error_t err;
+
+       if (pid < 0)
+               return NULL;
+
+       err = ps_context_create(getproc(), &pc);
+       if (err)
+               return NULL;
 
-       ps = get_proc_stat(pid, PSTAT_ARGS);
-       if (ps == NULL)
+       err = ps_context_find_proc_stat(pc, pid, &ps);
+       if (err)
                return NULL;
 
        /* On old Hurd systems we have to use the argv[0] value, because
         * there is nothing better. */
-       execname = proc_stat_args(ps);
+       if (proc_stat_set_flags(ps, PSTAT_ARGS) == 0 &&
+           (proc_stat_flags(ps) & PSTAT_ARGS))
+               execname = proc_stat_args(ps);
 
 #ifdef PSTAT_EXE
        /* On new Hurd systems we can use the correct value, as long
@@ -116,6 +134,8 @@ dpkg_get_pid_execname(pid_t pid)
            proc_stat_exe(ps)[0] != '\0')
                execname = proc_stat_exe(ps);
 #endif
+
+       ps_context_free(pc);
 #elif defined(__sun)
        char filename[64];
        struct varbuf vb = VARBUF_INIT;
diff --git a/lib/dpkg/libdpkg.pc.in b/lib/dpkg/libdpkg.pc.in
index 1a9159498..b658d59ac 100644
--- a/lib/dpkg/libdpkg.pc.in
+++ b/lib/dpkg/libdpkg.pc.in
@@ -7,5 +7,5 @@ Name: libdpkg
 Description: Debian package management system library
 Version: @VERSION@
 Libs: -L${libdir} -ldpkg
-Libs.private: @MD_LIBS@ @Z_LIBS@ @LZMA_LIBS@ @ZSTD_LIBS@ @BZ2_LIBS@
+Libs.private: @PS_LIBS@ @MD_LIBS@ @Z_LIBS@ @LZMA_LIBS@ @ZSTD_LIBS@ @BZ2_LIBS@
 Cflags: -I${includedir}

-- 
Dpkg.Org's dpkg

Reply via email to