syslogmodule.c.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(syslog_openlog__doc__,
  9. "openlog($module, /, ident=<unrepresentable>, logoption=0,\n"
  10. " facility=LOG_USER)\n"
  11. "--\n"
  12. "\n"
  13. "Set logging options of subsequent syslog() calls.");
  14. #define SYSLOG_OPENLOG_METHODDEF \
  15. {"openlog", _PyCFunction_CAST(syslog_openlog), METH_FASTCALL|METH_KEYWORDS, syslog_openlog__doc__},
  16. static PyObject *
  17. syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt,
  18. long facility);
  19. static PyObject *
  20. syslog_openlog(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  21. {
  22. PyObject *return_value = NULL;
  23. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  24. #define NUM_KEYWORDS 3
  25. static struct {
  26. PyGC_Head _this_is_not_used;
  27. PyObject_VAR_HEAD
  28. PyObject *ob_item[NUM_KEYWORDS];
  29. } _kwtuple = {
  30. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  31. .ob_item = { &_Py_ID(ident), &_Py_ID(logoption), &_Py_ID(facility), },
  32. };
  33. #undef NUM_KEYWORDS
  34. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  35. #else // !Py_BUILD_CORE
  36. # define KWTUPLE NULL
  37. #endif // !Py_BUILD_CORE
  38. static const char * const _keywords[] = {"ident", "logoption", "facility", NULL};
  39. static _PyArg_Parser _parser = {
  40. .keywords = _keywords,
  41. .fname = "openlog",
  42. .kwtuple = KWTUPLE,
  43. };
  44. #undef KWTUPLE
  45. PyObject *argsbuf[3];
  46. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  47. PyObject *ident = NULL;
  48. long logopt = 0;
  49. long facility = LOG_USER;
  50. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 3, 0, argsbuf);
  51. if (!args) {
  52. goto exit;
  53. }
  54. if (!noptargs) {
  55. goto skip_optional_pos;
  56. }
  57. if (args[0]) {
  58. if (!PyUnicode_Check(args[0])) {
  59. _PyArg_BadArgument("openlog", "argument 'ident'", "str", args[0]);
  60. goto exit;
  61. }
  62. if (PyUnicode_READY(args[0]) == -1) {
  63. goto exit;
  64. }
  65. ident = args[0];
  66. if (!--noptargs) {
  67. goto skip_optional_pos;
  68. }
  69. }
  70. if (args[1]) {
  71. logopt = PyLong_AsLong(args[1]);
  72. if (logopt == -1 && PyErr_Occurred()) {
  73. goto exit;
  74. }
  75. if (!--noptargs) {
  76. goto skip_optional_pos;
  77. }
  78. }
  79. facility = PyLong_AsLong(args[2]);
  80. if (facility == -1 && PyErr_Occurred()) {
  81. goto exit;
  82. }
  83. skip_optional_pos:
  84. return_value = syslog_openlog_impl(module, ident, logopt, facility);
  85. exit:
  86. return return_value;
  87. }
  88. PyDoc_STRVAR(syslog_syslog__doc__,
  89. "syslog([priority=LOG_INFO,] message)\n"
  90. "Send the string message to the system logger.");
  91. #define SYSLOG_SYSLOG_METHODDEF \
  92. {"syslog", (PyCFunction)syslog_syslog, METH_VARARGS, syslog_syslog__doc__},
  93. static PyObject *
  94. syslog_syslog_impl(PyObject *module, int group_left_1, int priority,
  95. const char *message);
  96. static PyObject *
  97. syslog_syslog(PyObject *module, PyObject *args)
  98. {
  99. PyObject *return_value = NULL;
  100. int group_left_1 = 0;
  101. int priority = LOG_INFO;
  102. const char *message;
  103. switch (PyTuple_GET_SIZE(args)) {
  104. case 1:
  105. if (!PyArg_ParseTuple(args, "s:syslog", &message)) {
  106. goto exit;
  107. }
  108. break;
  109. case 2:
  110. if (!PyArg_ParseTuple(args, "is:syslog", &priority, &message)) {
  111. goto exit;
  112. }
  113. group_left_1 = 1;
  114. break;
  115. default:
  116. PyErr_SetString(PyExc_TypeError, "syslog.syslog requires 1 to 2 arguments");
  117. goto exit;
  118. }
  119. return_value = syslog_syslog_impl(module, group_left_1, priority, message);
  120. exit:
  121. return return_value;
  122. }
  123. PyDoc_STRVAR(syslog_closelog__doc__,
  124. "closelog($module, /)\n"
  125. "--\n"
  126. "\n"
  127. "Reset the syslog module values and call the system library closelog().");
  128. #define SYSLOG_CLOSELOG_METHODDEF \
  129. {"closelog", (PyCFunction)syslog_closelog, METH_NOARGS, syslog_closelog__doc__},
  130. static PyObject *
  131. syslog_closelog_impl(PyObject *module);
  132. static PyObject *
  133. syslog_closelog(PyObject *module, PyObject *Py_UNUSED(ignored))
  134. {
  135. return syslog_closelog_impl(module);
  136. }
  137. PyDoc_STRVAR(syslog_setlogmask__doc__,
  138. "setlogmask($module, maskpri, /)\n"
  139. "--\n"
  140. "\n"
  141. "Set the priority mask to maskpri and return the previous mask value.");
  142. #define SYSLOG_SETLOGMASK_METHODDEF \
  143. {"setlogmask", (PyCFunction)syslog_setlogmask, METH_O, syslog_setlogmask__doc__},
  144. static long
  145. syslog_setlogmask_impl(PyObject *module, long maskpri);
  146. static PyObject *
  147. syslog_setlogmask(PyObject *module, PyObject *arg)
  148. {
  149. PyObject *return_value = NULL;
  150. long maskpri;
  151. long _return_value;
  152. maskpri = PyLong_AsLong(arg);
  153. if (maskpri == -1 && PyErr_Occurred()) {
  154. goto exit;
  155. }
  156. _return_value = syslog_setlogmask_impl(module, maskpri);
  157. if ((_return_value == -1) && PyErr_Occurred()) {
  158. goto exit;
  159. }
  160. return_value = PyLong_FromLong(_return_value);
  161. exit:
  162. return return_value;
  163. }
  164. PyDoc_STRVAR(syslog_LOG_MASK__doc__,
  165. "LOG_MASK($module, pri, /)\n"
  166. "--\n"
  167. "\n"
  168. "Calculates the mask for the individual priority pri.");
  169. #define SYSLOG_LOG_MASK_METHODDEF \
  170. {"LOG_MASK", (PyCFunction)syslog_LOG_MASK, METH_O, syslog_LOG_MASK__doc__},
  171. static long
  172. syslog_LOG_MASK_impl(PyObject *module, long pri);
  173. static PyObject *
  174. syslog_LOG_MASK(PyObject *module, PyObject *arg)
  175. {
  176. PyObject *return_value = NULL;
  177. long pri;
  178. long _return_value;
  179. pri = PyLong_AsLong(arg);
  180. if (pri == -1 && PyErr_Occurred()) {
  181. goto exit;
  182. }
  183. _return_value = syslog_LOG_MASK_impl(module, pri);
  184. if ((_return_value == -1) && PyErr_Occurred()) {
  185. goto exit;
  186. }
  187. return_value = PyLong_FromLong(_return_value);
  188. exit:
  189. return return_value;
  190. }
  191. PyDoc_STRVAR(syslog_LOG_UPTO__doc__,
  192. "LOG_UPTO($module, pri, /)\n"
  193. "--\n"
  194. "\n"
  195. "Calculates the mask for all priorities up to and including pri.");
  196. #define SYSLOG_LOG_UPTO_METHODDEF \
  197. {"LOG_UPTO", (PyCFunction)syslog_LOG_UPTO, METH_O, syslog_LOG_UPTO__doc__},
  198. static long
  199. syslog_LOG_UPTO_impl(PyObject *module, long pri);
  200. static PyObject *
  201. syslog_LOG_UPTO(PyObject *module, PyObject *arg)
  202. {
  203. PyObject *return_value = NULL;
  204. long pri;
  205. long _return_value;
  206. pri = PyLong_AsLong(arg);
  207. if (pri == -1 && PyErr_Occurred()) {
  208. goto exit;
  209. }
  210. _return_value = syslog_LOG_UPTO_impl(module, pri);
  211. if ((_return_value == -1) && PyErr_Occurred()) {
  212. goto exit;
  213. }
  214. return_value = PyLong_FromLong(_return_value);
  215. exit:
  216. return return_value;
  217. }
  218. /*[clinic end generated code: output=3b1bdb16565b8fda input=a9049054013a1b77]*/