| 12
 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
 
 | /*
 * Simple child to iterate over the entire fd list, opening/reading/closing as we go.
 */
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include "arch.h"	// page_size
#include "child.h"
#include "files.h"
#include "log.h"
#include "random.h"
#include "trinity.h"	// __unused__
int child_read_all_files(__unused__ int childno)
{
	struct stat sb;
	const char *filename;
	char *buffer;
	unsigned int i;
	int fd;
	int ret;
	for (i = 0; i < files_in_index; i++) {
		filename = fileindex[i];
		ret = (lstat(filename, &sb));
		if (ret == -1)
			continue;
		if (sb.st_size == 0)
			sb.st_size = page_size;
		buffer = malloc(sb.st_size);
		if (!buffer)
			continue;
		memset(buffer, 0, sb.st_size);
		fd = open(filename, O_RDONLY | O_NONBLOCK);
		if (!fd) {
			free(buffer);
			continue;
		}
		ret = read(fd, buffer, sb.st_size);
//		if (ret != -1)
//			output(0, "%s:%s\n", filename, buffer);
		if (rand_bool())
			sleep(1);
		free(buffer);
		close(fd);
	}
	return 0;
}
 |