53 procutil.stderr.flush() |
53 procutil.stderr.flush() |
54 |
54 |
55 fd = os.open(postexecargs['unlink'], |
55 fd = os.open(postexecargs['unlink'], |
56 os.O_WRONLY | os.O_APPEND | os.O_BINARY) |
56 os.O_WRONLY | os.O_APPEND | os.O_BINARY) |
57 try: |
57 try: |
58 os.dup2(fd, 1) |
58 os.dup2(fd, procutil.stdout.fileno()) |
59 os.dup2(fd, 2) |
59 os.dup2(fd, procutil.stderr.fileno()) |
60 finally: |
60 finally: |
61 os.close(fd) |
61 os.close(fd) |
62 |
62 |
63 def writepid(pid): |
63 def writepid(pid): |
64 if opts['pid_file']: |
64 if opts['pid_file']: |
92 pid = procutil.rundetached(runargs, condfn) |
92 pid = procutil.rundetached(runargs, condfn) |
93 if pid < 0: |
93 if pid < 0: |
94 # If the daemonized process managed to write out an error msg, |
94 # If the daemonized process managed to write out an error msg, |
95 # report it. |
95 # report it. |
96 if pycompat.iswindows and os.path.exists(lockpath): |
96 if pycompat.iswindows and os.path.exists(lockpath): |
97 with open(lockpath) as log: |
97 with open(lockpath, 'rb') as log: |
98 for line in log: |
98 for line in log: |
99 procutil.stderr.write(line) |
99 procutil.stderr.write(line) |
100 raise error.Abort(_('child process failed to start')) |
100 raise error.Abort(_('child process failed to start')) |
101 writepid(pid) |
101 writepid(pid) |
102 finally: |
102 finally: |
127 nullfd = os.open(os.devnull, os.O_RDWR) |
127 nullfd = os.open(os.devnull, os.O_RDWR) |
128 logfilefd = nullfd |
128 logfilefd = nullfd |
129 if logfile: |
129 if logfile: |
130 logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND, |
130 logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND, |
131 0o666) |
131 0o666) |
132 os.dup2(nullfd, 0) |
132 os.dup2(nullfd, procutil.stdin.fileno()) |
133 os.dup2(logfilefd, 1) |
133 os.dup2(logfilefd, procutil.stdout.fileno()) |
134 os.dup2(logfilefd, 2) |
134 os.dup2(logfilefd, procutil.stderr.fileno()) |
135 if nullfd not in (0, 1, 2): |
135 stdio = (procutil.stdin.fileno(), procutil.stdout.fileno(), |
|
136 procutil.stderr.fileno()) |
|
137 if nullfd not in stdio: |
136 os.close(nullfd) |
138 os.close(nullfd) |
137 if logfile and logfilefd not in (0, 1, 2): |
139 if logfile and logfilefd not in stdio: |
138 os.close(logfilefd) |
140 os.close(logfilefd) |
139 |
141 |
140 # Only unlink after redirecting stdout/stderr, so Windows doesn't |
142 # Only unlink after redirecting stdout/stderr, so Windows doesn't |
141 # complain about a sharing violation. |
143 # complain about a sharing violation. |
142 if 'unlink' in postexecargs: |
144 if 'unlink' in postexecargs: |