-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No access to xserver when started by udev #81
Comments
Is it possible to have something for this by default per user then? |
I'm not sure what you mean. I'm talking about systemd user units. |
This seems to be correct. No need to worry about the first two errors, they mean that the instance run as root does not have access to the display. The last line is the important one: It states that the global (batch) instance of autorandr forks a new instance of autorandr, running as your user, and that copy will have XAUTHORITY set properly (if it didn't, you'd see another error message from that copy). ..or do you have reason to believe that autorandr doesn't work?
For two reasons, (1) I don't know whether user instances of systemd trigger |
Yes, it doesn't apply the profile after those logs are shown. If I manually run
I'm pretty sure systemd-user works with the same targets as the global systemd.
That's true. I did a little research how you could acomplish this, and I came up with a kind-of-but-not-quite working solution:
Now for some reason that works the first time I plug in the monitor after a reboot, but not after that. It might have something to do with the following part of the documentation:
But I'm not quite sure what that means. I tried asking in the systemd IRC, but didn't get an answer yet. |
Hmm ok. Please add some debug output to autorandr:
This should generate enough info to see what's going on, hopefully.
Just found this as the first result on google. Might have changed in the meantime, of course.
That's a really nice feature, and it would be a great solution, but - alas - it won't work. See here, where we found exactly what you did find, too - this only works once. (A workaround that might work would be to make the systemd unit a service instead of a OneShot script, but write it such that it cleanly stops itself shortly after invocation. Maybe systemd is intelligent enough to see "oh, it's a service, I should restart it because this new device needs it"?!) |
I did that, and for some inexplicable reason it just works now. After switching back to the "vanilla" version, it still works. I'm sorry for bothering you with this, it was probably not working for some other reason. Thanks for the support.
Looks like you're right, and thats still the case:
We could ask on the systemd mailing list. But if the missing |
Okay, while I was fiddeling with postswitch scripts it stopped working again.
|
Okay, so the user instance is executed but To see which process this is, you can add before
the line
And to resolve the issue, try adding after
a line
|
"Unfortunately" right now it works again (which makes sense if your explanation is correct: it depends on which process autorandr semi-randomly selects). Instead I ran the following script to test: import os
for directory in os.listdir("/proc"):
directory = os.path.join("/proc/", directory)
if not os.path.isdir(directory):
continue
environ_file = os.path.join(directory, "environ")
if not os.path.isfile(environ_file):
continue
uid = os.stat(environ_file).st_uid
if uid < 1000:
continue
process_environ = {}
try:
for environ_entry in open(environ_file).read().split("\0"):
if "=" in environ_entry:
name, value = environ_entry.split("=", 1)
if name == "DISPLAY" and "." in value:
value = value[:value.find(".")]
process_environ[name] = value
if "DISPLAY" in process_environ and "XAUTHORITY" not in process_environ:
print("Found %s" % " ".join(open(os.path.join(directory, "cmdline")).read().split("\0")))
except IOError:
pass And got the following results:
I don't know anything about Note that I ignored all IOErrors. That's because I got an |
Interesting that However, there should be a simple fix: Prefer processes with |
Yes, that is weird. Maybe it does some hacks to discover Your "environment stealing" is a very clever workaround by the way. It might even be worthwhile to extract that to its own script:
or something like that. I could have used that on multiple occasions already (like when trying to Thank you for fixing it! |
I'll leave it in place here, because I've made the promise that autorandr would always remain a contained, single-file script without dependencies. But feel free to extract it into its own tool anyway if you feel you'd find some use for it :-) (Might be an idea to use psutil to be cross-platform compatible in that case.) |
When autorandr gets triggered by udev, I get the following logs:
Looking through the autorandr source,
Failed to run xrandr
seems to be a misleading error message that is caused by xrandrs stdout being empty (but not it's stdr,Can't open display :0
).When I disable x access control with
xhost +
, everything works fine.I'm assuming the problem is that autorandr doesn't get the
XAUTHORITY
variable via udev.However, I tried to add
Environment=XAUTHORITY=/home/timo/.Xauthority
to the service file and `ENV{XAUTHORITY}="/home/timo/.Xauthority" to the udev rule, without success.As an aside, why does autorandr use an system wide service file instead of systemd-user?
The text was updated successfully, but these errors were encountered: