nested_note.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * This file is part of Jehanne.
  3. *
  4. * Copyright (C) 2017 Giacomo Tesio <giacomo@tesio.it>
  5. *
  6. * Jehanne is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, version 2 of the License.
  9. *
  10. * Jehanne is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <u.h>
  19. #include <lib9.h>
  20. int done;
  21. int waited;
  22. void
  23. handler(void *v, char *s)
  24. {
  25. int i;
  26. if(strcmp(s, "stop") == 0){
  27. done = 1;
  28. print("stop note received; done = %d\n", done);
  29. }else{
  30. print("waiting after %s", s);
  31. for(i = 0; i < 1000*1000; ++i)
  32. if(i % 4999 == 0)
  33. print(".");
  34. print("\n");
  35. print("wait after %s terminated\n", s);
  36. waited++;
  37. }
  38. noted(NCONT);
  39. }
  40. void
  41. main(int argc, char**argv)
  42. {
  43. int fd;
  44. if(argc > 1){
  45. fd = ocreate(argv[1], OWRITE, 0666);
  46. dup(fd, 1);
  47. close(fd);
  48. }
  49. if (notify(handler)){
  50. fprint(2, "%r\n");
  51. exits("notify fails");
  52. }
  53. print("note handler installed\n");
  54. while(!done)
  55. sleep(100);
  56. if(waited == 2){
  57. print("PASS\n");
  58. exits("PASS");
  59. }
  60. print("%d notes received\n", waited);
  61. exits("FAIL");
  62. }