← Back to team overview

desktop-packages team mailing list archive

[Bug 1322275] Re: lightdm sessions started by dm-tool lock (or a session locker) never get closed

 

For those desperate because they work for companies who take locking
screen as a serious thing, this is the workaround I came with, have been
running for a few weeks and it does the job well so far.

The script if run via cron every 10 mins will keep your system clean of
lightdm dead sessions, your system will not get sluggish over time, this
is not an ideal solution but it is a good compromise until the issue is
fixed for good.

[begin file: lightdm_clean.sh]
#!/bin/bash
# Cleans lightdm session leftovers in Ubuntu 14.04.x
# Christian Uceda 2015 v0.0.2
set -u

declare PID=""
declare -i SESSION_COUNTER=0
declare -i INDICATOR_COUNTER=0
declare STATUS=""
declare SESSION=""
declare CRONMODE=""

# Send output to the console if not running on cron mode
function echo_print(){
    if [ ! "${CRONMODE}" == "yes" ]
    then
        echo -e "${1:-}"
    fi
}

# -------------------------8<--------------------- Script body

# Root required
if [ $(id -u) -ne 0 ]
then
    echo -e "\nI can only run as root.\n"
    exit 1
fi

if [ "${1:-}" == "-cron" ]
then
    CRONMODE="yes"
fi

# Get rid of lightdm "closing" sessions
while read SESSION
do    
    STATUS=$(loginctl session-status "${SESSION}" | awk '$1~/State/ {print $2}')
    if [ "${STATUS}" == "closing" ]
    then
        ((SESSION_COUNTER++))
        echo_print "Teminating session: ${SESSION}"
        loginctl kill-session "${SESSION}" &>/dev/null
    fi
done < <(loginctl | awk '$3~/lightdm/ {print $1}')
echo_print "\nTerminated: ${SESSION_COUNTER} sessions.\n"

# Notify if there are still some stray indicators (if not running in cron mode) can be removed if desired.
# I used it to verify the operation did not left any stray indicators.
if [ ! "${CRONMODE}" = "yes" ]
then
    while read PID
    do
        ((INDICATOR_COUNTER++))
        if [ ! "${PID}" == "" ]
        then
            echo_print "Found indicator pid: ${PID}"
        fi
    done < <(ps aux | awk '$0~/^[l]ightdm.*indicator-services-start/ {print $2}')
    echo_print "Found: ${INDICATOR_COUNTER} stray indicators.\n"
fi

exit 0
[end of file]

To test it lock and unlock the screen a couple of times and then run it
manually, run it from root's cron like:

*/10   *  *    *   *    /usr/local/sbin/lightdm_clean.sh -cron

-- 
You received this bug notification because you are a member of Desktop
Packages, which is subscribed to lightdm in Ubuntu.
https://bugs.launchpad.net/bugs/1322275

Title:
  lightdm sessions started by dm-tool lock (or a session locker) never
  get closed

Status in Light Display Manager:
  New
Status in lightdm package in Ubuntu:
  Confirmed
Status in upstart package in Ubuntu:
  Confirmed

Bug description:
  dm-tool lock starts a new lightdm greeter (for unlocking) and a new
  logind session. After unlocking the greeter disappears, but the logind
  session never closes. loginctl session status c24 reports something
  like:

  c24 - lightdm (103)
             Since: Thu 2014-05-22 18:38:27 CEST; 30min ago
            Leader: 7872
              Seat: seat0; vc8
           Display: :1
           Service: lightdm-greeter; type x11; class greeter
             State: closing
            CGroup: systemd:/user/103.user/c24.session
                    └─7907 init --user --startup-event indicator-services-start

  This results in an accumulation of stale lightdm sessions after using
  e.g. a session locker for a while.

  I get this issue on a freshly installed and fully updated Xubuntu
  14.04.

To manage notifications about this bug go to:
https://bugs.launchpad.net/lightdm/+bug/1322275/+subscriptions