Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 9513:ae88c721f916
cmdutil: service: add an optional runargs argument to pass the command to run
This would be necessary for inotify launching its server: the initial command
is a standard 'hg st'/'hg ci'/... but the daemon to run is 'hg inserve'
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Sun, 16 Aug 2009 11:30:24 +0900 |
parents | 1ef630452e0b |
children | f04d17912441 |
comparison
equal
deleted
inserted
replaced
9512:e7bde4680eec | 9513:ae88c721f916 |
---|---|
544 if errors: | 544 if errors: |
545 ui.warn(_('(consider using --after)\n')) | 545 ui.warn(_('(consider using --after)\n')) |
546 | 546 |
547 return errors | 547 return errors |
548 | 548 |
549 def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None): | 549 def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None, |
550 runargs=None): | |
550 '''Run a command as a service.''' | 551 '''Run a command as a service.''' |
551 | 552 |
552 if opts['daemon'] and not opts['daemon_pipefds']: | 553 if opts['daemon'] and not opts['daemon_pipefds']: |
553 rfd, wfd = os.pipe() | 554 rfd, wfd = os.pipe() |
554 args = sys.argv[:] | 555 if not runargs: |
555 args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) | 556 runargs = sys.argv[:] |
557 runargs.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) | |
556 # Don't pass --cwd to the child process, because we've already | 558 # Don't pass --cwd to the child process, because we've already |
557 # changed directory. | 559 # changed directory. |
558 for i in xrange(1,len(args)): | 560 for i in xrange(1,len(runargs)): |
559 if args[i].startswith('--cwd='): | 561 if runargs[i].startswith('--cwd='): |
560 del args[i] | 562 del runargs[i] |
561 break | 563 break |
562 elif args[i].startswith('--cwd'): | 564 elif runargs[i].startswith('--cwd'): |
563 del args[i:i+2] | 565 del runargs[i:i+2] |
564 break | 566 break |
565 pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), | 567 pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
566 args[0], args) | 568 runargs[0], runargs) |
567 os.close(wfd) | 569 os.close(wfd) |
568 os.read(rfd, 1) | 570 os.read(rfd, 1) |
569 if parentfn: | 571 if parentfn: |
570 return parentfn(pid) | 572 return parentfn(pid) |
571 else: | 573 else: |