File: net_lock_socket_iptables.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 (69 lines) | stat: -rw-r--r-- 1,275 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
58
59
60
61
62
63
64
65
66
67
68
69
#include "zdtmtst.h"

#if defined(ZDTM_IPV6)
#define ZDTM_FAMILY AF_INET6
#else
#define ZDTM_FAMILY AF_INET
#endif

const char *test_doc = "Check that sockets are locked between dump and restore\n";
const char *test_author = "Zeyad Yasser <zeyady98@gmail.com>";

#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <sys/socket.h>

static int port = 8880;
#define SYNCFILE_PATH "socket_lock.sync"

int main(int argc, char **argv)
{
	char buf[5];
	int fd_s, fd_sock, buf_len;
	FILE *f_sync;

	test_init(argc, argv);

	if ((fd_s = tcp_init_server(ZDTM_FAMILY, &port)) < 0) {
		pr_err("initializing server failed\n");
		return 1;
	}

	// Server is ready to accept sockets
	f_sync = fopen(SYNCFILE_PATH, "w");
	if (f_sync == NULL) {
		pr_perror("cannot create sync file");
		return 1;
	}
#if defined(ZDTM_IPV6)
	if (fprintf(f_sync, "ipv6") < 0) {
#else
	if (fprintf(f_sync, "ipv4") < 0) {
#endif
		pr_perror("cannot write to sync file");
		return 1;
	}
	fclose(f_sync);

	fd_sock = tcp_accept_server(fd_s);

	test_daemon();
	test_waitsig();

	buf_len = recv(fd_sock, buf, 3, MSG_WAITALL);
	if (buf_len < 0) {
		pr_perror("read less then have to");
		return 1;
	}

	if (!strncmp(buf, "ABC", 3))
		pass();
	else
		fail();

	close(fd_sock);
	close(fd_s);

	return 0;
}