diff options
Diffstat (limited to 'contrib/tools/python3/Modules/syslogmodule.c')
| -rw-r--r-- | contrib/tools/python3/Modules/syslogmodule.c | 70 |
1 files changed, 56 insertions, 14 deletions
diff --git a/contrib/tools/python3/Modules/syslogmodule.c b/contrib/tools/python3/Modules/syslogmodule.c index c925a42dc05..9c54af51402 100644 --- a/contrib/tools/python3/Modules/syslogmodule.c +++ b/contrib/tools/python3/Modules/syslogmodule.c @@ -49,8 +49,14 @@ Revision history: /* syslog module */ +// clinic/syslogmodule.c.h uses internal pycore_modsupport.h API +#ifndef Py_BUILD_CORE_BUILTIN +# define Py_BUILD_CORE_MODULE 1 +#endif + #include "Python.h" #include "osdefs.h" // SEP +#include "pycore_sysmodule.h" // _PySys_GetOptionalAttrString() #include <syslog.h> @@ -84,49 +90,55 @@ syslog_get_argv(void) Py_ssize_t argv_len, scriptlen; PyObject *scriptobj; Py_ssize_t slash; - PyObject *argv = PySys_GetObject("argv"); + PyObject *argv; - if (argv == NULL) { - return(NULL); + if (_PySys_GetOptionalAttrString("argv", &argv) <= 0) { + return NULL; } argv_len = PyList_Size(argv); if (argv_len == -1) { PyErr_Clear(); - return(NULL); + Py_DECREF(argv); + return NULL; } if (argv_len == 0) { - return(NULL); + Py_DECREF(argv); + return NULL; } scriptobj = PyList_GetItem(argv, 0); + Py_XINCREF(scriptobj); + Py_DECREF(argv); if (scriptobj == NULL) { PyErr_Clear(); return NULL; } if (!PyUnicode_Check(scriptobj)) { - return(NULL); + Py_DECREF(scriptobj); + return NULL; } scriptlen = PyUnicode_GET_LENGTH(scriptobj); if (scriptlen == 0) { - return(NULL); + Py_DECREF(scriptobj); + return NULL; } slash = PyUnicode_FindChar(scriptobj, SEP, 0, scriptlen, -1); if (slash == -2) { PyErr_Clear(); + Py_DECREF(scriptobj); return NULL; } if (slash != -1) { - return PyUnicode_Substring(scriptobj, slash + 1, scriptlen); - } else { - Py_INCREF(scriptobj); - return(scriptobj); + Py_SETREF(scriptobj, PyUnicode_Substring(scriptobj, slash + 1, scriptlen)); } + return scriptobj; } /*[clinic input] +@critical_section syslog.openlog ident: unicode = NULL @@ -139,7 +151,7 @@ Set logging options of subsequent syslog() calls. static PyObject * syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt, long facility) -/*[clinic end generated code: output=5476c12829b6eb75 input=8a987a96a586eee7]*/ +/*[clinic end generated code: output=5476c12829b6eb75 input=ee700b8786f81c23]*/ { // Since the sys.openlog changes the process level state of syslog library, // this operation is only allowed for the main interpreter. @@ -156,6 +168,9 @@ syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt, else { /* get sys.argv[0] or NULL if we can't for some reason */ ident = syslog_get_argv(); + if (ident == NULL && PyErr_Occurred()) { + return NULL; + } } /* At this point, ident should be INCREF()ed. openlog(3) does not @@ -184,6 +199,7 @@ syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt, /*[clinic input] +@critical_section syslog.syslog [ @@ -200,7 +216,7 @@ Send the string message to the system logger. static PyObject * syslog_syslog_impl(PyObject *module, int group_left_1, int priority, const char *message) -/*[clinic end generated code: output=c3dbc73445a0e078 input=ac83d92b12ea3d4e]*/ +/*[clinic end generated code: output=c3dbc73445a0e078 input=6588ddb0b113af8e]*/ { if (PySys_Audit("syslog.syslog", "is", priority, message) < 0) { return NULL; @@ -238,6 +254,7 @@ syslog_syslog_impl(PyObject *module, int group_left_1, int priority, /*[clinic input] +@critical_section syslog.closelog Reset the syslog module values and call the system library closelog(). @@ -245,7 +262,7 @@ Reset the syslog module values and call the system library closelog(). static PyObject * syslog_closelog_impl(PyObject *module) -/*[clinic end generated code: output=97890a80a24b1b84 input=fb77a54d447acf07]*/ +/*[clinic end generated code: output=97890a80a24b1b84 input=167f489868bd5a72]*/ { // Since the sys.closelog changes the process level state of syslog library, // this operation is only allowed for the main interpreter. @@ -401,12 +418,37 @@ syslog_exec(PyObject *module) ADD_INT_MACRO(module, LOG_AUTHPRIV); #endif +#ifdef LOG_FTP + ADD_INT_MACRO(module, LOG_FTP); +#endif + +#ifdef LOG_NETINFO + ADD_INT_MACRO(module, LOG_NETINFO); +#endif + +#ifdef LOG_REMOTEAUTH + ADD_INT_MACRO(module, LOG_REMOTEAUTH); +#endif + +#ifdef LOG_INSTALL + ADD_INT_MACRO(module, LOG_INSTALL); +#endif + +#ifdef LOG_RAS + ADD_INT_MACRO(module, LOG_RAS); +#endif + +#ifdef LOG_LAUNCHD + ADD_INT_MACRO(module, LOG_LAUNCHD); +#endif + return 0; } static PyModuleDef_Slot syslog_slots[] = { {Py_mod_exec, syslog_exec}, {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, + {Py_mod_gil, Py_MOD_GIL_NOT_USED}, {0, NULL} }; |
