File: libfault.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 (31 lines) | stat: -rw-r--r-- 830 bytes parent folder | download | duplicates (2)
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
#define _GNU_SOURCE
#include <unistd.h>
#include <dlfcn.h>
#include <errno.h>

ssize_t (*original_pread)(int fd, void *buf, size_t count, off_t offset) = NULL;

/**
 * This function is a wrapper around pread() that is used for testing CRIU's
 * handling of cases where pread() returns less data than requested.
 *
 * pmc_fill() in criu/pagemap.c is a good example of where this can happen.
 */
ssize_t pread64(int fd, void *buf, size_t count, off_t offset)
{
	if (!original_pread) {
		original_pread = dlsym(RTLD_NEXT, "pread");
		if (!original_pread) {
			errno = EIO;
			return -1;
		}
	}

	/* The following aims to simulate the case when pread() returns less
	 * data than requested. We need to ensure that CRIU handles such cases. */
	if (count > 2048) {
		count -= 1024;
	}

	return original_pread(fd, buf, count, offset);
}