rename
[trinity.git] / fd-pipes.c
blob1adf66d58ed7dcbec9bd338b8f1fb1d7c853afd3
1 /* Pipe FD related functions. */
3 #include <errno.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <sys/epoll.h>
9 #include <sys/eventfd.h>
11 #include "files.h"
12 #include "log.h"
13 #include "net.h"
14 #include "params.h"
15 #include "pids.h"
16 #include "pipes.h"
17 #include "random.h"
18 #include "sanitise.h"
19 #include "shm.h"
20 #include "trinity.h"
22 void open_pipes(void)
24 int pipes[2];
25 unsigned int i;
27 for (i = 0; i < MAX_PIPE_FDS; i+=2) {
28 if (pipe(pipes) < 0) {
29 perror("pipe fail.\n");
30 exit(EXIT_FAILURE);
32 shm->pipe_fds[i] = pipes[0];
33 shm->pipe_fds[i+1] = pipes[1];
35 output(2, "fd[%d] = pipe\n", shm->pipe_fds[i]);
36 output(2, "fd[%d] = pipe\n", shm->pipe_fds[i+1]);
40 int rand_pipe_fd(void)
42 return shm->pipe_fds[rand() % MAX_PIPE_FDS];