issignals.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
  24. /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
  25. /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
  26. /*%% (c) Copyright 1993, 1994 Novell, Inc. */
  27. /*%% $XConsortium: issignals.c /main/3 1995/10/23 11:44:41 rswiston $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * issignals.c
  33. *
  34. * Description:
  35. * Signal masking functions
  36. */
  37. #include "isam_impl.h"
  38. #include <signal.h>
  39. /*
  40. * _issignal_mask() is called at the beginning of each ISAM update operation
  41. * to mask signals for the duration of the operation. _issignals_unmask()
  42. * is called at the end of the operation to restore the original signal
  43. * mask.
  44. *
  45. * _issignals_cntl() enables/disables this signal masking facility.
  46. * (the default is "mask the signals").
  47. *
  48. * The variable already_masked is used to provide more robustness: it
  49. * will prevent permanent signal masking due to bugs in the ISAM package.
  50. * The permanent masking of signals would happen if _issignals_mask()
  51. * were called twice in a row.
  52. */
  53. static int do_mask = 1; /* default value */
  54. static int already_masked;
  55. static sigset_t oldmask;
  56. static sigset_t allsignals;
  57. /* opt, 1 will enable masking, 0 will disable masking */
  58. int _issignals_cntl(int opt)
  59. {
  60. int oldmask = do_mask;
  61. do_mask = opt ? 1 : 0;
  62. return (oldmask);
  63. }
  64. void
  65. _issignals_mask(void)
  66. {
  67. if (do_mask && !already_masked) {
  68. (void) sigfillset(&allsignals);
  69. (void) sigdelset(&allsignals, SIGTRAP);
  70. (void) sigdelset(&allsignals, SIGSEGV);
  71. (void) sigdelset(&allsignals, SIGILL);
  72. (void) sigdelset(&allsignals, SIGBUS);
  73. (void) sigprocmask(SIG_SETMASK, &allsignals, &oldmask);
  74. already_masked = 1;
  75. }
  76. }
  77. void
  78. _issignals_unmask(void)
  79. {
  80. if (do_mask) {
  81. (void)sigprocmask(SIG_SETMASK, &oldmask, NULL);
  82. already_masked = 0;
  83. }
  84. }