File: poll.c

package info (click to toggle)
dmtcp 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,496 kB
  • sloc: cpp: 33,592; ansic: 28,099; sh: 6,735; makefile: 1,950; perl: 1,690; python: 1,241; asm: 138; java: 13
file content (29 lines) | stat: -rw-r--r-- 773 bytes parent folder | download | duplicates (3)
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
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <poll.h>
#include <errno.h>

int main() {
  int pipefd[2];
  if (pipe(pipefd) == -1) {
    perror("pipe");
    exit(1);
  }
  int fd = open("/dev/null", O_RDONLY);
  struct pollfd pfd[1];
  pfd[0].fd = pipefd[0];
  pfd[0].events = POLLIN;
  /* poll should never return, since we can't read from /dev/in.
   * 'man 7 signal' says that any arriving signal (e.g. CKPT signal)
   *   will cause poll to return -1 with EINTR.
   * The DMTCP poll wrapper should restart poll() before it can return.
   */
  int rc = poll(pfd, 1, -1); /* -1 means infinite timeout */
  printf("ERROR:  rc = %d; errno = %d\n", rc, errno);
  close(fd);
  return 1;
}