aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/bison/lib/getprogname.c
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.com>2024-06-29 11:45:54 +0300
committerthegeorg <thegeorg@yandex-team.com>2024-06-29 11:54:41 +0300
commit9158d9115725ca7f4ada745ec55eddd5747bc61e (patch)
treef262cd6d7a98bb367943a4918b6963a7800f3937 /contrib/tools/bison/lib/getprogname.c
parent632b3cedb8e12fbbb0bcd1bdbf7ec5686725b7e9 (diff)
downloadydb-9158d9115725ca7f4ada745ec55eddd5747bc61e.tar.gz
Update contrib/tools/bison to 3.2.4
78e59a97f3fde03511ddb9969cd1daabbaf998bd
Diffstat (limited to 'contrib/tools/bison/lib/getprogname.c')
-rw-r--r--contrib/tools/bison/lib/getprogname.c70
1 files changed, 67 insertions, 3 deletions
diff --git a/contrib/tools/bison/lib/getprogname.c b/contrib/tools/bison/lib/getprogname.c
index 43f37505ea..284581da24 100644
--- a/contrib/tools/bison/lib/getprogname.c
+++ b/contrib/tools/bison/lib/getprogname.c
@@ -110,9 +110,73 @@ getprogname (void)
first = 0;
pid_t pid = getpid ();
struct pst_status status;
- p = (0 < pstat_getproc (&status, sizeof status, 0, pid)
- ? strdup (status.pst_ucomm)
- : NULL);
+ if (pstat_getproc (&status, sizeof status, 0, pid) > 0)
+ {
+ char *ucomm = status.pst_ucomm;
+ char *cmd = status.pst_cmd;
+ 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
+ {
+# 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 = "?";
}