[opensuse] Changing hibernate behaviour.
Hi, I wrote a /usr/lib/systemd/system-sleep/mine-sleep script. I have in it: #!/bin/sh case $1 in pre) echo "mine-sleep locking screen" DISPLAY=:0.0 xscreensaver-command -lock # xscreensaver-command: can't open display :0.0 ;; post) if [ "$2" = suspend ]; then echo "mine-sleep adjusting brigthness" echo 10 > /sys/class/backlight/acpi_video0/brightness fi ;; esac For now, I'm interested only in the "xscreensaver-command" sequence. The rest appears to work. I get this in the log: ** <3.6> 2017-04-01 13:35:21 minas-tirith systemd-sleep 18597 - - mine-sleep locking screen <3.5> 2017-04-01 13:35:21 minas-tirith dbus 1584 - - [system] Successfully activated service 'org.freedesktop.nm_dispatcher' <3.6> 2017-04-01 13:35:21 minas-tirith systemd 1 - - Started Network Manager Script Dispatcher Service. <3.6> 2017-04-01 13:35:21 minas-tirith systemd-sleep 18597 - - INFO: running /usr/lib/systemd/system-sleep/grub2.sleep for hibernate <3.6> 2017-04-01 13:35:21 minas-tirith systemd-sleep 18597 - - INFO: Running prepare-grub .. <3.6> 2017-04-01 13:35:21 minas-tirith systemd 1 - - Stopping Deferred execution scheduler... <3.6> 2017-04-01 13:35:21 minas-tirith systemd 1 - - Stopped Deferred execution scheduler. <3.6> 2017-04-01 13:35:21 minas-tirith systemd-sleep 18597 - - No protocol specified ** <3.6> 2017-04-01 13:35:21 minas-tirith systemd-sleep 18597 - - xscreensaver-command: can't open display :0.0 ... <3.4> 2017-04-01 13:35:31 minas-tirith systemd-sleep 18601 - - /usr/lib/systemd/system-sleep/mine-sleep failed with error code 1. Why does it fail with "xscreensaver-command: can't open display :0.0"? When I do it as root in a terminal it does work. Ideas? -- Cheers / Saludos, Carlos E. R. (from 42.2 x86_64 "Malachite" (Minas Tirith))
02.04.2017 04:53, Carlos E. R. пишет:
Hi,
I wrote a /usr/lib/systemd/system-sleep/mine-sleep script. I have in it:
#!/bin/sh
case $1 in pre) echo "mine-sleep locking screen" DISPLAY=:0.0 xscreensaver-command -lock # xscreensaver-command: can't open display :0.0 ;; post) if [ "$2" = suspend ]; then echo "mine-sleep adjusting brigthness" echo 10 > /sys/class/backlight/acpi_video0/brightness fi ;; esac
For now, I'm interested only in the "xscreensaver-command" sequence. The rest appears to work.
I get this in the log:
** <3.6> 2017-04-01 13:35:21 minas-tirith systemd-sleep 18597 - - mine-sleep locking screen <3.5> 2017-04-01 13:35:21 minas-tirith dbus 1584 - - [system] Successfully activated service 'org.freedesktop.nm_dispatcher' <3.6> 2017-04-01 13:35:21 minas-tirith systemd 1 - - Started Network Manager Script Dispatcher Service. <3.6> 2017-04-01 13:35:21 minas-tirith systemd-sleep 18597 - - INFO: running /usr/lib/systemd/system-sleep/grub2.sleep for hibernate <3.6> 2017-04-01 13:35:21 minas-tirith systemd-sleep 18597 - - INFO: Running prepare-grub .. <3.6> 2017-04-01 13:35:21 minas-tirith systemd 1 - - Stopping Deferred execution scheduler... <3.6> 2017-04-01 13:35:21 minas-tirith systemd 1 - - Stopped Deferred execution scheduler. <3.6> 2017-04-01 13:35:21 minas-tirith systemd-sleep 18597 - - No protocol specified ** <3.6> 2017-04-01 13:35:21 minas-tirith systemd-sleep 18597 - - xscreensaver-command: can't open display :0.0
...
<3.4> 2017-04-01 13:35:31 minas-tirith systemd-sleep 18601 - - /usr/lib/systemd/system-sleep/mine-sleep failed with error code 1.
Why does it fail with "xscreensaver-command: can't open display :0.0"? When I do it as root in a terminal it does work.
How exactly are you running command "as root in terminal"? After "su"? When logging in on another vt?
Ideas?
On 2017-04-02 08:08, Andrei Borzenkov wrote:
02.04.2017 04:53, Carlos E. R. пишет:
Hi,
I wrote a /usr/lib/systemd/system-sleep/mine-sleep script. I have in it:
#!/bin/sh
case $1 in pre) echo "mine-sleep locking screen" DISPLAY=:0.0 xscreensaver-command -lock
...
Why does it fail with "xscreensaver-command: can't open display :0.0"? When I do it as root in a terminal it does work.
How exactly are you running command "as root in terminal"? After "su"? When logging in on another vt?
su - Tried now in a vt. I get this text: minas-tirith:~ # xscreensaver -lock xscreensaver: 09:45:54: warning: $DISPLAY is not set: defaulting to ":0.0". No protocol specified xscreensaver: 09:45:54: Can't open display: :0.0 xscreensaver: 09:45:54: initial effective uid/gid was root/root (0/0) xscreensaver: 09:45:54: running as nobody/nobody (65534/65533) xscreensaver: 09:45:54: This is probably because you're logging in as root. You shouldn't log in as root: you should log in as a normal user, and then `su' as needed. If you insist on logging in as root, you will have to turn off X's security features before xscreensaver will work. Please read the manual and FAQ for more information: http://www.jwz.org/xscreensaver/faq.html http://www.jwz.org/xscreensaver/man.html minas-tirith:~ # If does not change if I set DISPLAY first. I have to go, can't read that doc now. -- Cheers / Saludos, Carlos E. R. (from 42.2 x86_64 "Malachite" (Minas Tirith))
On Sun, 2 Apr 2017 09:50, Carlos E. R. wrote:
On 2017-04-02 08:08, Andrei Borzenkov wrote:
02.04.2017 04:53, Carlos E. R. пишет:
Hi,
I wrote a /usr/lib/systemd/system-sleep/mine-sleep script. I have in it:
#!/bin/sh
case $1 in pre) echo "mine-sleep locking screen" DISPLAY=:0.0 xscreensaver-command -lock
...
Why does it fail with "xscreensaver-command: can't open display :0.0"? When I do it as root in a terminal it does work.
How exactly are you running command "as root in terminal"? After "su"? When logging in on another vt?
su -
Tried now in a vt. I get this text:
minas-tirith:~ # xscreensaver -lock xscreensaver: 09:45:54: warning: $DISPLAY is not set: defaulting to ":0.0". No protocol specified xscreensaver: 09:45:54: Can't open display: :0.0 xscreensaver: 09:45:54: initial effective uid/gid was root/root (0/0) xscreensaver: 09:45:54: running as nobody/nobody (65534/65533)
xscreensaver: 09:45:54: This is probably because you're logging in as root. You shouldn't log in as root: you should log in as a normal user, and then `su' as needed. If you insist on logging in as root, you will have to turn off X's security features before xscreensaver will work.
Please read the manual and FAQ for more information:
http://www.jwz.org/xscreensaver/faq.html http://www.jwz.org/xscreensaver/man.html
minas-tirith:~ #
If does not change if I set DISPLAY first.
I have to go, can't read that doc now.
How is your "xhost" setup? meaning: are you even allowed to conntact the $USER's Xscreen as root? "xhost LOCAL:" as $USER allows other local users (including root) to connect to the $USERs Xscreen. The correctly set DISPLAY env is still needed. - Yamaban.
On 2017-04-02 10:04, Yamaban wrote:
On Sun, 2 Apr 2017 09:50, Carlos E. R. wrote:
How is your "xhost" setup? meaning: are you even allowed to conntact the $USER's Xscreen as root?
"xhost LOCAL:" as $USER allows other local users (including root) to connect to the $USERs Xscreen.
The correctly set DISPLAY env is still needed.
minas-tirith:~ # xhost LOCAL: xhost: unable to open display "" minas-tirith:~ # DISPLAY=:0.0 xhost LOCAL: non-network local connections being added to access control list minas-tirith:~ # DISPLAY=:0.0 xscreensaver-command -lock xscreensaver-command: activating and locking. minas-tirith:~ # And the screen saver kicks in. Thanks. So that's the trick! Thanks Let's try on the script. Well, the screen saver locks, as in crashes, with the change: case $1 in pre) echo "mine-sleep locking screen" DISPLAY=:0.0 xhost LOCAL: DISPLAY=:0.0 xscreensaver-command -lock Or restore from suspend, there is no dialog. A further DISPLAY=:0.0 xscreensaver-command -lock says there is no response from command. I have to kill the xscreensaver to restore. The log says: <3.6> 2017-04-02 22:08:28 minas-tirith systemd-sleep 7844 - - xscreensaver-command: already locked. <3.4> 2017-04-02 22:08:28 minas-tirith systemd-sleep 7848 - - /usr/lib/systemd/system-sleep/mine-sleep failed with error code 255. Ok, I know this one: on lid close, which triggers suspend, the screensaver is already activated by the desktop. I do not need to activate it myself a second time, but that should not make it crash. On hibernate from the command line, that's different. So I need to do: if [ "$2" = hibernate ]; then echo "mine-sleep locking screen" DISPLAY=:0.0 xhost LOCAL: DISPLAY=:0.0 xscreensaver-command -lock fi No, the sreensaver blocks. Let's try: if [ "$2" = suspend ]; then echo "INFO: Skip running $0 for $2" exit 0 else echo "INFO: running $0 for $2" DISPLAY=:0.0 xhost LOCAL: DISPLAY=:0.0 xscreensaver-command -lock fi This works for suspend. Later tonight I'll see if it works on hibernate. Progress! :-) -- Cheers / Saludos, Carlos E. R. (from 42.2 x86_64 "Malachite" (Minas Tirith))
02.04.2017 23:40, Carlos E. R. пишет:
case $1 in pre) echo "mine-sleep locking screen" DISPLAY=:0.0 xhost LOCAL: DISPLAY=:0.0 xscreensaver-command -lock
You misunderstand. "xhost local:" should be executed once in your desktop session by *you*, to grant access to your X server to *other* users. Using it as above won't work (unless access is already granted by other means). By default X server is using primitive access control based on "magic cookie", which is stored in your home directory. When you run command using "su -", magic cookie is propagated from current (calling) user to called user session by PAM module. When you run it in other user's login context (or from daemon context), your magic cooker is not known. So either both commands are rejected or both commands work (but then "xhost" is redundant).
On 2017-04-03 05:25, Andrei Borzenkov wrote:
02.04.2017 23:40, Carlos E. R. пишет:
case $1 in pre) echo "mine-sleep locking screen" DISPLAY=:0.0 xhost LOCAL: DISPLAY=:0.0 xscreensaver-command -lock
You misunderstand. "xhost local:" should be executed once in your desktop session by *you*, to grant access to your X server to *other* users. Using it as above won't work (unless access is already granted by other means).
But it does. Apparently at least.
By default X server is using primitive access control based on "magic cookie", which is stored in your home directory. When you run command using "su -", magic cookie is propagated from current (calling) user to called user session by PAM module. When you run it in other user's login context (or from daemon context), your magic cooker is not known. So either both commands are rejected or both commands work (but then "xhost" is redundant).
Then, what should I do instead in the script? I could perhaps su to the user that has the desktop. How do I find that out? -- Cheers / Saludos, Carlos E. R. (from 42.2 x86_64 "Malachite" (Minas Tirith))
02.04.2017 10:50, Carlos E. R. пишет:
On 2017-04-02 08:08, Andrei Borzenkov wrote:
02.04.2017 04:53, Carlos E. R. пишет:
Hi,
I wrote a /usr/lib/systemd/system-sleep/mine-sleep script. I have in it:
#!/bin/sh
case $1 in pre) echo "mine-sleep locking screen" DISPLAY=:0.0 xscreensaver-command -lock
...
Why does it fail with "xscreensaver-command: can't open display :0.0"? When I do it as root in a terminal it does work.
How exactly are you running command "as root in terminal"? After "su"? When logging in on another vt?
su -
Tried now in a vt. I get this text:
minas-tirith:~ # xscreensaver -lock
It is not the same command.
On 2017-04-02 10:07, Andrei Borzenkov wrote:
02.04.2017 10:50, Carlos E. R. пишет:
Tried now in a vt. I get this text:
minas-tirith:~ # xscreensaver -lock
It is not the same command.
Ah. minas-tirith:~ # DISPLAY=:0.0 xscreensaver-command -lock No protocol specified xscreensaver-command: can't open display :0.0 minas-tirith:~ # xscreensaver-command -lock xscreensaver-command: warning: $DISPLAY is not set: defaulting to ":0.0". No protocol specified xscreensaver-command: can't open display :0.0 minas-tirith:~ # -- Cheers / Saludos, Carlos E. R. (from 42.2 x86_64 "Malachite" (Minas Tirith))
participants (3)
-
Andrei Borzenkov
-
Carlos E. R.
-
Yamaban