reading /proc/$PID/environ returns Permission Denied

Asked by Snap Deus

I am trying to export DBUS_SESSION_BUS_ADDRESS as environment variable in a startup script to change the background via gsettings. This script was working before a recent Ubuntu update. I am guessing that something changed in the 20.04.03 release, but after looking at the release notes I couldn't find anything relevant, so I am not sure.

Here is the relevant snippet of shell script code that I am using to attempt to export DBUS_SESSION_BUS_ADDRESS as an environment variable

pid_gnome=$(pgrep gnome-session | head -1)
DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/${pid_gnome}/environ|cut -d= -f2- | tr -d '\0\n')
export DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}

I get this error:

grep /proc/$PID/environ PERMISSION DENIED

If I manually try to cat /proc/$PID/environ, I also get permission denied. If I use sudo it works.

Did something change regarding the permissions for gnome-session environ recently?
If so, how can I export the DBUS_SESSION_BUS_ADDRESS as environment variable in a startup script ?

Thanks.

Edit: I have managed to get the script running again by setting the DISPLAY variable to DISPLAY=:1
I am confused as to why my DISPLAY is :1 and not :0, but no complaints here and that isn't the topic of the question.

My question still stands because I'm curious about how to export the DBUS_SESSION_BUS_ADDRESS as an environment variable, but it is not urgent or anything.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

If you use /etc/rc.local and add the command above the "exit 0" it will run as root at startup. Not pretty but will work

Can you help with this problem?

Provide an answer of your own, or ask Snap Deus for more information if necessary.

To post a message you must log in.