- 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:
junglecow 2006-11-22 20:56:25 +00:00
parent 7cdb177558
commit 9694f931bf
1 changed files with 29 additions and 8 deletions

View File

@ -144,25 +144,46 @@ gajimpaths = common.configpaths.gajimpaths
pid_filename = gajimpaths['PID_FILE']
config_filename = gajimpaths['CONFIG_FILE']
import traceback
import errno
import dialogs
def pid_alive():
if os.name == 'nt':
if os.path.exists(pid_filename):
return True
return False
try:
try:
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())
pf.close()
f = open('/proc/%d/status'% pid)
n = f.readline()
try:
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()
n = n.split()[1].strip()
if n == 'gajim':
return True
if n.find('gajim') < 0:
return False
return True # Running Gajim found at pid
except:
pass
return False
traceback.print_exc()
# If we are here, pidfile exists, but some unexpected error occured.
# Assume Gajim is running.
return True
if pid_alive():
path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps/gajim.png')