Opened 10 years ago

Closed 5 years ago

Last modified 5 years ago

#1962 closed defect (fixed)

logoff on suspend

Reported by: Adam Nowotny <adam@…> Owned by: nk
Priority: normal Milestone: 0.15
Component: None Version:
Severity: normal Keywords: suspend, patch
Cc: Kamil, Paral Blocked By:
Blocking: OS: All

Description

Gajim should log off before the system is suspended, which is a common event in a mobile environment. I've used this feature with Psi, and it was very helpful. Right now i get these annoying popups every time turn the laptop back on. This is in progress in #859, but logoff is helpful for people subscribed to my presence. The problem is portability here, it's possible in Windows, but have no idea how's it with other OSes.

Change History (23)

comment:1 Changed 10 years ago by dottedmag@…

What about using gajim-remote in your suspend/resume scripts? Seems to be

trivial task.

comment:2 Changed 10 years ago by Adam Nowotny <adam@…>

I using windows, no script there i guess. Besides i'm the user here, not

developer.

comment:3 Changed 10 years ago by nk

anyone that knows can link us to Psi source (I think they do this stuff)

and they do it cross plat?

comment:4 Changed 10 years ago by jt

Unfortunately, this does not work, at least not on my debian system. I put

"su -c 'gajim-remote change_status offline' $USER" in my suspend script. However, the script runs in a context that does not allow using dbus. At least I could not get it to work. Any suggestions?

comment:5 Changed 10 years ago by dkirov

This is what are signals for. Gajim should disconnect all accounts from

servers on TERM signal and you will just do: kill -15 pid_of_gajim in your suspend script.

comment:6 Changed 10 years ago by sb

Gajim quits on TERM signal. I think it is better to have it disconnect on suspend and connect again on wake up. This is something that is better done in conncection with gnome-power-manager since this allows a generic implementation across distributions, compared to acpi scripts.

comment:8 Changed 10 years ago by sb

It should be alright for mobile entvironment now if network manager is used, at least on linux.

comment:9 Changed 9 years ago by patrys

Not if NetworkManager? does not support your distro (which is the case here - PLD Linux).

comment:10 Changed 9 years ago by nk

MACOSX/Windows http://svn.psi-im.org/listing.php?repname=Psi&path=%2Ftrunk%2Fsrc%2Ftools%2Fsystemwatch%2F#_trunk_src_tools_systemwatch_

[2:12:53 μμ] spike (psi dev): all 3 logoff i would expect
[2:12:56 μμ] nkour: okay
[2:12:58 μμ] spike (psi dev): well, shutdown that is for sure
[2:13:08 μμ] spike (psi dev): suspend and hibernate on windows, both logoff
[2:13:10 μμ] nkour: any idea where you have this code?
[2:13:19 μμ] nkour: which file I should look @?
[2:13:54 μμ] nkour: I guess you also save show, so when you come back from suspend you go that show
[2:14:06 μμ] nkour: if you shutdown, then I don't think you use that show anymore
[2:14:07 μμ] spike (psi dev): well, we don't do that yet, but we should do that yes
[2:14:16 μμ] nkour: oh ok
[2:14:18 μμ] spike (psi dev): we should remember the last available status before shutting down
[2:14:18 μμ] nkour: which file is it?
[2:14:40 μμ] nkour: it's interesting how you do that in MacOSX and in Windows (maybe even Vista works)
[2:14:45 μμ] spike (psi dev): http://svn.psi-im.org/listing.php?repname=Psi&path=%2Ftrunk%2Fsrc%2Ftools%2Fsystemwatch%2F#_trunk_src_tools_systemwatch_
[2:14:47 μμ] spike (psi dev): systemwatch

for Unix:

[2:11:46 μμ] spike (psi dev): it uses SIGUSR, which sounds like something non-standard
[2:11:52 μμ] spike (psi dev): we had a patch that does it on unix

comment:11 Changed 9 years ago by nk

we should watch for:

