iserror.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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: iserror.c /main/3 1995/10/23 11:38:16 rswiston $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * iserror.c
  33. *
  34. * Description:
  35. * NetISAM error handling functions.
  36. *
  37. */
  38. #include "isam_impl.h"
  39. #include <unistd.h>
  40. #include <errno.h>
  41. #include <stdlib.h>
  42. #include <syslog.h>
  43. /*
  44. * _isfatal_error(msg)
  45. *
  46. * Fatal error. Display message and terminate program.
  47. */
  48. static int (*fatal_error_user_handler)(); /* set by iscntl(..,ISCNTL_FATAL,..) */
  49. void
  50. _isfatal_error(char *msg)
  51. {
  52. int logerr;
  53. if (fatal_error_user_handler) {
  54. logerr = fatal_error_user_handler(msg); /* User returns 1 in order
  55. * to use syslog()
  56. */
  57. }
  58. else
  59. logerr = 1;
  60. if (logerr) {
  61. openlog("NetISAM", LOG_PID, LOG_USER);
  62. /* Free one UNIX for syslog */
  63. (void)close(0);
  64. syslog(LOG_ERR, "Fatal error: %s - UNIX errno %d", msg, errno);
  65. closelog();
  66. }
  67. exit (1);
  68. }
  69. void
  70. _isfatal_error1(char *msg)
  71. {
  72. int logerr;
  73. if (fatal_error_user_handler) {
  74. logerr = fatal_error_user_handler(msg); /* User returns 1 in order
  75. * to use syslog()
  76. */
  77. }
  78. else
  79. logerr = 1;
  80. if (logerr) {
  81. openlog("NetISAM", LOG_PID, LOG_USER);
  82. /* Free one UNIX for syslog */
  83. (void)close(0);
  84. syslog(LOG_ERR, "Fatal error: %s - UNIX errno %d", msg, errno);
  85. closelog();
  86. }
  87. }
  88. void
  89. _isam_warning(char *msg)
  90. {
  91. openlog("NetISAM", LOG_PID, LOG_USER);
  92. syslog(LOG_ERR, "%s", msg);
  93. }
  94. /* Set user specified fatal_error handler */
  95. int _isfatal_error_set_func(int(*func)())
  96. {
  97. #if 0
  98. int (*oldfunc)();
  99. oldfunc = fatal_error_user_handler;
  100. #endif
  101. fatal_error_user_handler = func;
  102. return (0);
  103. }
  104. /*
  105. * _setiserrno2(error, isstat1, isstat2)
  106. *
  107. * Set iserrno variable.
  108. */
  109. void
  110. _setiserrno2(int error, int is1, int is2)
  111. {
  112. iserrno = error;
  113. isstat1 = is1;
  114. isstat2 = is2;
  115. }
  116. /*
  117. * _seterr_errcode(errcode)
  118. *
  119. * Set all error and status variable from errcode structure.
  120. */
  121. void
  122. _seterr_errcode(struct errcode *errcode)
  123. {
  124. iserrno = errcode->iserrno;
  125. isstat1 = errcode->isstat[0];
  126. isstat2 = errcode->isstat[1];
  127. isstat3 = errcode->isstat[2];
  128. isstat4 = errcode->isstat[3];
  129. }