Results 1 to 8 of 8

Thread: Systemd xlock and suspend

  1. #1
    Join Date
    Apr 2010
    Location
    Bayern Germany
    Posts
    9

    Default Systemd xlock and suspend

    Hi all,

    I want to use systemd to lock my screen after I suspend my system. I'm not using any common desktop environment but i3 as a lightweight window manager. It has now power management so my system doesn't do that automatically. I wanted to write a systemd service which handles this problem.

    I placed the service under /etc/systemd/system/xlock.service:

    Code:
    [Unit]
    Description=Lock X session using xlock
    
    [Service]
    User=philipp
    Environment=DISPLAY=:0
    ExecStart=/usr/bin/xlock -mode strange -bg black -fg white
    
    [Install]
    WantedBy=sleep.target
    But this doesn't work.
    The error messages i get:
    Code:
    Aug 01 16:18:43 tesla.site xlock[19261]: No protocol specified
    Aug 01 16:18:43 tesla.site xlock[19261]: xlock: unable to open display .
    I don't know how to get this work. I set the display variable and everything else looks good. I think openSUSE implements suspend a bit different than archlinux does, because on archlinux it seems to work:
    https://bbs.archlinux.org/viewtopic.php?id=148829

    Does anybody has an idea?

    System: openSUSE 12.3 x86_64
    WM: i3

  2. #2
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    26,846
    Blog Entries
    15

    Default Re: Systemd xlock and suspend

    On Thu 01 Aug 2013 02:36:05 PM CDT, seilerphilipp wrote:


    Hi all,

    I want to use systemd to lock my screen after I suspend my system. I'm
    not using any common desktop environment but i3 as a lightweight window
    manager. It has now power management so my system doesn't do that
    automatically. I wanted to write a systemd service which handles this
    problem.

    I placed the service under /etc/systemd/system/xlock.service:


    Code:
    --------------------

    [Unit]
    Description=Lock X session using xlock

    [Service]
    User=philipp
    Environment=DISPLAY=:0
    ExecStart=/usr/bin/xlock -mode strange -bg black -fg white

    [Install]
    WantedBy=sleep.target

    --------------------


    But this doesn't work.
    The error messages i get:

    Code:
    --------------------

    Aug 01 16:18:43 tesla.site xlock[19261]: No protocol specified
    Aug 01 16:18:43 tesla.site xlock[19261]: xlock: unable to open
    display .
    --------------------


    I don't know how to get this work. I set the display variable and
    everything else looks good. I think openSUSE implements suspend a bit
    different than archlinux does, because on archlinux it seems to work:
    https://bbs.archlinux.org/viewtopic.php?id=148829

    Does anybody has an idea?

    System: openSUSE 12.3 x86_64
    WM: i3


    Hi
    What about using i3lock?
    http://software.opensuse.org/package/i3lock

    systemd service
    https://github.com/krgn/systemd/blob...3lock@.service

    --
    Cheers Malcolm °¿° (Linux Counter #276890)
    openSUSE 12.3 (x86_64) Kernel 3.7.10-1.16-desktop
    up 14:49, 3 users, load average: 0.59, 0.35, 0.27
    CPU AMD E2-1800@1.70GHz | GPU Radeon HD 7340


  3. #3
    Join Date
    Apr 2010
    Location
    Bayern Germany
    Posts
    9

    Default Re: Systemd xlock and suspend

    It's always the same. I can fix my problems by myself, after I start a forum thread. Even if i try to fix this problem for a few days.
    The problem was, that not the DISPLAY variable isn't set, but the XAUTHORITY variable. But to get safe i added the parameter "-display :0" to the xlock command line.


    My systemd service now looks like this:
    Code:
    [Unit]
    Description=Lock X session using xlock
    
    [Service]
    User=philipp
    Environment=XAUTHORITY=/run/lightdm/philipp/xauthority
    ExecStart=/usr/bin/xlock -mode strange -bg black -fg white -display :0
    
    [Install]
    WantedBy=sleep.target
    /e: @malcomlewis:

    I think this would be the same result as xlock was. I tried xtrlock slock and xlock.

    I think the point of the matter is the XAUTHORITY variable.

    But nevertheless thank your for the quick answer

    Last edited by seilerphilipp; 01-Aug-2013 at 08:01. Reason: added part for the poster above

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,156

    Default Re: Systemd xlock and suspend

    I can try to explain the second message.

    As you run this somewhere from the background, the program xlock has no idea what to do when it comes to interaction with an X-server. Which one? Linux is a multi-user system and there can be many X sessions running at the same time. As a general convention the environment variable DISPLAY has the value of the display (host identification and display number) that is to be used by any X program. For most simple cases like only one user being loged in localy on the first display of a system (remember that X on openSUSE allows more logical displays on the physical screen you have) is
    Code:
    henk@boven:~> echo $DISPLAY
    :0
    henk@boven:~>
    Thus first thing to try is to changte your command to
    Code:
    DISPLAY=:0 /usr/bin/xlock -mode strange -bg black -fg white
    Allthough that is not 100% tight as doing this you in fact deny that there can be multiple users using X (local and remote) and multiple screens on the sytem. It even does not cope for no user loged in using display :0.

    A second problem could then be that the program is not allowed to do something with diplay :0. After all, most people want to be sure that no outsiders can attach there display, open windows at will and possibly even reading all their keyboard typing. Thus there is security implemented there. A user can allow/deny usage of his display from local/remote on a per host and per user base with the tool
    Code:
    xhost
    Check what your current situation is with
    Code:
    henk@boven:~> xhost
    access control disabled, clients can connect from any host
    henk@boven:~>
    and read
    Code:
    man xhost
    Henk van Velden

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,156

    Default Re: Systemd xlock and suspend

    Hm, it seems I took to long to type the above and in the meantime you solved it all. Very good.
    Henk van Velden

  6. #6
    Join Date
    Sep 2012
    Posts
    5,140

    Default Re: Systemd xlock and suspend

    Quote Originally Posted by seilerphilipp View Post

    I want to use systemd to lock my screen after I suspend my system.
    That's the wrong tool to do it. systemd manages system services, it does not manage user sessions (yet). Actually, all desktop environments can do it, and those I worked with do it by default; why do you need to reinvent the wheel?

  7. #7
    Join Date
    Apr 2010
    Location
    Bayern Germany
    Posts
    9

    Default Re: Systemd xlock and suspend

    replace xlock with systemd in the sentence you have cited.
    But in fact systemd is the right place to configure actions/commands/whatelse which depends on a suspend event/target

  8. #8
    Join Date
    Mar 2010
    Location
    Austin - Texas
    Posts
    10,140
    Blog Entries
    48

    Smile Re: Systemd xlock and suspend

    Quote Originally Posted by seilerphilipp View Post
    replace xlock with systemd in the sentence you have cited.
    But in fact systemd is the right place to configure actions/commands/whatelse which depends on a suspend event/target
    And for working with systemd, including creating service files, have a look at my bash script you can find here: SysdCmd - systemd Command Help/Config Editor - Blogs - openSUSE Forums

    Thank You,
    My Blog: https://forums.opensuse.org/blogs/jdmcdaniel3/

    Software efficiency halves every 18 months, thus compensating for Moore's Law

    Its James again from Austin, Texas

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •