##// END OF EJS Templates
cmdutil: replace unix pipe handshake with file lock...
Patrick Mezard -
r10238:e22695b4 default
parent child Browse files
Show More
@@ -7,7 +7,7 b''
7
7
8 from node import hex, nullid, nullrev, short
8 from node import hex, nullid, nullrev, short
9 from i18n import _
9 from i18n import _
10 import os, sys, errno, re, glob
10 import os, sys, errno, re, glob, tempfile, time
11 import mdiff, bdiff, util, templater, patch, error, encoding, templatekw
11 import mdiff, bdiff, util, templater, patch, error, encoding, templatekw
12 import match as _match
12 import match as _match
13
13
@@ -567,10 +567,13 b' def service(opts, parentfn=None, initfn='
567 '''Run a command as a service.'''
567 '''Run a command as a service.'''
568
568
569 if opts['daemon'] and not opts['daemon_pipefds']:
569 if opts['daemon'] and not opts['daemon_pipefds']:
570 rfd, wfd = os.pipe()
570 # Signal child process startup with file removal
571 lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-')
572 os.close(lockfd)
573 try:
571 if not runargs:
574 if not runargs:
572 runargs = sys.argv[:]
575 runargs = sys.argv[:]
573 runargs.append('--daemon-pipefds=%d,%d' % (rfd, wfd))
576 runargs.append('--daemon-pipefds=%s' % lockpath)
574 # Don't pass --cwd to the child process, because we've already
577 # Don't pass --cwd to the child process, because we've already
575 # changed directory.
578 # changed directory.
576 for i in xrange(1,len(runargs)):
579 for i in xrange(1,len(runargs)):
@@ -581,8 +584,14 b' def service(opts, parentfn=None, initfn='
581 del runargs[i:i+2]
584 del runargs[i:i+2]
582 break
585 break
583 pid = util.spawndetached(runargs)
586 pid = util.spawndetached(runargs)
584 os.close(wfd)
587 while os.path.exists(lockpath):
585 os.read(rfd, 1)
588 time.sleep(0.1)
589 finally:
590 try:
591 os.unlink(lockpath)
592 except OSError, e:
593 if e.errno != errno.ENOENT:
594 raise
586 if parentfn:
595 if parentfn:
587 return parentfn(pid)
596 return parentfn(pid)
588 else:
597 else:
@@ -598,14 +607,12 b' def service(opts, parentfn=None, initfn='
598 fp.close()
607 fp.close()
599
608
600 if opts['daemon_pipefds']:
609 if opts['daemon_pipefds']:
601 rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')]
610 lockpath = opts['daemon_pipefds']
602 os.close(rfd)
603 try:
611 try:
604 os.setsid()
612 os.setsid()
605 except AttributeError:
613 except AttributeError:
606 pass
614 pass
607 os.write(wfd, 'y')
615 os.unlink(lockpath)
608 os.close(wfd)
609 sys.stdout.flush()
616 sys.stdout.flush()
610 sys.stderr.flush()
617 sys.stderr.flush()
611
618
General Comments 0
You need to be logged in to leave comments. Login now