Show More
@@ -355,7 +355,18 b' class server(object):' | |||||
355 | ) |
|
355 | ) | |
356 |
|
356 | |||
357 | try: |
|
357 | try: | |
358 | ret = self._dispatchcommand(req) & 255 |
|
358 | err = None | |
|
359 | try: | |||
|
360 | status = self._dispatchcommand(req) | |||
|
361 | except error.StdioError as e: | |||
|
362 | status = -1 | |||
|
363 | err = e | |||
|
364 | ||||
|
365 | retval = dispatch.closestdio(req.ui, err) | |||
|
366 | if retval: | |||
|
367 | status = retval | |||
|
368 | ||||
|
369 | ret = status & 255 | |||
359 | # If shutdown-on-interrupt is off, it's important to write the |
|
370 | # If shutdown-on-interrupt is off, it's important to write the | |
360 | # result code *after* SIGINT handler removed. If the result code |
|
371 | # result code *after* SIGINT handler removed. If the result code | |
361 | # were lost, the client wouldn't be able to continue processing. |
|
372 | # were lost, the client wouldn't be able to continue processing. |
@@ -104,6 +104,35 b' class request(object):' | |||||
104 | raise exc |
|
104 | raise exc | |
105 |
|
105 | |||
106 |
|
106 | |||
|
107 | def closestdio(ui, err): | |||
|
108 | status = None | |||
|
109 | # In all cases we try to flush stdio streams. | |||
|
110 | if util.safehasattr(ui, b'fout'): | |||
|
111 | assert ui is not None # help pytype | |||
|
112 | assert ui.fout is not None # help pytype | |||
|
113 | try: | |||
|
114 | ui.fout.flush() | |||
|
115 | except IOError as e: | |||
|
116 | err = e | |||
|
117 | status = -1 | |||
|
118 | ||||
|
119 | if util.safehasattr(ui, b'ferr'): | |||
|
120 | assert ui is not None # help pytype | |||
|
121 | assert ui.ferr is not None # help pytype | |||
|
122 | try: | |||
|
123 | if err is not None and err.errno != errno.EPIPE: | |||
|
124 | ui.ferr.write( | |||
|
125 | b'abort: %s\n' % encoding.strtolocal(err.strerror) | |||
|
126 | ) | |||
|
127 | ui.ferr.flush() | |||
|
128 | # There's not much we can do about an I/O error here. So (possibly) | |||
|
129 | # change the status code and move on. | |||
|
130 | except IOError: | |||
|
131 | status = -1 | |||
|
132 | ||||
|
133 | return status | |||
|
134 | ||||
|
135 | ||||
107 | def run(): |
|
136 | def run(): | |
108 | """run the command in sys.argv""" |
|
137 | """run the command in sys.argv""" | |
109 | try: |
|
138 | try: | |
@@ -117,30 +146,9 b' def run():' | |||||
117 | err = e |
|
146 | err = e | |
118 | status = -1 |
|
147 | status = -1 | |
119 |
|
148 | |||
120 | # In all cases we try to flush stdio streams. |
|
149 | ret = closestdio(req.ui, err) | |
121 | if util.safehasattr(req.ui, b'fout'): |
|
150 | if ret: | |
122 | assert req.ui is not None # help pytype |
|
151 | status = ret | |
123 | assert req.ui.fout is not None # help pytype |
|
|||
124 | try: |
|
|||
125 | req.ui.fout.flush() |
|
|||
126 | except IOError as e: |
|
|||
127 | err = e |
|
|||
128 | status = -1 |
|
|||
129 |
|
||||
130 | if util.safehasattr(req.ui, b'ferr'): |
|
|||
131 | assert req.ui is not None # help pytype |
|
|||
132 | assert req.ui.ferr is not None # help pytype |
|
|||
133 | try: |
|
|||
134 | if err is not None and err.errno != errno.EPIPE: |
|
|||
135 | req.ui.ferr.write( |
|
|||
136 | b'abort: %s\n' % encoding.strtolocal(err.strerror) |
|
|||
137 | ) |
|
|||
138 | req.ui.ferr.flush() |
|
|||
139 | # There's not much we can do about an I/O error here. So (possibly) |
|
|||
140 | # change the status code and move on. |
|
|||
141 | except IOError: |
|
|||
142 | status = -1 |
|
|||
143 |
|
||||
144 | _silencestdio() |
|
152 | _silencestdio() | |
145 | except KeyboardInterrupt: |
|
153 | except KeyboardInterrupt: | |
146 | # Catch early/late KeyboardInterrupt as last ditch. Here nothing will |
|
154 | # Catch early/late KeyboardInterrupt as last ditch. Here nothing will |
General Comments 0
You need to be logged in to leave comments.
Login now