test-container: disable ld.so system cache on DSO detection
[glibc.git] / posix / tst-execlp2.c
blob4c3afb853974c6ad013066f3139904c13658947d
1 #include <errno.h>
2 #include <libgen.h>
3 #undef basename
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <sys/stat.h>
11 static void prepare (int argc, char *argv[]);
12 static int do_test (void);
13 #define PREPARE(argc, argv) prepare (argc, argv)
14 #define TEST_FUNCTION do_test ()
15 #include "../test-skeleton.c"
18 static char *copy;
20 static void
21 prepare (int argc, char *argv[])
23 char *buf;
24 int off;
26 buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]);
27 if (system (buf) != 0)
29 puts ("system failed");
30 exit (1);
33 /* Make it not executable. */
34 copy = buf + off;
35 if (chmod (copy, 0666) != 0)
37 puts ("chmod failed");
38 exit (1);
41 add_temp_file (copy);
45 static int
46 do_test (void)
48 /* Make sure we do not find a binary with the name we are going to
49 use. */
50 char *bindir = strdupa (copy);
51 bindir = canonicalize_file_name (dirname (bindir));
52 if (bindir == NULL)
54 puts ("canonicalize_file_name failed");
55 return 1;
58 char *path = xasprintf ("%s:../libio:../elf", bindir);
60 setenv ("PATH", path, 1);
62 char *prog = basename (copy);
63 errno = 0;
64 execlp (prog, prog, NULL);
66 if (errno != EACCES)
68 printf ("errno = %d (%m), expected EACCES\n", errno);
69 return 1;
72 return 0;