source: branches/libc-0.6/src/libctests/glibc/posix/tst-execl2.c

Last change on this file was 2127, checked in by bird, 20 years ago

Don't execute in loop!

  • Property cvs2svn:cvs-rev set to 1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.2 KB
Line 
1#include <errno.h>
2#include <stdio.h>
3#include <unistd.h>
4#include <sys/stat.h>
5
6/* Nonzero if the program gets called via `exec'. */
7static int restart;
8#define CMDLINE_OPTIONS \
9 { "restart", no_argument, &restart, 1 },
10
11static void prepare (int argc, char *argv[]);
12static int do_test (void);
13#define PREPARE(argc, argv) prepare (argc, argv)
14#define TEST_FUNCTION do_test ()
15#include "../test-skeleton.c"
16
17
18static char *copy;
19
20static void
21prepare (int argc, char *argv[])
22{
23 char *buf;
24 int off;
25 asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]);
26 if (buf == NULL)
27 {
28 puts ("asprintf failed");
29 exit (1);
30 }
31 if (system (buf) != 0)
32 {
33 puts ("system failed");
34 exit (1);
35 }
36
37 /* Make it not executable. */
38 copy = buf + off;
39 if (chmod (copy, 0666) != 0)
40 {
41 puts ("chmod failed");
42 exit (1);
43 }
44
45 add_temp_file (copy);
46}
47
48
49static int
50do_test (void)
51{
52 if (restart)
53 {
54 printf ("error, child shouldn't run!\n");
55 return 1;
56 }
57 errno = 0;
58 execl (copy, copy, "--restart", NULL);
59
60 if (errno != EACCES)
61 {
62 printf ("errno = %d (%m), expected EACCES\n", errno);
63 return 1;
64 }
65
66 return 0;
67}
Note: See TracBrowser for help on using the repository browser.