1 /*
2 * Check success injection.
3 *
4 * Copyright (c) 2017 Elvira Khabirova <lineprinter0@gmail.com>
5 * Copyright (c) 2017-2021 The strace developers.
6 * All rights reserved.
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #include "tests.h"
12 #include "scno.h"
13
14 #include <assert.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <sys/stat.h>
19
20 int
21 main(int argc, char *argv[])
22 {
23 assert(argc == 2);
24
25 static const char dir[] = "..";
26 struct stat before, after;
27
28 if (stat(".", &before))
29 perror_msg_and_fail("stat");
30
31 long rval = syscall(__NR_chdir, dir);
32
33 if (stat(".", &after))
34 perror_msg_and_fail("stat");
35
36 if (before.st_dev != after.st_dev || before.st_ino != after.st_ino)
37 error_msg_and_fail("syscall succeeded");
38 if (atol(argv[1]) != rval)
39 error_msg_and_fail("expected retval %s, got retval %ld",
40 argv[1], rval);
41
42 printf("chdir(\"%s\") = %ld (INJECTED)\n", dir, rval);
43
44 puts("+++ exited with 0 +++");
45 return 0;
46 }