OLD | NEW |
(Empty) | |
| 1 #!/bin/bash |
| 2 |
| 3 suid-python <<END |
| 4 |
| 5 import Foundation |
| 6 import os |
| 7 import subprocess |
| 8 import tempfile |
| 9 import time |
| 10 |
| 11 SERVICE_NAME = "org.chromium.chromoting" |
| 12 |
| 13 def is_job_running(): |
| 14 process = subprocess.Popen(["launchctl", "list"], stdout=subprocess.PIPE) |
| 15 is_running = False |
| 16 for line in process.stdout: |
| 17 # Format is: |
| 18 # 12345 - my.job (if my.job is running, number is job's PID) |
| 19 # - 0 my.other.job (if my.other.job is not running) |
| 20 print "*** %s ***" % line |
| 21 fields = line.strip().split('\t') |
| 22 if fields[2] == SERVICE_NAME and fields[0] != "-": |
| 23 is_running = True |
| 24 break |
| 25 process.wait() |
| 26 return is_running |
| 27 |
| 28 print "*** Started mock pref pane ***" |
| 29 print "*** EUID=%d, UID=%d ***" % (os.geteuid(), os.getuid()) |
| 30 |
| 31 config_file = os.path.join(tempfile.gettempdir(), |
| 32 "%s.json" % SERVICE_NAME) |
| 33 |
| 34 print "*** config_file=%s" % config_file |
| 35 |
| 36 tool_script = "/Library/PrivilegedHelperTools/%s.me2me.sh" % SERVICE_NAME |
| 37 |
| 38 real_user_id = os.getuid() |
| 39 |
| 40 # Elevate privileges, otherwise tool_script executes with EUID != 0. |
| 41 os.setuid(0) |
| 42 subprocess.call([tool_script, "--disable"], stdin=open(config_file)) |
| 43 |
| 44 # Drop privileges, in order to start the launchd job as the logged-in user. |
| 45 os.setuid(real_user_id) |
| 46 subprocess.call(["launchctl", "stop", SERVICE_NAME]) |
| 47 |
| 48 # Starting a launchd job is an asynchronous operation that typically takes |
| 49 # a couple of seconds, so poll until the job has started. |
| 50 is_running = True |
| 51 for i in range(1, 10): |
| 52 if not is_job_running(): |
| 53 is_running = False |
| 54 break |
| 55 time.sleep(2) |
| 56 |
| 57 print "*** is_runnning = %d" % is_running |
| 58 |
| 59 notification_center = Foundation.NSDistributedNotificationCenter.defaultCenter() |
| 60 notification_center.postNotificationName_object_userInfo_( |
| 61 SERVICE_NAME + ".update_succeeded", None, None) |
| 62 |
| 63 time.sleep(10) |
| 64 |
| 65 END |
OLD | NEW |