Comments (22)
Does who --all
show the information? How about w
?
from autorandr.
See also: https://github.com/Idolf/autorandr/commit/021e22f3059cf856824e7fa4024d97e54036c622
from autorandr.
..did yesterday's commit fix the issue?
from autorandr.
No, w -h
looks like this for me:
user tty1 Wed14 3days 1:11m 0.00s xinit /home/user/.xinitrc -- /usr/bin/X :0 -nolisten tcp vt1 -auth /tmp/serverauth.XXX
user pts/3 Wed14 4:49m 7.43s 0.05s /usr/bin/python2 -c import sys; sys.path.remove(""); import neovim; neovim.start_host() /home/user/.local/opt/neovim/share/nvim/runtime/aut
I think the problem is "just" that there's no display manager that would update the utmp
database with the display information.
from autorandr.
I have searched for portable ways to find which user "owns" an X11 session, but haven't been able to find one.. I doubt that this is generally solvable (at least, without creating potential security issues like one might do by e.g. searching for any program that is connected to the display and then su to its owner.).
from autorandr.
Yeah.
What about getting the :0
out from my w -h
?
But maybe after all xinit
would need to be changed to also update the utmp database like other desktop managers do?
from autorandr.
What about getting the
:0
out from myw -h
?
This seems to be the best course of action, though I'm still not perfectly happy with su'ing to some user based on the output of some command that said user can influence. See the latest change.
from autorandr.
FWIW, here's some adhoc method, which might be too specific, but works for me:
w -h | grep -oE '/usr/bin/X (:\S+)' | cut -d\ -f2
from autorandr.
That'll find any X11 session, not specifically yours, right? But in
combination with a check whether it's the only one that'd indeed be a good
fallback.
from autorandr.
Another thought, do you think this would work?
USERS=($(w -hu | cut -d\ -f1 | grep -vx root | sort | uniq))
if [ ${#USERS} -eq 1 ]; then
# Obviously the session must be owned by ${USERS[1]}
fi
(I'm aware that dash does not support the array syntax, this is currently written for bash)
from autorandr.
Works for me.
This does the same, using awk
and only looks at tty*
entries (which I'm not sure is good?!):
w -hu | awk '$2 ~ "tty.*" && $1 !~ "root" { print $1; exit }'
from autorandr.
Great. I'll include this as a fallback, then.
(Your variant doesn't do exactly the same; actually, checking that there isn't another user logged in was an intentional security measure.)
from autorandr.
checking that there isn't another user logged in was an intentional security measure
Hmm. Isn't the idea/point to handle all logged in users?
from autorandr.
Hmm. Isn't the idea/point to handle all logged in users?
Sure. That works, too, if the utmp database is used correctly. If it isn't, we still lack a reliable way to determine the owner of an X11-session. We use the information to su
to a user and run an executable, which is potentially dangerous, so I'd prefer to include "forgery proof" in "reliable" unless it is absolutely unavoidable not to. Since we haven't found a way to do that yet, my idea was, for the time being, to provide a fallback for the case of a single user system, where this isn't an issue.
btw, here's an awk only variant of my above approach:
w -hu | awk '/^\w+/ && $1 !~ "root" { users[$1]=$1; } ENDFILE { if(asort(users) == 1) for(u in users) print users[u]; }'
from autorandr.
I committed the workaround; closing this for now, though I'd still prefer to have a proper fix.
from autorandr.
Bumping an old one, but I did face this issue though I use SDDM. It looks like utmp is not updated, so my active login is not reflected by w/who. I've addressed this by using loginctl:
user="
loginctl list-users --no-legend | cut -d' ' -f8"
from autorandr.
It'd be an option to detect whether loginctl is available and use it preferably if it is. Does this DISPLAY detection script work for you? That is, does
loginctl show-session -p Display -p Active `loginctl list-sessions --no-legend | awk '{print $1}'`
output the correct display? The SO answer however claims that this won't work with gdm.
Here's another alternative: We could search for all processes that locally run and have access to the display and check whether except for root, there's only one owning user:
for p in /proc/*; do
[ -d $p ] || continue
d=$(awk -v RS='\0' -F= '$1=="DISPLAY" {print $2}' $p/environ 2>/dev/null);
if [ "$d" = ":0" ]; then # Replace :0 with $D !!
stat -c %U $p
fi
done | sort | uniq | grep -v root
does this work for you?
from autorandr.
Yes, those work for me. I prefer the loginctl based approach though. Going through all the processes seems heavy -- we can perhaps use loginctl and consider other options for GDM?
from autorandr.
So do I. I wondered whether this works because we need some fail-safe in case all other detection methods fail. That was what the final w
invocation was for as well (..and I thought it'd work because I foolishly assumed that noone would break POSIX compatibility.)
from autorandr.
Yes, I think that makes sense. I suppose a few if [ -z "$user" ]; then
checks can't hurt and going through all the processes as the last resort seems better than autorandr not working at all.
from autorandr.
I tried implementing this. Could you test if the version from the new branch works for you, please?
from autorandr.
This works for me with the change I mentioned in your commit. Thanks for fixing this!
from autorandr.
Related Issues (20)
- Use of --skip-options breaks --current HOT 1
- Parsing XRandR output failed HOT 1
- Detected Wayland session 'wayland-0'. Exiting.
- Failed to apply profile because xrandr cannot find mode
- postscript loses authentication for systemctl commands after suspending HOT 1
- Unhandled exception (local variable 'output' referenced before assignment) HOT 1
- Broken regexes due to missing `r` string literal HOT 6
- Unable to save lid state when using NVIDIA GPU (no eDP / LVDS output)
- Total system crash + soundloop could be caused by autorandr
- Total system crash + soundloop could be caused by autorandr
- No XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE events HOT 2
- Prevent profile change with screen lock HOT 1
- Additional Documentation HOT 7
- autorandr.service "Failed to load profile: 'xxx' : Profile not found" althoug profile exists HOT 1
- Failed to apply profile due to `--crtc` option HOT 3
- Incorrect profile settings HOT 1
- autorandr /usr/bin/autorandr:210: SyntaxWarning: invalid escape sequence '\s' XRANDR_OUTPUT_REGEXP = """(?x) /usr/bin/autorandr:236: SyntaxWarning: invalid escape sequence '\s' """ + XRANDR_PROPERTIES_REGEXP + """ | # Properties to include in the profile /usr/bin/autorandr:248: SyntaxWarning: invalid escape sequence '\S' XRANDR_OUTPUT_MODES_REGEXP = """(?x) /usr/bin/autorandr:592: SyntaxWarning: invalid escape sequence '\s' version = re.search("xrandr program version\s+([0-9\.]+)", version_string).group(1) /usr/bin/autorandr:888: SyntaxWarning: invalid escape sequence '\+' match = re.match("(?P<w>[0-9]+)x(?P<h>[0-9]+)(?:\+(?P<x>[0-9]+))?(?:\+(?P<y>[0-9]+))?.*", output.options["panning"]) HOT 6
- please support appimage , or binary file HOT 1
- Enabling udev rule / systemd service on a per-user basis? HOT 2
- Systemd : StartLimitIntervalSec too short
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autorandr.