File: console.c

package info (click to toggle)
criu 4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,500 kB
  • sloc: ansic: 139,280; python: 7,484; sh: 3,824; java: 2,799; makefile: 2,659; asm: 1,137; perl: 206; xml: 117; exp: 45
file content (57 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#include <sys/stat.h>
#include <sys/types.h>
#include <sys/sysmacros.h>

#include "zdtmtst.h"

const char *test_doc = "Check c/r for console device";
const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>";

char *filename;
TEST_OPTION(filename, string, "file name", 1);

int main(int argc, char **argv)
{
	struct stat st1, st2;
	int fd;

	test_init(argc, argv);

	if (mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, makedev(5, 1))) {
		pr_perror("Can't create console %s", filename);
		return 1;
	}

	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		pr_perror("Open console %s failed", filename);
		return 1;
	}

	if (fstat(fd, &st1)) {
		pr_perror("Can't stat %s console", filename);
		return 1;
	}

	test_daemon();
	test_waitsig();

	if (fstat(fd, &st2)) {
		pr_perror("Can't stat %s console", filename);
		return 1;
	}

	if (st1.st_rdev != st2.st_rdev) {
		fail("Console rdev mismatch %x != %x on %s", (int)st1.st_rdev, (int)st2.st_rdev, filename);
		return 1;
	}

	pass();
	return 0;
}