Mercurial > gnulib
changeset 39904:c9d7c2bfa3f1
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Thu, 11 Oct 2018 20:07:00 +0200 |
parents | cadbcf6826fd |
children | c3122bb580fe |
files | ChangeLog lib/getprogname.c |
diffstat | 2 files changed, 57 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- 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 <bruno@clisp.org> + + 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 <bruno@clisp.org> getprogname: Work around program name truncation when possible.
--- 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 = "?"; }