- More conservative PID file handling:
- Assume Gajim is running if pid's commandline contains 'gajim' anywhere. (The chance that it's some other process is very small, better safe than sorry.) (Linux only) - On non-Windows OS without /proc, assume Gajim is running if pid file exists.
This commit is contained in:
parent
7cdb177558
commit
9694f931bf
37
src/gajim.py
37
src/gajim.py
|
@ -144,25 +144,46 @@ gajimpaths = common.configpaths.gajimpaths
|
||||||
pid_filename = gajimpaths['PID_FILE']
|
pid_filename = gajimpaths['PID_FILE']
|
||||||
config_filename = gajimpaths['CONFIG_FILE']
|
config_filename = gajimpaths['CONFIG_FILE']
|
||||||
|
|
||||||
|
import traceback
|
||||||
|
import errno
|
||||||
|
|
||||||
import dialogs
|
import dialogs
|
||||||
def pid_alive():
|
def pid_alive():
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
if os.path.exists(pid_filename):
|
if os.path.exists(pid_filename):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
try:
|
|
||||||
|
try:
|
||||||
pf = open(pid_filename)
|
pf = open(pid_filename)
|
||||||
|
except:
|
||||||
|
# probably file not found
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not os.path.exists('/proc'):
|
||||||
|
return True # no /proc, assume Gajim is running
|
||||||
|
|
||||||
|
try:
|
||||||
pid = int(pf.read().strip())
|
pid = int(pf.read().strip())
|
||||||
pf.close()
|
pf.close()
|
||||||
f = open('/proc/%d/status'% pid)
|
try:
|
||||||
n = f.readline()
|
f = open('/proc/%d/cmdline'% pid)
|
||||||
|
except IOError, e:
|
||||||
|
if e.errno == errno.ENOENT:
|
||||||
|
return False # file/pid does not exist
|
||||||
|
raise
|
||||||
|
|
||||||
|
n = f.read().lower()
|
||||||
f.close()
|
f.close()
|
||||||
n = n.split()[1].strip()
|
if n.find('gajim') < 0:
|
||||||
if n == 'gajim':
|
return False
|
||||||
return True
|
return True # Running Gajim found at pid
|
||||||
except:
|
except:
|
||||||
pass
|
traceback.print_exc()
|
||||||
return False
|
|
||||||
|
# If we are here, pidfile exists, but some unexpected error occured.
|
||||||
|
# Assume Gajim is running.
|
||||||
|
return True
|
||||||
|
|
||||||
if pid_alive():
|
if pid_alive():
|
||||||
path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps/gajim.png')
|
path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps/gajim.png')
|
||||||
|
|
Loading…
Reference in New Issue