// These defines come from Microsoft Platform SDK, August 2005
#if(WINVER >= 0x0400)
# ifndef WM_POWERBROADCAST
#  define WM_POWERBROADCAST                0x0218
# endif // WM_POWERBROADCAST
# ifndef _WIN32_WCE
#  ifndef PBT_APMQUERYSUSPEND
#   define PBT_APMQUERYSUSPEND             0x0000
#  endif // PBT_APMQUERYSUSPEND
#  ifndef PBT_APMQUERYSTANDBY
#   define PBT_APMQUERYSTANDBY             0x0001
#  endif // PBT_APMQUERYSTANDBY
#  ifndef PBT_APMQUERYSUSPENDFAILED
#   define PBT_APMQUERYSUSPENDFAILED       0x0002
#  endif // PBT_APMQUERYSUSPENDFAILED
#  ifndef PBT_APMQUERYSTANDBYFAILED
#   define PBT_APMQUERYSTANDBYFAILED       0x0003
#  endif // PBT_APMQUERYSTANDBYFAILED
#  ifndef PBT_APMSUSPEND
#   define PBT_APMSUSPEND                  0x0004
#  endif // PBT_APMSUSPEND
#  ifndef PBT_APMSTANDBY
#   define PBT_APMSTANDBY                  0x0005
#  endif // PBT_APMSTANDBY
#  ifndef PBT_APMRESUMECRITICAL
#   define  PBT_APMRESUMECRITICAL          0x0006
#  endif // PBT_APMRESUMECRITICAL
#  ifndef PBT_APMRESUMESUSPEND
#   define PBT_APMRESUMESUSPEND            0x0007
#  endif // PBT_APMRESUMESUSPEND
#  ifndef PBT_APMRESUMESTANDBY
#   define PBT_APMRESUMESTANDBY            0x0008
#  endif // PBT_APMRESUMESTANDBY
#  ifndef PBTF_APMRESUMEFROMFAILURE
#   define PBTF_APMRESUMEFROMFAILURE       0x00000001
#  endif // PBTF_APMRESUMEFROMFAILURE
#  ifndef PBT_APMBATTERYLOW
#   define PBT_APMBATTERYLOW               0x0009
#  endif // PBT_APMBATTERYLOW
#  ifndef PBT_APMPOWERSTATUSCHANGE
#   define PBT_APMPOWERSTATUSCHANGE        0x000A
#  endif // PBT_APMPOWERSTATUSCHANGE
#  ifndef PBT_APMOEMEVENT
#   define PBT_APMOEMEVENT                 0x000B
#  endif // PBT_APMOEMEVENT
#  ifndef PBT_APMRESUMEAUTOMATIC
#   define PBT_APMRESUMEAUTOMATIC          0x0012
#  endif // PBT_APMRESUMEAUTOMATIC
# endif // _WIN32_WCE
#endif // WINVER >= 0x0400

comment:12 Changed 9 years ago by nk

I looked everywhere. all I could find was win32event.WaitForSingleObject?

and yeah I don't feel like it atm

comment:13 Changed 9 years ago by nk

  • Owner changed from asterix to nk

comment:14 Changed 9 years ago by asterix

  • OS set to All

I did it using wmi, but the signal is emitted too late. Gajim doesn't have time to go offline before going to suspend :/

comment:15 Changed 8 years ago by Kamil Páral

I second this bug. When I shutdown my notebook, Gajim correctly logs off. But if I suspend or hibernate, I am "online" for another 5-15 minutes. All messages which comes in the meantime are lost. That's very inconvenient.

Gajim should listen for suspend/hibernate signals and log off, and log in again after resume.

I use Ubuntu 8.04.

comment:16 Changed 7 years ago by ronny

Some workaround:

(Debian Squeeze, Gajim 0.12.1)

Create a new script file "00gajim" in "/etc/pm/sleep.d/". And add this text into script:

#!/bin/sh

# Script to loggoff/logon gajim
#
# Copyright: Copyright (c) 2009, Jindrich Skacel <ronny63@gmail.com>
# License:   GNU/GPL
#

USERNAME='ronny' # CHANGE THIS!

case "${1}" in
        suspend|hibernate)
                su $USERNAME -c 'gajim-remote change_status offline "Notebook usnul..."'
                ;;
	resume|thaw)
		sleep 10
		su $USERNAME -c 'gajim-remote change_status online'
		;;
esac

Please change USERNAME, because gajim-remote cannot run as root :-) (i am tried use $USER, but $USER is root during suspend). "Sleep 10" is due wifi connection (network manager need some time to connect to my wifi network). I don't know how quick connect wired connection.

comment:17 Changed 7 years ago by ronny

And please if you want, change status from "Notebook usnul..." (in English means "Notebook fell asleep").

Sorry for double post, my mistake :-/

comment:18 Changed 7 years ago by anonymous

Update of script (if Gajim not running suspend failed):

#!/bin/sh

# Script to loggoff/logon gajim
#
# Copyright: Copyright (c) 2009, Jindrich Skacel <ronny63@gmail.com>
# License:   GNU/GPL
#

USERNAME='ronny' # CHANGE THIS!

case "${1}" in
        suspend|hibernate)
               `killall -0 gajim`
                if [ $? =="0" ]; then
                    su $USERNAME -c 'gajim-remote change_status offline "Notebook fall asleep..."'
                fi
                ;;
	resume|thaw)
		sleep 10
		su $USERNAME -c 'gajim-remote change_status online'
		;;
esac

