Fix link errors with GCC 10 and binutils 2.34 on Fedora
[pintos-anon] / src / tests / userprog / child-rox.c
1 /* Child process run by rox-child and rox-multichild tests.
2    Opens and tries to write to its own executable, verifying that
3    that is disallowed.
4    Then recursively executes itself to the depth indicated by the
5    first command-line argument. */
6
7 #include <ctype.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <syscall.h>
11 #include "tests/lib.h"
12
13 static void
14 try_write (void) 
15 {
16   int handle;
17   char buffer[19];
18
19   quiet = true;
20   CHECK ((handle = open ("child-rox")) > 1, "open \"child-rox\"");
21   quiet = false;
22
23   CHECK (write (handle, buffer, sizeof buffer) == 0,
24          "try to write \"child-rox\"");
25   
26   close (handle);
27 }
28
29 int
30 main (int argc UNUSED, char *argv[]) 
31 {
32   test_name = "child-rox";
33
34   msg ("begin");
35   try_write ();
36
37   if (!isdigit (*argv[1]))
38     fail ("bad command-line arguments");
39   if (atoi (argv[1]) > 1) 
40     {
41       char cmd[128];
42       int child;
43       
44       snprintf (cmd, sizeof cmd, "child-rox %d", atoi (argv[1]) - 1);
45       CHECK ((child = exec (cmd)) != -1, "exec \"%s\"", cmd);
46       quiet = true;
47       CHECK (wait (child) == 12, "wait for \"child-rox\"");
48       quiet = false;
49     }
50
51   try_write ();
52   msg ("end");
53
54   return 12;
55 }