Debian Codegraph @

usr/lib/common/aix/short_name.c

raw symbols SCIP
1 /*
2 * COPYRIGHT (c) International Business Machines Corp. 2024
3 *
4 * This program is provided under the terms of the Common Public License,
5 * version 1.0 (CPL-1.0). Any use, reproduction or distribution for this
6 * software constitutes recipient's acceptance of CPL-1.0 terms which can be
7 * found in the file LICENSE file or at
8 * https://opensource.org/licenses/cpl1.0.php
9 */
10 #if defined(_AIX)
11 #include <stdio.h>
12 #include <sys/procfs.h>
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <errno.h>
16 #include <string.h>
17
18 /* program_invocation_short_name is GNU extension */
19 char program_invocation_short_name[256 + 1] = { NULL, };
20
21 void populate_progname(void) {
22 struct psinfo ps;
23 int psfd;
24
25 snprintf(program_invocation_short_name, 256, "/proc/%lld/psinfo", getpid());
26 psfd = open(program_invocation_short_name, O_RDONLY);
27 if (psfd == -1) {
28 fprintf(stderr,
29 "Failed to open procfs to read cmdname: %s\n", strerror(errno));
30 return;
31 }
32
33 if (read(psfd, &ps, sizeof(ps)) == -1) {
34 fprintf(stderr, "Failed to populate psinfo: %s\n", strerror(errno));
35 return;
36 }
37 close(psfd);
38 strncpy(program_invocation_short_name, ps.pr_fname, PRFNSZ);
39 }
40 #endif