Back to index

glibc  2.9
tst-execve2.c
Go to the documentation of this file.
00001 #include <errno.h>
00002 #include <stdio.h>
00003 #include <unistd.h>
00004 #include <sys/stat.h>
00005 
00006 
00007 static void prepare (int argc, char *argv[]);
00008 static int do_test (void);
00009 #define PREPARE(argc, argv) prepare (argc, argv)
00010 #define TEST_FUNCTION do_test ()
00011 #include "../test-skeleton.c"
00012 
00013 
00014 static char *copy;
00015 
00016 static void
00017 prepare (int argc, char *argv[])
00018 {
00019   char *buf;
00020   int off;
00021   asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]);
00022   if (buf == NULL)
00023     {
00024       puts ("asprintf  failed");
00025       exit (1);
00026     }
00027   if (system (buf) != 0)
00028     {
00029       puts ("system  failed");
00030       exit (1);
00031     }
00032 
00033   /* Make it not executable.  */
00034   copy = buf + off;
00035   if (chmod (copy, 0666) != 0)
00036     {
00037       puts ("chmod  failed");
00038       exit (1);
00039     }
00040 
00041   add_temp_file (copy);
00042 }
00043 
00044 
00045 static int
00046 do_test (void)
00047 {
00048   char *argv[] = { copy, NULL };
00049   char *envp[] = { (char *) "FOO=BAR", NULL };
00050 
00051   errno = 0;
00052   execve (copy, argv, envp);
00053 
00054   if (errno != EACCES)
00055     {
00056       printf ("errno = %d (%m), expected EACCES\n", errno);
00057       return 1;
00058     }
00059 
00060   return 0;
00061 }