##// END OF EJS Templates
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet -
r9514:7c01599d default
parent child Browse files
Show More
@@ -17,28 +17,7 b' from client import client, QueryFailed'
17 17
18 18 def serve(ui, repo, **opts):
19 19 '''start an inotify server for this repository'''
20 timeout = opts.get('timeout')
21 if timeout:
22 timeout = float(timeout) * 1e3
23
24 class service(object):
25 def init(self):
26 try:
27 self.master = server.master(ui, repo.dirstate,
28 repo.root, timeout)
29 except server.AlreadyStartedException, inst:
30 raise util.Abort(str(inst))
31
32 def run(self):
33 try:
34 self.master.run()
35 finally:
36 self.master.shutdown()
37
38 service = service()
39 logfile = ui.config('inotify', 'log')
40 cmdutil.service(opts, initfn=service.init, runfn=service.run,
41 logfile=logfile)
20 server.start(ui, repo.dirstate, repo.root, opts)
42 21
43 22 def debuginotify(ui, repo, **opts):
44 23 '''debugging information for inotify extension
@@ -34,7 +34,8 b' def start_server(function):'
34 34 self.ui.debug('(starting inotify server)\n')
35 35 try:
36 36 try:
37 server.start(self.ui, self.dirstate, self.root)
37 server.start(self.ui, self.dirstate, self.root,
38 dict(daemon=True, daemon_pipefds=''))
38 39 except server.AlreadyStartedException, inst:
39 40 # another process may have started its own
40 41 # inotify server while this one was starting.
@@ -7,7 +7,7 b''
7 7 # GNU General Public License version 2, incorporated herein by reference.
8 8
9 9 from mercurial.i18n import _
10 from mercurial import osutil, util
10 from mercurial import cmdutil, osutil, util
11 11 import common
12 12 import errno, os, select, socket, stat, struct, sys, tempfile, time
13 13
@@ -823,52 +823,29 b' class master(object):'
823 823 sys.exit(0)
824 824 pollable.run()
825 825
826 def start(ui, dirstate, root):
827 def closefds(ignore):
828 # (from python bug #1177468)
829 # close all inherited file descriptors
830 # Python 2.4.1 and later use /dev/urandom to seed the random module's RNG
831 # a file descriptor is kept internally as os._urandomfd (created on demand
832 # the first time os.urandom() is called), and should not be closed
833 try:
834 os.urandom(4)
835 urandom_fd = getattr(os, '_urandomfd', None)
836 except AttributeError:
837 urandom_fd = None
838 ignore.append(urandom_fd)
839 for fd in range(3, 256):
840 if fd in ignore:
841 continue
826 def start(ui, dirstate, root, opts):
827 timeout = opts.get('timeout')
828 if timeout:
829 timeout = float(timeout) * 1e3
830
831 class service(object):
832 def init(self):
842 833 try:
843 os.close(fd)
844 except OSError:
845 pass
846
847 m = master(ui, dirstate, root)
848 sys.stdout.flush()
849 sys.stderr.flush()
834 self.master = master(ui, dirstate, root, timeout)
835 except AlreadyStartedException, inst:
836 raise util.Abort(str(inst))
850 837
851 pid = os.fork()
852 if pid:
853 return pid
854
855 closefds(pollable.instances.keys())
856 os.setsid()
857
858 fd = os.open('/dev/null', os.O_RDONLY)
859 os.dup2(fd, 0)
860 if fd > 0:
861 os.close(fd)
838 def run(self):
839 try:
840 self.master.run()
841 finally:
842 self.master.shutdown()
862 843
863 fd = os.open(ui.config('inotify', 'log', '/dev/null'),
864 os.O_RDWR | os.O_CREAT | os.O_TRUNC)
865 os.dup2(fd, 1)
866 os.dup2(fd, 2)
867 if fd > 2:
868 os.close(fd)
844 runargs = None
845 if 'inserve' not in sys.argv:
846 runargs = [sys.argv[0], 'inserve', '-R', root]
869 847
870 try:
871 m.run()
872 finally:
873 m.shutdown()
874 os._exit(0)
848 service = service()
849 logfile = ui.config('inotify', 'log')
850 cmdutil.service(opts, initfn=service.init, runfn=service.run,
851 logfile=logfile, runargs=runargs)
@@ -1,5 +1,5 b''
1 1 % fail
2 could not talk to new inotify server: No such file or directory
2 abort: could not start server: File exists
3 3 abort: could not start server: File exists
4 4 % inserve
5 5 % status
General Comments 0
You need to be logged in to leave comments. Login now