# HG changeset patch # User Bruno Haible # Date 1539281220 -7200 # Node ID c9d7c2bfa3f12300d57897ae69e77e5f9bef3964 # Parent cadbcf6826fdce2c2fa90f82c773402527c98e89 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 -r cadbcf6826fd -r c9d7c2bfa3f1 ChangeLog --- a/ChangeLog Thu Oct 11 18:24:51 2018 +0200 +++ b/ChangeLog Thu Oct 11 20:07:00 2018 +0200 @@ -1,3 +1,9 @@ +2018-10-11 Bruno Haible + + 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. + 2018-10-11 Bruno Haible getprogname: Work around program name truncation when possible. diff -r cadbcf6826fd -r c9d7c2bfa3f1 lib/getprogname.c --- a/lib/getprogname.c Thu Oct 11 18:24:51 2018 +0200 +++ b/lib/getprogname.c Thu Oct 11 20:07:00 2018 +0200 @@ -112,31 +112,71 @@ 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 = "?"; }