diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2012-08-15 21:33:25 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2012-08-15 21:33:25 (GMT) |
commit | 67483e134c7b255988f8dfd56c5c21767ffb05f3 (patch) | |
tree | 7ebf6c2847ffd2b759ce105ac734418f27957fa9 | |
parent | e9efce579d2e07360fd98393ced2206fdcf5d688 (diff) |
Create .pid file
-rwxr-xr-x | sugar-network-service | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/sugar-network-service b/sugar-network-service index ce425b3..280b654 100755 --- a/sugar-network-service +++ b/sugar-network-service @@ -19,6 +19,7 @@ import os import sys import json import shlex +import errno import signal import locale import logging @@ -147,6 +148,10 @@ class Application(application.Application): 'start service and log to files', name='start', keep_stdout=True) def _start(self): + if self.check_for_instance(): + printf.info('%s is not run', self.name) + exit(1) + # In case if it is new Sugar Shell profile toolkit.ensure_dsa_pubkey(sugar.profile_path('owner.key')) @@ -197,6 +202,7 @@ class Application(application.Application): jobs.spawn(IPCServer(mountset).serve_forever) + pid_path = self.new_instance() try: mountset.open() dbus_thread.start(mountset) @@ -208,6 +214,7 @@ class Application(application.Application): mounts_monitor.stop() jobs.kill() mountset.close() + os.unlink(pid_path) @contextmanager def _rendezvous(self): @@ -265,9 +272,14 @@ class Application(application.Application): def __SIGCHLD_cb(self): while True: - pid, __ = os.waitpid(-1, os.WNOHANG) - if not pid: - break + try: + pid, __ = os.waitpid(-1, os.WNOHANG) + if pid: + continue + except OSError, error: + if error.errno != errno.ECHILD: + raise + break locale.setlocale(locale.LC_ALL, '') |