none/tests/fdleak_cmsg_supp.supp: Add suppressions for older glibc
[valgrind.git] / none / tests / solaris / proc_auxv.c
blob4af8f57c8564518a42f7d72221835573a3bd21a1
1 /* Test if /proc/{self,$PID}/auxv is correctly simulated and that the aux
2 vector contains plausible values. */
4 #include <errno.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <sys/auxv.h>
9 #include <sys/fcntl.h>
11 static int check_file(const char *path, auxv_t *auxv)
13 auxv_t rauxv;
14 int res = 1;
15 FILE *fi;
17 if (!(fi = fopen(path, "r"))) {
18 perror("fopen");
19 return 1;
21 while (1) {
22 if (fread(&rauxv, sizeof(rauxv), 1, fi) != 1) {
23 if (ferror(fi)) {
24 perror("fread");
25 goto out;
27 fprintf(stderr, "unexpected EOF\n");
28 goto out;
30 if (memcmp(auxv, &rauxv, sizeof(rauxv))) {
31 fprintf(stderr, "incorrect auxv in %s\n", path);
32 fprintf(stderr, "expected: type=%d, val=%ld\n", auxv->a_type,
33 auxv->a_un.a_val);
34 fprintf(stderr, "got: type=%d, val=%ld\n", rauxv.a_type,
35 rauxv.a_un.a_val);
36 goto out;
39 if (auxv->a_type == AT_NULL)
40 break;
42 auxv++;
45 res = 0;
47 out:
48 fclose(fi);
49 return res;
52 int main(int argc, char *argv[], char *envp[])
54 auxv_t *auxv;
55 char buf[128];
57 /* Find aux vector. */
58 while (*envp)
59 envp++;
60 auxv = (auxv_t*)(envp + 1);
62 /* /proc/self/auxv check */
63 if (check_file("/proc/self/auxv", auxv))
64 return 1;
66 /* /proc/$PID/auxv check */
67 snprintf(buf, sizeof(buf), "/proc/%ld/auxv", (long)getpid());
68 if (check_file(buf, auxv))
69 return 1;
71 /* AT_SUN_EXECNAME check */
72 while (auxv->a_type != AT_NULL) {
73 if (auxv->a_type == AT_SUN_EXECNAME) {
74 const char *execname = auxv->a_un.a_ptr;
75 if (!execname) {
76 fprintf(stderr, "AT_SUN_EXECNAME is null\n");
77 return 1;
79 if (access(execname, R_OK | X_OK)) {
80 fprintf(stderr, "AT_SUN_EXECNAME (%s) is invalid: %s\n",
81 execname, strerror(errno));
82 return 1;
84 break;
86 auxv++;
89 return 0;