none/tests/fdleak_cmsg_supp.supp: Add suppressions for older glibc
[valgrind.git] / none / tests / solaris / proc_psinfo.c
blobda4109f66be14a40bcd83a7e0694538d048c2f4f
1 /*
2 * Reads /proc/self/psinfo such that it can be tested whether Valgrind
3 * intercepts the system calls that access this pseudo-file.
4 */
6 #include <fcntl.h>
7 #include <limits.h>
8 #include <procfs.h>
9 #include <stdio.h>
10 #include <unistd.h>
12 static void test_psinfo(int op, const char *label,
13 const char *path)
15 int fd;
16 if (op == 0) {
17 printf("open for %s:\n", label);
19 fd = open(path, O_RDONLY);
20 if (fd < 0) {
21 perror("open");
22 return;
24 } else {
25 printf("openat for %s:\n", label);
27 fd = openat(AT_FDCWD, path, O_RDONLY);
28 if (fd < 0) {
29 perror("openat");
30 return;
34 psinfo_t psinfo;
35 ssize_t bytes = read(fd, &psinfo, sizeof(psinfo));
36 if (bytes != sizeof(psinfo)) {
37 perror("read");
38 return;
41 printf("fname: %s\n", psinfo.pr_fname);
42 printf("psargs: %s\n", psinfo.pr_psargs);
44 printf("argc: %d\n", psinfo.pr_argc);
45 unsigned int i;
46 char **argv = (char **) psinfo.pr_argv;
47 for (i = 0; i < psinfo.pr_argc; i++) {
48 printf("argv[%u]: %s\n", i, argv[i]);
51 close(fd);
54 int main(int argc, const char *argv[])
56 char path[PATH_MAX];
57 snprintf(path, sizeof(path), "/proc/%ld/psinfo", (long int) getpid());
59 test_psinfo(0, "/proc/self/psinfo", "/proc/self/psinfo");
60 printf("\n");
61 test_psinfo(0, "/proc/<pid>/psinfo", path);
62 printf("\n");
64 test_psinfo(1, "/proc/self/psinfo", "/proc/self/psinfo");
65 printf("\n");
66 test_psinfo(1, "/proc/<pid>/psinfo", path);
68 return 0;