From 4d9e58a580f8b289eb7a23486155092e4ec61ace Mon Sep 17 00:00:00 2001 From: Yann Leboulanger <asterix@lagaule.org> Date: Wed, 22 Nov 2006 16:15:16 +0000 Subject: [PATCH] better pid behaviour. we now in process list if pid contained in gajim.pid is still gajim. fixes #2165. (Linux only) --- src/gajim.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/gajim.py b/src/gajim.py index 75e53e439a..9e00b2946b 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -145,7 +145,26 @@ config_filename = gajimpaths['CONFIG_FILE'] import dialogs -if os.path.exists(pid_filename): +def pid_alive(): + if os.name == 'nt': + if os.path.exists(pid_filename): + return True + return False + try: + pf = open(pid_filename) + pid = int(pf.read().strip()) + pf.close() + f = open('/proc/%d/status'% pid) + n = f.readline() + f.close() + n = n.split()[1].strip() + if n == 'gajim': + return True + except: + pass + return False + +if pid_alive(): path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps/gajim.png') pix = gtk.gdk.pixbuf_new_from_file(path_to_file) gtk.window_set_default_icon(pix) # set the icon to all newly opened wind @@ -168,7 +187,8 @@ if not os.path.exists(pid_dir): check_paths.create_path(pid_dir) # Create pid file -f = open(pid_filename, 'a') +f = open(pid_filename, 'w') +f.write(str(os.getpid())) f.close() del pid_dir -- GitLab