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