| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#define PROBABILITY 0.9 |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#include <stdio.h> |
| 26 |
#include <stdlib.h> |
| 27 |
#include <errno.h> |
| 28 |
|
| 29 |
|
| 30 |
#include <sys/types.h> |
| 31 |
#include <sys/socket.h> |
| 32 |
#include <sys/stat.h> |
| 33 |
#include <fcntl.h> |
| 34 |
|
| 35 |
|
| 36 |
#define __USE_GNU |
| 37 |
#include <dlfcn.h> |
| 38 |
|
| 39 |
#include "interrupter.h" |
| 40 |
|
| 41 |
static int probability = PROBABILITY * RAND_MAX; |
| 42 |
|
| 43 |
static int maybe_interrupt() { |
| 44 |
if (rand() < probability) { |
| 45 |
return 1; |
| 46 |
} |
| 47 |
return 0; |
| 48 |
} |
| 49 |
|
| 50 |
DEFINE_INTERCEPT(read, ssize_t, int, void*, size_t); |
| 51 |
DEFINE_INTERCEPT(write, ssize_t, int, const void*, size_t); |
| 52 |
DEFINE_INTERCEPT(accept, int, int, struct sockaddr*, socklen_t*); |
| 53 |
DEFINE_INTERCEPT(creat, int, const char*, mode_t); |