]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Port getprogname() to AIX
authorGuillem Jover <guillem@hadrons.org>
Mon, 17 Apr 2023 22:44:49 +0000 (00:44 +0200)
committerGuillem Jover <guillem@hadrons.org>
Fri, 21 Apr 2023 03:20:27 +0000 (05:20 +0200)
Get the program name from the COMM field from the proc filesystem.

We could use instead the information from the psinfo binary file under
/proc, but that seems to have a shorter string limit.

src/progname.c

index b62ecd417474338dc85b74853b63e633ac33d22f..56d91eca5127ebe3edd8c7e60db8a9ab3bc0d649 100644 (file)
@@ -62,6 +62,14 @@ getprogname(void)
        /* getexecname(3) returns an absolute pathname, normalize it. */
        if (__progname == NULL)
                setprogname(getexecname());
+#elif defined(_AIX)
+       if (__progname == NULL) {
+               struct procentry64 procs;
+               pid_t pid = getpid ();
+
+               if (getprocs64(&procs, sizeof procs, NULL, 0, &pid, 1) > 0)
+                       __progname = strdup(procs.pi_comm);
+       }
 #elif defined(_WIN32)
        if (__progname == NULL) {
                WCHAR *wpath = NULL;