main.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program 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 this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "test.h"
  20. #if defined(PJ_SUNOS) && PJ_SUNOS!=0
  21. #include <signal.h>
  22. static void init_signals()
  23. {
  24. struct sigaction act;
  25. memset(&act, 0, sizeof(act));
  26. act.sa_handler = SIG_IGN;
  27. sigaction(SIGALRM, &act, NULL);
  28. }
  29. #elif (PJ_LINUX || PJ_DARWINOS) && defined(PJ_HAS_EXECINFO_H) && PJ_HAS_EXECINFO_H != 0
  30. #include <execinfo.h>
  31. #include <signal.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <unistd.h>
  35. static void print_stack(int sig)
  36. {
  37. void *array[16];
  38. size_t size;
  39. size = backtrace(array, 16);
  40. fprintf(stderr, "Error: signal %d:\n", sig);
  41. backtrace_symbols_fd(array, size, STDERR_FILENO);
  42. exit(1);
  43. }
  44. static void init_signals(void)
  45. {
  46. signal(SIGSEGV, &print_stack);
  47. signal(SIGABRT, &print_stack);
  48. }
  49. #else
  50. #define init_signals()
  51. #endif
  52. #define boost()
  53. int main(int argc, char *argv[])
  54. {
  55. int rc;
  56. int interractive = 0;
  57. int no_trap = 0;
  58. boost();
  59. while (argc > 1) {
  60. char *arg = argv[--argc];
  61. if (*arg=='-' && *(arg+1)=='i') {
  62. interractive = 1;
  63. } else if (*arg=='-' && *(arg+1)=='n') {
  64. no_trap = 1;
  65. }
  66. }
  67. if (!no_trap) {
  68. init_signals();
  69. }
  70. rc = test_main();
  71. if (interractive) {
  72. char s[10];
  73. puts("");
  74. puts("Press <ENTER> to exit");
  75. if (!fgets(s, sizeof(s), stdin))
  76. return rc;
  77. }
  78. return rc;
  79. }