Scripts launched from udev do not have DISPLAY access anymore?

后端 未结 5 934
慢半拍i
慢半拍i 2020-12-16 00:38

I have a script that runs from udev when I plug in my external drive. It always worked. But after upgrading from Linux 3.8/Xorg 1.12/Mint 14 (<

5条回答
  •  無奈伤痛
    2020-12-16 01:09

    A quick search turned up the following:

    X authentication is based on cookies -- secret little pieces of random data that only you and the X server know... So, you need to let the other user in on what your cookie is. One way to do this is as follows: Before you issue the su or sudo (but after having ssh'ed into the remote system if you are using ssh), request the cookie for the current DISPLAY that's connecting to your X server:

    $ xauth list $DISPLAY You'll get something like

    somehost.somedomain:10 mit-magic-cookie-1 4d22408a71a55b41ccd1657d377923ae

    Then, after having done su, tell the new user what the cookie is:

    $ xauth add somehost.somedomain:10 MIT-MAGIC-COOKIE-1 4d22408a71a55b41ccd1657d377923ae

    (just copy and paste the output of the above 'xauth list' onto 'xauth add') That's it. Now, you should be able to start any X application.

    For reference, here is the origin http://www.linuxquestions.org/questions/linux-newbie-8/xlib-connection-to-0-0-refused-by-server-xlib-no-protocol-specified-152556/

提交回复
热议问题