Fails on Fedora 31 when user is specified
Ian2020 opened this issue · 2 comments
This is the error seen:
...subprocess.CalledProcessError: Command '['grep', '-z', '^DBUS_SESSION_BUS_ADDRESS', '/proc/181555\\n181619\\n181622/environ']' returned non-zero exit status 2.
It appears that the work to get the PID of the gnome session on line 29:
pid = _check_output_strip(['pgrep', '-u', user, 'gnome-session'])
...now returns three processes instead of one on Fedora 31.
I think this is due to a change in GNOME 3.33.90 where new binaries were added/renamed to help with systemd, e.g. this commit which introduced new binary gnome-session-ctl.
I have a suggested fix to get the GNOME version with a new function:
def _get_gnome_version():
return tuple(map(int, (_check_output_strip(
['gnome-shell', '--version']).split(' ')[2].split('.'))))
And change the pgrep cmd depending on it:
pgrep_cmd = ['pgrep', '-u', user, 'gnome-session']
gnome_ver = _get_gnome_version()
if (gnome_ver >= (3, 33, 90)):
# From GNOME 3.33.90 session process has changed
# https://github.com/GNOME/gnome-session/releases/tag/3.33.90
pgrep_cmd = ['pgrep', '-u', user, '-f', 'session=gnome']
I have tested this and it works on Fedora 30 (GNOME 3.32.2) which is prior to the GNOME change and after on Fedora 31 (GNOME 3.34.3).
I can raise a pull request against this issue but please let me know any feedback. Perhaps there is a better way to get the user's GNOME session without pgrep?
Hi Ian, thanks for the detailed report and solution suggestion. I was wondering why i'm not hitting the bug and realized that i don't use the user
parameter on the module (i configure settings of the user who's running Ansible), so the code path looking for gnome session never gets exercised in my case.
Please do submit a pull request with your solution, i don't know of a better way to get a gnome session PID without pgrep.
The final solution should not crash if there is no gnome-session process present for the user. The _get_dbus_address
function should keep returning None
so that _run_cmd_with_dbus
will then fall back to launching a new session. Maybe you're keeping it in mind already but it's not easy to tell from the code snippets so i thought i'd just highlight this as something to watch out for.
wondering why i'm not hitting the bug and realized that i don't use the user parameter
Totally forgot I was using 'user'! I've changed the issue title for clarity.
The final solution should not crash if there is no gnome-session process present for the user.
Understood. I'll send the PR, I think it's safe as we fall back into the original logic, I just change the pgrep cmd but yes I didn't include enough code here for you to tell.
Oh and I should say thanks for creating this in the first place and maintaining it!