iscntl.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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: iscntl.c /main/3 1995/10/23 11:36:59 rswiston $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * iscntl.c
  33. *
  34. * Description:
  35. * Generic control function
  36. */
  37. #if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
  38. #include <stdarg.h>
  39. #else
  40. #include <varargs.h>
  41. #endif
  42. #include "isam_impl.h"
  43. /*
  44. * err = iscntl(isfd, args)
  45. *
  46. * Functions:
  47. *
  48. * iscntl(isfd, ISCNTL_RPCS_TO_SET, tout) - Set timeout for short operations
  49. * iscntl(isfd, ISCNTL_RPCL_TO_SET, tout) - Set timeout for long operations
  50. * iscntl(isfd, ISCNTL_RPCS_TO_GET) - Get timeout for short operations
  51. * iscntl(isfd, ISCNTL_RPCL_TO_GET) - Get timeout for long operations
  52. * iscntl(isfd, ISCNTL_TCP_TO_SET) - Set TCP reconnect timeout
  53. * iscntl(isfd, ISCNTL_TCP_TO_GET) - Get TCP reconnect timeout
  54. *
  55. * iscntl(isfd, ISCNTL_APPLMAGIC_WRITE, string) - Write application magic
  56. * iscntl(isfd, ISCNTL_APPLMAGIC_READ, buf) - Read application magic
  57. *
  58. * iscntl(ALLISFD, ISCNTL_FDLIMIT_SET, n) - Set limit on UNIX fd use
  59. * iscntl(ALLISFD, ISCNTL_FDLIMIT_GET) - Set limit on UNIX fd use
  60. *
  61. * oldfunc = iscntl(ALLISFD, ISCNTL_FATAL, func) - Set fatal error handler
  62. * int func(msg) - Apllication handler
  63. * if 0 is returned, NetISAM will use openlog("NetISAM") and
  64. * syslog(ERR_LOG, msg) to log the error.
  65. *
  66. * iscntl(ALLISFD, ISCNTL_MASKSIGNALS, bool) 1 mask, 0 don't mask
  67. *
  68. * iscntl(isfd, ISCNTL_FSYNC) - synchronize a file's in-core state
  69. * with that on disk
  70. *
  71. */
  72. typedef int (* intfunc)();
  73. #if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
  74. int
  75. iscntl(int isfd, int func, ...)
  76. #else
  77. int
  78. iscntl(isfd, func, va_alist)
  79. int isfd;
  80. int func;
  81. va_dcl
  82. #endif
  83. {
  84. va_list pvar;
  85. int ret;
  86. #if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
  87. va_start(pvar, func);
  88. #else
  89. va_start(pvar);
  90. #endif
  91. switch (func) {
  92. case ISCNTL_MASKSIGNALS:
  93. ret = _issignals_cntl(va_arg(pvar, int));
  94. break;
  95. case ISCNTL_FATAL:
  96. ret = _isfatal_error_set_func(va_arg(pvar, intfunc));
  97. break;
  98. case ISCNTL_FDLIMIT_SET:
  99. ret = _watchfd_max_set(va_arg(pvar, int));
  100. break;
  101. case ISCNTL_FDLIMIT_GET:
  102. ret = _watchfd_max_get();
  103. break;
  104. case ISCNTL_APPLMAGIC_WRITE:
  105. ret = _isapplmw(isfd, (va_arg(pvar, char *)));
  106. break;
  107. case ISCNTL_APPLMAGIC_READ:
  108. ret = _isapplmr(isfd, (va_arg(pvar, char *)));
  109. break;
  110. case ISCNTL_FSYNC:
  111. ret = _isfsync(isfd);
  112. break;
  113. default:
  114. _setiserrno2(EBADARG, '9', '0');
  115. ret = ISERROR;
  116. }
  117. va_end(pvar);
  118. return (ret);
  119. }