tst-signalfd.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* vi: set sw=4 ts=4 sts=4: */
  2. /*
  3. * signalfd test for uClibc
  4. * Copyright (C) 2012 by Kevin Cernekee <cernekee@gmail.com>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <unistd.h>
  12. #include <errno.h>
  13. #include <error.h>
  14. #include <signal.h>
  15. #include <sys/signalfd.h>
  16. #include <sys/fcntl.h>
  17. static int
  18. do_test(void)
  19. {
  20. int fd, ret, result = 0;
  21. struct signalfd_siginfo ssi;
  22. sigset_t mask;
  23. sigemptyset(&mask);
  24. sigaddset(&mask, SIGUSR1);
  25. sigprocmask(SIG_BLOCK, &mask, NULL);
  26. fd = signalfd(-1, &mask, SFD_NONBLOCK);
  27. if (fd < 0) {
  28. printf("signalfd() failed: %s\n", strerror(errno));
  29. result = 1;
  30. }
  31. /* this should return immediately with EAGAIN due to SFD_NONBLOCK */
  32. memset(&ssi, 0, sizeof(ssi));
  33. ret = read(fd, &ssi, sizeof(ssi));
  34. if (ret != -1 || errno != EAGAIN) {
  35. error(0, 0, "first read() returned %d", ret);
  36. result = 1;
  37. }
  38. kill(getpid(), SIGUSR1);
  39. /* this should return a struct ssi indicating receipt of SIGUSR1 */
  40. ret = read(fd, &ssi, sizeof(ssi));
  41. if (ret != sizeof(ssi)) {
  42. error(0, 0, "second read() returned %d", ret);
  43. result = 1;
  44. }
  45. if (ssi.ssi_signo != SIGUSR1) {
  46. error(0, 0, "ssi contains bogus signo");
  47. result = 1;
  48. }
  49. return result;
  50. }
  51. #define TIMEOUT 5
  52. #define TEST_FUNCTION do_test ()
  53. #include "../test-skeleton.c"