##// END OF EJS Templates
cmdutil: service: logfile option to redirect stdout & stderr in a file
Nicolas Dumazet -
r8789:e0ed1798 default
parent child Browse files
Show More
@@ -537,7 +537,7 b' def copy(ui, repo, pats, opts, rename=Fa'
537
537
538 return errors
538 return errors
539
539
540 def service(opts, parentfn=None, initfn=None, runfn=None):
540 def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None):
541 '''Run a command as a service.'''
541 '''Run a command as a service.'''
542
542
543 if opts['daemon'] and not opts['daemon_pipefds']:
543 if opts['daemon'] and not opts['daemon_pipefds']:
@@ -581,11 +581,18 b' def service(opts, parentfn=None, initfn='
581 os.close(wfd)
581 os.close(wfd)
582 sys.stdout.flush()
582 sys.stdout.flush()
583 sys.stderr.flush()
583 sys.stderr.flush()
584 fd = os.open(util.nulldev, os.O_RDWR)
584
585 if fd != 0: os.dup2(fd, 0)
585 nullfd = os.open(util.nulldev, os.O_RDWR)
586 if fd != 1: os.dup2(fd, 1)
586 logfilefd = nullfd
587 if fd != 2: os.dup2(fd, 2)
587 if logfile:
588 if fd not in (0, 1, 2): os.close(fd)
588 logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND)
589 os.dup2(nullfd, 0)
590 os.dup2(logfilefd, 1)
591 os.dup2(logfilefd, 2)
592 if nullfd not in (0, 1, 2):
593 os.close(nullfd)
594 if logfile and logfilefd not in (0, 1, 2):
595 os.close(logfilefd)
589
596
590 if runfn:
597 if runfn:
591 return runfn()
598 return runfn()
General Comments 0
You need to be logged in to leave comments. Login now