Skip to content

Using "env" in subprocess.run clears all environment variables #59

@jwmullally

Description

@jwmullally

Hello,

SystemCommand.nmcli() uses the env parameter of subprocess.run to set the LANG environment variable. Unfortunately this clobbers the rest of the environment and can cause issues when configuring nmcli through environment variables.


E.g. On BalenaOS, the host DBUS socket is accessed by specifying an alternative DBUS_SYSTEM_BUS_ADDRESS.

export DBUS_SYSTEM_BUS_ADDRESS="unix:path=/host/run/dbus/system_bus_socket"
nmcli dev show

However as this environment variable is overwritten by usage of a minimal env paramater, running any nmcli command produces the following exception, as the command can't reach the default DBUS endpoint.

import nmcli
nmcli.disable_use_sudo()
nmcli.device.show_all()
UnspecifiedException: Unknown or unspecified error [code:1, detail:Error: Could not create NMClient object: Could not connect: No such file or directory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions