7 #include <sys/eventfd.h>
23 static int get_new_random_fd(void)
31 if (do_specific_proto
== TRUE
)
38 * Sometimes, we can get here without any fd's setup.
39 * If this happens, we divide by zero if we pick case 0 because
42 * When this circumstance occurs, we just force it to use another network socket.
44 * FIXME: A better solution would be to like, actually open an fd. duh.
55 /* When using victim files, sockets can be 0.
56 * Use files as a fallback, or pipes if no files are open.
58 if (nr_sockets
== 0) {
65 fd
= shm
->sockets
[rand() % nr_sockets
].fd
;
73 if (shm
->perf_fds
[0] == 0) /* perf unavailable/disabled. */
84 fd
= rand_eventfd_fd();
92 int get_random_fd(void)
94 /* 25% chance of returning something new. */
95 if ((rand() % 4) == 0)
96 return get_new_random_fd();
98 /* the rest of the time, return the same fd as last time. */
100 if (shm
->fd_lifetime
== 0) {
101 shm
->current_fd
= get_new_random_fd();
102 shm
->fd_lifetime
= (rand() % max_children
) + 5;
106 if (shm
->current_fd
== 0) {
107 shm
->fd_lifetime
= 0;
111 return shm
->current_fd
;
114 unsigned int setup_fds(void)
118 /* If we have victim files, don't worry about sockets. */
119 if (victim_path
== NULL
) {
120 ret
= open_sockets();
133 if (no_files
== FALSE
)
139 void regenerate_fds(void)
141 if (no_files
== TRUE
)