comment:19 Changed 7 years ago by ronny

Updated script :-) Now is working correctly, please create 00gajim at /etc/pm/sleep.d

#!/bin/sh

# Script to loggoff/logon gajim
#
# Copyright: Copyright (c) 2009, Jindrich Skacel <ronny63@gmail.com>
# License:   GNU/GPL
#

USERNAME='ronny' # CHANGE THIS!
SLEEP='10' # After this time, Gajim try to back online (after resume)

PID=`pgrep -u $USERNAME '^gajim$'`
TMP=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ`
export DBUS_SESSION_BUS_ADDRESS=${TMP:25}

case "${1}" in
        suspend|hibernate)
        	su $USERNAME -c 'gajim-remote change_status offline "Notebook fell asleep..."'
        ;;
	resume|thaw)
		sleep $SLEEP
		su $USERNAME -c 'gajim-remote change_status online'
		;;
esac

comment:20 Changed 7 years ago by ronny

And new version of suspend script :-) Many thanks to Blackened :-) You don't have to set any users, script try to find gajim instancies and switch they to offline.

#!/bin/sh

# Set up the field separator:
IFS=$'\n'

# Set sleep time to connect after resume (for wifi)
SLEEP=10

if [ "$1" == "resume" ]; then
	sleep $SLEEP
fi

# Process each instance separately:
for INSTANCE in `ps -eopid,comm,user | grep -e '[\t ]gajim'`; do
  # Decompose the record:
  PID=`echo $INSTANCE | awk '{ print $1 }'`
  USR=`echo $INSTANCE | awk '{ print $3 }'`
#  echo $PID
#  echo $USR

  # Export the DBUS session address:
  TMP=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ`
  export DBUS_SESSION_BUS_ADDRESS=${TMP:25}
#  echo $DBUS_SESSION_BUS_ADDRESS

  # Do something useful here. ;-)
  case "${1}" in
        suspend|hibernate)
        	su $USR -c 'gajim-remote change_status offline "Notebook fell asleep..."'
        ;;
	resume|thaw)
		su $USR -c 'gajim-remote change_status online'
		;;
  esac

done

comment:21 Changed 6 years ago by asterix

  • Resolution set to wontfix
  • Status changed from new to closed

I've added the script to GajimSuspendScript. I don't think we have anything to do in Gajim. I think it's OS work to close it's programs properly before going to sleep.

comment:22 Changed 5 years ago by Kamil Paral

  • Cc Kamil Paral added
  • Keywords patch added
  • Resolution wontfix deleted
  • Status changed from closed to reopened

Reopening this bug. I believe I have enough knowledge now to provide important details.

This is a long-standing very inconvenient bug. Every time I suspend my computer, my account stays online for another 10-15 minutes, and all messages sent to me are completely lost. I'd like to have this solved. Yesterday I finally started working on that. Everything below relates to Linux.

First, it is important to understand the difference between shutdown and suspend. At shutdown operating system sends TERM signal to Gajim, and Gajim disconnects user accounts (making them 'offline') and quits. This works. At suspend however, no classic Unix signal is sent. Gajim has to listen for D-Bus signal of UPower service, which announces machine suspend. When suspend announcement is sent, applications have one second to do whatever they need, and then the machine is suspended. In this one second, Gajim has to disconnect user accounts. If it does not do that (currently it doesn't), then the accounts seem to be "online" for user's buddies for many more minutes. Important: OS can't disconnect Gajim's accounts, it doesn't know how. It can just ask applications to do whatever they need to do before the network connectivity is lost and machine is put to sleep.

I had no time to hack Gajim sources. Instead I have written a simple Python script that listens for UPower D-Bus signal for suspend and when that happens it sets Gajim to offline using gajim-remote command. On system resume it first waits for network connectivity to come up and then restores previous Gajim's state. If you run this Python script on your session start, it will automatically work around this bug for you.

Of course, proper fix in Gajim would be much much better than my little hacks. I believe it should be very simple. All the necessary code should be already in my script. It is enough to listen for UPower 'Suspending' signal and disconnect accounts, and reconnect them on resume after network is again up.

Thank you very much in advance for fixing this one.

My script: https://github.com/kparal/gajim-suspend-watcher/blob/master/gajim-suspend-watcher.py

comment:22 Changed 5 years ago by Yann Leboulanger <asterix@…>

  • Milestone set to 0.15
  • Resolution set to fixed
  • Status changed from reopened to closed

(In [a1bd08ef4ac0]) [Kamil Paral & I] upower support. Fixes #1962

comment:23 Changed 5 years ago by Yann Leboulanger <asterix@…>

(In [acb49650cf22]) [Kamil Paral & I] upower support. Fixes #1962

Note: See TracTickets for help on using tickets.