Discussion:
[systemd-devel] xmodmap gives: No protocol specified
Cecil Westerhof
2016-11-04 11:47:45 UTC
Permalink
I have a script I want to run as a service which uses:
xmodmap -pk
I have to define the DISPLAY, so I use:
export DISPLAY=:0.0

But this gives:
export DISPLAY=:0.0
xmodmap: unable to open display ':0.0'

When I try the same with at, I do not have this problem.

What is happening here and how can I resolve this?
--
Cecil Westerhof
Mantas Mikulėnas
2016-11-04 12:29:20 UTC
Permalink
Post by Cecil Westerhof
xmodmap -pk
export DISPLAY=:0.0
export DISPLAY=:0.0
xmodmap: unable to open display ':0.0'
When I try the same with at, I do not have this problem.
What is happening here and how can I resolve this?
What's happening is that you shouldn't run X11 programs as system services.

Most of the time, Xlib saying "No protocol specified" means that the X
server rejected the connection attempt due to missing authentication
details. To fix that, either the program needs the path to your Xauthority
file, or the X server needs to be configured to allow all connections by
your UID.

The default location of Xauth information is ~/.Xauthority – if your
program cannot find it, either you need to set $HOME, or your display
manager (gdm &c.) probably stored it elsewhere and you need to set
$XAUTHORITY. Either way, don't run X11 programs as system services.

Allowing connections by UID might be simpler – run `xauth
+SI:localuser:$(id -un)` in your X11 startup script. (The full SI:* syntax
is described in Xsecurity(7).)
--
Mantas Mikulėnas <***@gmail.com>
Cecil Westerhof
2016-11-04 14:46:19 UTC
Permalink
Post by Mantas Mikulėnas
Post by Cecil Westerhof
xmodmap -pk
export DISPLAY=:0.0
export DISPLAY=:0.0
xmodmap: unable to open display ':0.0'
When I try the same with at, I do not have this problem.
What is happening here and how can I resolve this?
What's happening is that you shouldn't run X11 programs as system services.
It worked with xscreensaver:
https://www.linkedin.com/pulse/saving-netbook-battery-bash-script-cecil-westerhof
Post by Mantas Mikulėnas
Most of the time, Xlib saying "No protocol specified" means that the X
server rejected the connection attempt due to missing authentication
details. To fix that, either the program needs the path to your Xauthority
file, or the X server needs to be configured to allow all connections by
your UID.
The strange thing I use the same user with at and systemd. So what is
the difference?
But I also tried setting XAUTHORITY with:
export XAUTHORITY=~/.Xauthority

With ‘xauth info’ I saw that the authority file is:
/run/lightdm/cecil/xauthority
but using that in the above statement did not help either.
Post by Mantas Mikulėnas
The default location of Xauth information is ~/.Xauthority – if your program
cannot find it, either you need to set $HOME, or your display manager (gdm
&c.) probably stored it elsewhere and you need to set $XAUTHORITY. Either
way, don't run X11 programs as system services.
I want to set my own keyboard definitions when they get lost. They
sometimes do. The only way of doing this automatically is in a cronjob
or a systemd service. I would prefer a systemd service. But for the
moment I rewrite the script to be run from cron instead of systemd.
--
Cecil Westerhof
Cecil Westerhof
2016-11-04 15:26:36 UTC
Permalink
Post by Cecil Westerhof
I want to set my own keyboard definitions when they get lost. They
sometimes do. The only way of doing this automatically is in a cronjob
or a systemd service. I would prefer a systemd service. But for the
moment I rewrite the script to be run from cron instead of systemd.
That does not work either: in cron I get the same errors. :'-(
--
Cecil Westerhof
Reindl Harald
2016-11-04 15:32:02 UTC
Permalink
Post by Cecil Westerhof
Post by Cecil Westerhof
I want to set my own keyboard definitions when they get lost. They
sometimes do. The only way of doing this automatically is in a cronjob
or a systemd service. I would prefer a systemd service. But for the
moment I rewrite the script to be run from cron instead of systemd.
That does not work either: in cron I get the same errors. :'-(
you *can not* start a GUI application without a GUI and systemd-services
nor cron-jobs have any GUI - that's it

what you try to do is simply not possible

Lennart Poettering
2016-11-04 12:43:25 UTC
Permalink
Post by Cecil Westerhof
xmodmap -pk
export DISPLAY=:0.0
export DISPLAY=:0.0
xmodmap: unable to open display ':0.0'
When I try the same with at, I do not have this problem.
What is happening here and how can I resolve this?
This is the systemd mailing list, we don't really have much knowledge
about X11, sorry.

Lennart
--
Lennart Poettering, Red Hat
Loading...