diff options
| author | Dirk | 2013-12-12 11:18:18 +0100 |
|---|---|---|
| committer | Dirk | 2013-12-12 11:18:18 +0100 |
| commit | b614bbbe854cd12d94074c04c70dee049b9bdf4f (patch) | |
| tree | 9f75eedb2bc7d007918fa156dc5e1b21172fe6ee /remote/modules/pam | |
| parent | Removing unneeded (deprecated) hwinfo stuff ... (diff) | |
| parent | [rootfs-stage32] add macvtap module to wanted kernel module list (diff) | |
| download | tm-scripts-b614bbbe854cd12d94074c04c70dee049b9bdf4f.tar.gz tm-scripts-b614bbbe854cd12d94074c04c70dee049b9bdf4f.tar.xz tm-scripts-b614bbbe854cd12d94074c04c70dee049b9bdf4f.zip | |
Merge branch 'master' of git.openslx.org:openslx-ng/tm-scripts
...
Diffstat (limited to 'remote/modules/pam')
| -rwxr-xr-x | remote/modules/pam/data/opt/openslx/scripts/pam_script_ses_close | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/remote/modules/pam/data/opt/openslx/scripts/pam_script_ses_close b/remote/modules/pam/data/opt/openslx/scripts/pam_script_ses_close index d3b5ebb3..535cd0d6 100755 --- a/remote/modules/pam/data/opt/openslx/scripts/pam_script_ses_close +++ b/remote/modules/pam/data/opt/openslx/scripts/pam_script_ses_close @@ -7,30 +7,42 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/o slxlog "session-close" "$PAM_USER logged out on $PAM_TTY" # do not kill all root processes :) -[ "x${PAM_USER}" == "xroot" ] && exit 0 +[ "x${PAM_USER}" = "xroot" ] && exit 0 +# can only work if script is run as root +[ "x$(whoami)" = "xroot" ] || exit 0 -OPENSESSIONS=$(loginctl | grep "${PAM_USER}" | wc -l) +OPENSESSION=$(loginctl show-user "$PAM_USER" | grep "Sessions=" | cut -c 10-) +SESSIONCOUNT=$(echo "$OPENSESSION" | wc -w) -if [ "x${OPENSESSIONS}" == "x1" ]; then +if [ "$SESSIONCOUNT" = "1" ]; then # last sessions, close all ghost user processes + usleep 500000 pkill -u "${PAM_USER}" # check if user's process are still running - for TIMEOUT in 1 1 1 2; do - if ! ps aux | grep -v grep | grep -q "${PAM_USER}"; then - break; + for TIMEOUT in 1 1 2 FAIL; do + if [ "$TIMEOUT" = "FAIL" ]; then + # still something running, send SIGKILL + pkill -9 -u "${PAM_USER}" + break fi + if ! ps -o pid,s -u "$PAM_USER" -U "$PAM_USER" | grep -q -v -E "PID|Z"; then + # nothing running anymore + break + fi + # give some time sleep "${TIMEOUT}" done - # all done, kill it again to be sure - pkill -9 -u "${PAM_USER}" - - # unmount the home directory structure - umount -l "/home/${PAM_USER}/PERSISTENT" || \ - echo "Could not unmount '/home/${PAM_USER}/PERSISTENT'." + # just to be sure we check if there's no other open session in the meantime + OPEN2=$(loginctl show-user "$PAM_USER" | grep "Sessions=" | cut -c 10-) + if [ -z "$OPEN2" -o "x$OPENSESSION" = "x$OPEN2" ]; then + # unmount the home directory structure + umount -l "/home/${PAM_USER}/PERSISTENT" || \ + echo "Could not unmount '/home/${PAM_USER}/PERSISTENT'." - umount -l "/home/${PAM_USER}" || \ - echo "Could not unmount '/home/${PAM_USER}'." + umount -l "/home/${PAM_USER}" || \ + echo "Could not unmount '/home/${PAM_USER}'." + fi fi exit 0 |
