Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,25 @@ process and user.
:data:`os.environ`, and when one of the :meth:`~dict.pop` or
:meth:`~dict.clear` methods is called.

If the :manpage:`clearenv(3)` function is available, the :meth:`~dict.clear` method
Comment thread
vstinner marked this conversation as resolved.
uses it and emits a single ``os._clearenv`` audit event. Otherwise, it emits
an ``os.unsetenv`` event on each deleted variable.

.. audit-event:: os.unsetenv key os.unsetenv

.. audit-event:: os._clearenv "" os._clearenv

.. seealso::

The :func:`os.reload_environ` function.

.. versionchanged:: 3.9
Updated to support :pep:`584`'s merge (``|``) and update (``|=``) operators.

.. versionchanged:: 3.15
The :meth:`~dict.clear` method can now emit an ``os._clearenv`` audit
event.


.. data:: environb

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Calling ``os.environ.clear()`` now emits ``os._clearenv`` auditing event.
Comment thread
picnixz marked this conversation as resolved.
Patch by Victor Stinner.
4 changes: 4 additions & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -13663,6 +13663,10 @@ static PyObject *
os__clearenv_impl(PyObject *module)
/*[clinic end generated code: output=2d6705d62c014b51 input=47d2fa7f323c43ca]*/
{
if (PySys_Audit("os._clearenv", NULL) < 0) {
return NULL;
}

errno = 0;
int err = clearenv();
if (err) {
Expand Down
Loading