GithubHelp home page GithubHelp logo

Comments (22)

phillipberndt avatar phillipberndt commented on June 23, 2024

Does who --all show the information? How about w?

from autorandr.

phillipberndt avatar phillipberndt commented on June 23, 2024

See also: https://github.com/Idolf/autorandr/commit/021e22f3059cf856824e7fa4024d97e54036c622

from autorandr.

phillipberndt avatar phillipberndt commented on June 23, 2024

..did yesterday's commit fix the issue?

from autorandr.

blueyed avatar blueyed commented on June 23, 2024

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.

phillipberndt avatar phillipberndt commented on June 23, 2024

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.

blueyed avatar blueyed commented on June 23, 2024

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.

phillipberndt avatar phillipberndt commented on June 23, 2024

What about getting the :0 out from my w -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.

blueyed avatar blueyed commented on June 23, 2024

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.

phillipberndt avatar phillipberndt commented on June 23, 2024

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.

phillipberndt avatar phillipberndt commented on June 23, 2024

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.

blueyed avatar blueyed commented on June 23, 2024

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.

phillipberndt avatar phillipberndt commented on June 23, 2024

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.

blueyed avatar blueyed commented on June 23, 2024

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.

phillipberndt avatar phillipberndt commented on June 23, 2024

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.

phillipberndt avatar phillipberndt commented on June 23, 2024

I committed the workaround; closing this for now, though I'd still prefer to have a proper fix.

from autorandr.

rnav avatar rnav commented on June 23, 2024

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.

phillipberndt avatar phillipberndt commented on June 23, 2024

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.

rnav avatar rnav commented on June 23, 2024

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.

phillipberndt avatar phillipberndt commented on June 23, 2024

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.

rnav avatar rnav commented on June 23, 2024

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.

phillipberndt avatar phillipberndt commented on June 23, 2024

I tried implementing this. Could you test if the version from the new branch works for you, please?

from autorandr.

rnav avatar rnav commented on June 23, 2024

This works for me with the change I mentioned in your commit. Thanks for fixing this!

from autorandr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.