bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getprogname: support for 32-bit programs on HP-UX


From: Bruno Haible
Subject: getprogname: support for 32-bit programs on HP-UX
Date: Thu, 11 Oct 2018 20:06:55 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-137-generic; KDE/5.18.0; x86_64; ; )

2018-10-11  Bruno Haible  <address@hidden>

        getprogname: Add support for 32-bit programs on HP-UX.
        * lib/getprogname.c (getprogname) [HP-UX]: If pstat_getproc fails,
        try the similar functions 32-bit programs on 64-bit HP-UX.

diff --git a/lib/getprogname.c b/lib/getprogname.c
index 4f97df4..2236d19 100644
--- a/lib/getprogname.c
+++ b/lib/getprogname.c
@@ -112,31 +112,71 @@ getprogname (void)
       struct pst_status status;
       if (pstat_getproc (&status, sizeof status, 0, pid) > 0)
         {
-          if (strlen (status.pst_ucomm) < PST_UCOMMLEN - 1)
-            p = status.pst_ucomm;
+          char *ucomm = status.pst_ucomm;
+          char *cmd = status.pst_cmd;
+          if (strlen (ucomm) < PST_UCOMMLEN - 1)
+            p = ucomm;
           else
             {
-              /* status.pst_ucomm is truncated to length PST_UCOMMLEN - 1.
-                 Look at status.pst_cmd instead.  */
-              char *space = strchr (status.pst_cmd, ' ');
+              /* ucomm is truncated to length PST_UCOMMLEN - 1.
+                 Look at cmd instead.  */
+              char *space = strchr (cmd, ' ');
               if (space != NULL)
                 *space = '\0';
-              p = strrchr (status.pst_cmd, '/');
+              p = strrchr (cmd, '/');
               if (p != NULL)
                 p++;
               else
-                p = status.pst_cmd;
+                p = cmd;
               if (strlen (p) > PST_UCOMMLEN - 1
-                  && memcmp (p, status.pst_ucomm, PST_UCOMMLEN - 1) == 0)
-                /* p is less truncated than status.pst_ucomm.  */
+                  && memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
+                /* p is less truncated than ucomm.  */
                 ;
               else
-                p = status.pst_ucomm;
+                p = ucomm;
             }
           p = strdup (p);
         }
       else
-        p = NULL;
+        {
+#  if !defined __LP64__
+          /* Support for 32-bit programs running in 64-bit HP-UX.
+             The documented way to do this is to use the same source code
+             as above, but in a compilation unit where '#define _PSTAT64 1'
+             is in effect.  I prefer a single compilation unit; the struct
+             size and the offsets are not going to change.  */
+          char status64[1216];
+          if (__pstat_getproc64 (status64, sizeof status64, 0, pid) > 0)
+            {
+              char *ucomm = status64 + 288;
+              char *cmd = status64 + 168;
+              if (strlen (ucomm) < PST_UCOMMLEN - 1)
+                p = ucomm;
+              else
+                {
+                  /* ucomm is truncated to length PST_UCOMMLEN - 1.
+                     Look at cmd instead.  */
+                  char *space = strchr (cmd, ' ');
+                  if (space != NULL)
+                    *space = '\0';
+                  p = strrchr (cmd, '/');
+                  if (p != NULL)
+                    p++;
+                  else
+                    p = cmd;
+                  if (strlen (p) > PST_UCOMMLEN - 1
+                      && memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
+                    /* p is less truncated than ucomm.  */
+                    ;
+                  else
+                    p = ucomm;
+                }
+              p = strdup (p);
+            }
+          else
+#  endif
+            p = NULL;
+        }
       if (!p)
         p = "?";
     }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]