2038
|
1 |
--- elisa-1.0.6/elisa/core/utils/misc.py-orig 2009-08-06 11:25:58.307494000 -0500
|
|
2 |
+++ elisa-1.0.6/elisa/core/utils/misc.py 2009-08-06 11:26:55.181318000 -0500
|
|
3 |
@@ -25,6 +25,7 @@ reasonnably small.
|
|
4 |
import platform
|
|
5 |
import os, re
|
|
6 |
import subprocess
|
|
7 |
+import threading
|
|
8 |
|
|
9 |
from twisted.trial.unittest import SkipTest
|
|
10 |
|
|
11 |
@@ -209,17 +210,30 @@ def get_os_name():
|
|
12 |
else:
|
|
13 |
return platform.system().lower()
|
|
14 |
|
|
15 |
-def linux_pidof(program_name):
|
|
16 |
+def unix_pidof(program_name):
|
|
17 |
"""
|
|
18 |
- Get the Linux process id of the given program name. Because
|
|
19 |
+ Get the UNIX process id of the given program name. Because
|
|
20 |
multiple processes can exist, we return a list of the pids.
|
|
21 |
|
|
22 |
@rtype: C{list} of C{int}
|
|
23 |
@returns: the list of running pids of given program name
|
|
24 |
"""
|
|
25 |
- output = subprocess.Popen(["pidof", program_name],
|
|
26 |
- stderr=subprocess.STDOUT,
|
|
27 |
- stdout=subprocess.PIPE).communicate()[0]
|
|
28 |
+ try:
|
|
29 |
+ lock = threading.Lock()
|
|
30 |
+ lock.acquire()
|
|
31 |
+ if platform.system() == 'SunOS':
|
|
32 |
+ output = subprocess.Popen(["/bin/sh", "-c", "/usr/bin/pgrep -u `whoami` %s" % program_name],
|
|
33 |
+ stderr=subprocess.STDOUT,
|
|
34 |
+ stdout=subprocess.PIPE,
|
|
35 |
+ close_fds=True).communicate()[0]
|
|
36 |
+ else:
|
|
37 |
+ output = subprocess.Popen(["pidof", program_name],
|
|
38 |
+ stderr=subprocess.STDOUT,
|
|
39 |
+ stdout=subprocess.PIPE,
|
|
40 |
+ close_fds=True).communicate()[0]
|
|
41 |
+ finally:
|
|
42 |
+ lock.release()
|
|
43 |
+
|
|
44 |
return [int(pid) for pid in output.split()]
|
|
45 |
|
|
46 |
def get_user_desktop_name():
|
|
47 |
@@ -255,7 +269,7 @@ def get_user_desktop_name():
|
|
48 |
'xfwm4': 'xfce',
|
|
49 |
}
|
|
50 |
for prog, name in progs.iteritems():
|
|
51 |
- if linux_pidof(prog) != []:
|
|
52 |
+ if unix_pidof(prog) != []:
|
|
53 |
desktop_name = name
|
|
54 |
break
|
|
55 |
if desktop_name is None:
|