)]}'
{"neutron/agent/linux/daemon.py":[{"author":{"_account_id":2874,"name":"yong sheng gong","email":"gong.yongsheng@99cloud.net","username":"gongysh"},"change_message_id":"682099d5eafa78c015112952319f15897c7675f3","unresolved":false,"context_lines":[{"line_number":199,"context_line":"        stdin \u003d devnull if self.stdin is DEVNULL else self.stdin"},{"line_number":200,"context_line":"        stdout \u003d devnull if self.stdout is DEVNULL else self.stdout"},{"line_number":201,"context_line":"        stderr \u003d devnull if self.stderr is DEVNULL else self.stderr"},{"line_number":202,"context_line":"        os.dup2(stdin.fileno(), 0)"},{"line_number":203,"context_line":"        os.dup2(stdout.fileno(), 1)"},{"line_number":204,"context_line":"        os.dup2(stderr.fileno(), 2)"},{"line_number":205,"context_line":""}],"source_content_type":"text/x-python","patch_set":2,"id":"7a016987_18a10095","line":202,"updated":"2015-05-15 09:23:10.000000000","message":"can u put the reason why we hardcode 0,1,2 numbers here?","commit_id":"1b78b0c2bced83d402566ee96e3986522dde5182"},{"author":{"_account_id":6854,"name":"YAMAMOTO Takashi","email":"yamamoto@midokura.com","username":"yamamoto"},"change_message_id":"e8e6c582ffd2ef2cc1ffce26624c57685c5cf208","unresolved":false,"context_lines":[{"line_number":36,"context_line":"# - and indeed may not even have a file descriptor at all (eg: test"},{"line_number":37,"context_line":"# fixtures that monkey patch fixtures.StringStream onto sys.stdout)."},{"line_number":38,"context_line":"# Below we always want the _real_ well-known 0,1,2 Unix fds during"},{"line_number":39,"context_line":"# os.dup2 manipulation."},{"line_number":40,"context_line":"STDIN_FILENO \u003d 0"},{"line_number":41,"context_line":"STDOUT_FILENO \u003d 1"},{"line_number":42,"context_line":"STDERR_FILENO \u003d 2"}],"source_content_type":"text/x-python","patch_set":4,"id":"3afb71cf_bf125555","line":39,"updated":"2015-06-10 05:02:55.000000000","message":"i tend to consider it a problem in tests.\n\ni\u0027m not sure what\u0027s the expected consequence of these dup2 calls in case sys.std* is mocked out.","commit_id":"ca3e79e683efe1e7fc7d2a3be14e055ec8450a11"},{"author":{"_account_id":11279,"name":"Angus Lees","email":"gus@inodes.org","username":"gus"},"change_message_id":"887b5d7929d5f5ea252f4e51854d8038a67aa683","unresolved":false,"context_lines":[{"line_number":36,"context_line":"# - and indeed may not even have a file descriptor at all (eg: test"},{"line_number":37,"context_line":"# fixtures that monkey patch fixtures.StringStream onto sys.stdout)."},{"line_number":38,"context_line":"# Below we always want the _real_ well-known 0,1,2 Unix fds during"},{"line_number":39,"context_line":"# os.dup2 manipulation."},{"line_number":40,"context_line":"STDIN_FILENO \u003d 0"},{"line_number":41,"context_line":"STDOUT_FILENO \u003d 1"},{"line_number":42,"context_line":"STDERR_FILENO \u003d 2"}],"source_content_type":"text/x-python","patch_set":4,"id":"3afb71cf_bf2495c4","line":39,"in_reply_to":"3afb71cf_bf125555","updated":"2015-06-10 05:44:13.000000000","message":"Do you mean you\u0027re not sure what the below code will do, or you\u0027re not sure what the behaviour _should_ be when sys.std* is mocked out?\n\nIf you can explain what you think the behaviour should be during a test, then I\u0027m happy to show you how the below code will do exactly that and the current code will throw an exception ;)\n\nMore generally, I really don\u0027t know how to make this clearer - so I need more information from the -1\u0027ers to understand where their objections are coming from.","commit_id":"ca3e79e683efe1e7fc7d2a3be14e055ec8450a11"},{"author":{"_account_id":6854,"name":"YAMAMOTO Takashi","email":"yamamoto@midokura.com","username":"yamamoto"},"change_message_id":"e4a01fb97eb222aef42437f9ee479bb74c37606c","unresolved":false,"context_lines":[{"line_number":36,"context_line":"# - and indeed may not even have a file descriptor at all (eg: test"},{"line_number":37,"context_line":"# fixtures that monkey patch fixtures.StringStream onto sys.stdout)."},{"line_number":38,"context_line":"# Below we always want the _real_ well-known 0,1,2 Unix fds during"},{"line_number":39,"context_line":"# os.dup2 manipulation."},{"line_number":40,"context_line":"STDIN_FILENO \u003d 0"},{"line_number":41,"context_line":"STDOUT_FILENO \u003d 1"},{"line_number":42,"context_line":"STDERR_FILENO \u003d 2"}],"source_content_type":"text/x-python","patch_set":4,"id":"3afb71cf_a5a7dcbb","line":39,"in_reply_to":"3afb71cf_bf2495c4","updated":"2015-06-10 10:40:57.000000000","message":"dup2(.., 1) doesn\u0027t seems to make sense\nwhen sys.stdout are something which doesn\u0027t have fileno.\n\nIMO daemonizing in such a special environment should be avoided.","commit_id":"ca3e79e683efe1e7fc7d2a3be14e055ec8450a11"},{"author":{"_account_id":6854,"name":"YAMAMOTO Takashi","email":"yamamoto@midokura.com","username":"yamamoto"},"change_message_id":"0b5fbafdb421d23379b4a3226d73ca4bf1313b16","unresolved":false,"context_lines":[{"line_number":36,"context_line":"# - and indeed may not even have a file descriptor at all (eg: test"},{"line_number":37,"context_line":"# fixtures that monkey patch fixtures.StringStream onto sys.stdout)."},{"line_number":38,"context_line":"# Below we always want the _real_ well-known 0,1,2 Unix fds during"},{"line_number":39,"context_line":"# os.dup2 manipulation."},{"line_number":40,"context_line":"STDIN_FILENO \u003d 0"},{"line_number":41,"context_line":"STDOUT_FILENO \u003d 1"},{"line_number":42,"context_line":"STDERR_FILENO \u003d 2"}],"source_content_type":"text/x-python","patch_set":4,"id":"fa32b979_f7884624","line":39,"in_reply_to":"3afb71cf_bf2495c4","updated":"2015-06-24 03:25:04.000000000","message":"my opinion is, if tests needs to run this code in a special environment, it\u0027s their responsibility to apply necessary mocks.","commit_id":"ca3e79e683efe1e7fc7d2a3be14e055ec8450a11"},{"author":{"_account_id":10980,"name":"Doug Wiegley","email":"dougwig@parkside.io","username":"dougw"},"change_message_id":"40580ce0886e971db612a7a1da6b9fed563139b9","unresolved":false,"context_lines":[{"line_number":40,"context_line":"STDIN_FILENO \u003d 0"},{"line_number":41,"context_line":"STDOUT_FILENO \u003d 1"},{"line_number":42,"context_line":"STDERR_FILENO \u003d 2"},{"line_number":43,"context_line":""},{"line_number":44,"context_line":""},{"line_number":45,"context_line":"def setuid(user_id_or_name):"},{"line_number":46,"context_line":"    try:"}],"source_content_type":"text/x-python","patch_set":4,"id":"3afb71cf_6d28bf86","line":43,"updated":"2015-06-10 00:55:33.000000000","message":"Won\u0027t this break if I\u0027ve purposely reset stdin/out/err in whatever launches the program using this module (say, exec\u003e in bash?)\n\nI\u0027d feel more comfortable with something like:\n\ntry:\n  STDIN_FILENO \u003d sys.stdin.fileno()\nexcept:\n  STDIN_FILENO \u003d 0\n\n...","commit_id":"ca3e79e683efe1e7fc7d2a3be14e055ec8450a11"},{"author":{"_account_id":11279,"name":"Angus Lees","email":"gus@inodes.org","username":"gus"},"change_message_id":"5d59936f043062c54b1e56636d307d81aa7b11a6","unresolved":false,"context_lines":[{"line_number":40,"context_line":"STDIN_FILENO \u003d 0"},{"line_number":41,"context_line":"STDOUT_FILENO \u003d 1"},{"line_number":42,"context_line":"STDERR_FILENO \u003d 2"},{"line_number":43,"context_line":""},{"line_number":44,"context_line":""},{"line_number":45,"context_line":"def setuid(user_id_or_name):"},{"line_number":46,"context_line":"    try:"}],"source_content_type":"text/x-python","patch_set":4,"id":"3afb71cf_04e000f9","line":43,"in_reply_to":"3afb71cf_6d28bf86","updated":"2015-06-10 04:28:23.000000000","message":"No, this is exactly the bug I\u0027m fixing with this change.\n\nYou\u0027ll see that the use case below is we\u0027ve just forked, and I need to set up the provided file objects (or a freshly-opened /dev/null) as stdin/out/err for the new child process.\n\nPreviously the code just used sys.stdin.fileno(), but this fails if sys.stdin is a mocked stringIO thing without a fileno at all.\n\nWith your suggestion (sys.stdin.fileno() with fallback) then if sys.stdin is a monkey-patched file-backed thing, then I\u0027d be duping onto some random file descriptor (and closing the fd behind the sys.stdin thing).\n\nI need to use the real value \"0\" here to refer to the real stdin file descriptor, and no other value is correct.\n\nI feel the python comment above already says this, but I\u0027m already too familiar with this code and finding it hard to see why there are any questions here ;)\nIf there\u0027s something in an alternate explanation that helps make this clearer for you, please point it out and I\u0027ll include it for the next confused reader.\n\n\nTo your specific example of exec\u003e in a bash wrapper, this works by manipulating stdout before exec()ing the (python) command - coincidentally using code very much like what we\u0027re discussing here.  As far as the invoked executable is concerned, the redirected stdout is still the \"real\" stdout and uses the well-known fd \"1\".  I encourage you to print sys.stdout.fileno() in various scenarios and see, perhaps along with \"strace -etrace\u003dprocess,file,dup2 sh -c \u0027/bin/echo foo \u003e/dev/null\u0027\" and similar.","commit_id":"ca3e79e683efe1e7fc7d2a3be14e055ec8450a11"},{"author":{"_account_id":2592,"name":"Mark McClain","email":"mark@mcclain.xyz","username":"markmcclain"},"change_message_id":"6188778eb233289ef7a65704726a532e1dbaa50b","unresolved":false,"context_lines":[{"line_number":204,"context_line":"        self._fork()"},{"line_number":205,"context_line":""},{"line_number":206,"context_line":"        # redirect standard file descriptors"},{"line_number":207,"context_line":"        sys.stdout.flush()"},{"line_number":208,"context_line":"        sys.stderr.flush()"},{"line_number":209,"context_line":"        devnull \u003d open(os.devnull, \u0027w+\u0027)"},{"line_number":210,"context_line":"        stdin \u003d devnull if self.stdin is DEVNULL else self.stdin"}],"source_content_type":"text/x-python","patch_set":6,"id":"1af86dd1_dbe5b7a8","line":207,"updated":"2015-06-12 17:06:54.000000000","message":"Uhm... so we\u0027re just blindly flushing these descriptors.  Shouldn\u0027t we be flushing the static ones below?","commit_id":"6eff549f3765ade34a92be631743f5206086fba5"},{"author":{"_account_id":10980,"name":"Doug Wiegley","email":"dougwig@parkside.io","username":"dougw"},"change_message_id":"96779775a4878ef5e91271786352702f19203cd0","unresolved":false,"context_lines":[{"line_number":204,"context_line":"        self._fork()"},{"line_number":205,"context_line":""},{"line_number":206,"context_line":"        # redirect standard file descriptors"},{"line_number":207,"context_line":"        sys.stdout.flush()"},{"line_number":208,"context_line":"        sys.stderr.flush()"},{"line_number":209,"context_line":"        devnull \u003d open(os.devnull, \u0027w+\u0027)"},{"line_number":210,"context_line":"        stdin \u003d devnull if self.stdin is DEVNULL else self.stdin"}],"source_content_type":"text/x-python","patch_set":6,"id":"fa32b979_71976690","line":207,"in_reply_to":"1af86dd1_dbe5b7a8","updated":"2015-06-24 01:42:43.000000000","message":"No, this is correct. Since we forked, we\u0027re an exact copy, but since the fd\u0027s haven\u0027t dup\u0027ed yet, if another thread was filling the stream buffer at the time of the fork but before we get here, it\u0027s possible that the child has some of the parents output.  Flushing it gets things correct, and then we reset the streams to be standard.","commit_id":"6eff549f3765ade34a92be631743f5206086fba5"},{"author":{"_account_id":11279,"name":"Angus Lees","email":"gus@inodes.org","username":"gus"},"change_message_id":"1eac40f8616c41392f6f8dcda7a204150fa688b8","unresolved":false,"context_lines":[{"line_number":204,"context_line":"        self._fork()"},{"line_number":205,"context_line":""},{"line_number":206,"context_line":"        # redirect standard file descriptors"},{"line_number":207,"context_line":"        sys.stdout.flush()"},{"line_number":208,"context_line":"        sys.stderr.flush()"},{"line_number":209,"context_line":"        devnull \u003d open(os.devnull, \u0027w+\u0027)"},{"line_number":210,"context_line":"        stdin \u003d devnull if self.stdin is DEVNULL else self.stdin"}],"source_content_type":"text/x-python","patch_set":6,"id":"fa32b979_f1ba96e0","line":207,"in_reply_to":"1af86dd1_dbe5b7a8","updated":"2015-06-25 15:13:22.000000000","message":"hrm. I think Mark is right and I should be flushing the {stdin,stdout,stderr} file objects here, not the sys.std* objects.\n\nThe intention here is to flush any data buffered at the python level into the kernel before messing the the kernel objects underneath.  The dup2 implicitly closes the original destination fd, which could mean buffered data doesn\u0027t have a chance to be written.  It\u0027s more obscure, but I can also conceive a situation where the file position ends up at an unexpected place in one of the dup\u0027ed fds because the buffer on the original source file object was flushed _after_ the dup2 occurred.  Way more important is flushing before fork(), since that will result in duplicate data being written to the fd - I note the original code didn\u0027t do this.\n\nI\u0027ll fix this to flush all the relevant objects before fork()+dup2().","commit_id":"6eff549f3765ade34a92be631743f5206086fba5"},{"author":{"_account_id":8124,"name":"cbrandily","email":"zzelle@gmail.com","username":"cbrandily"},"change_message_id":"df3468b4e0911d19777b5bef35bc94706f422cb9","unresolved":false,"context_lines":[{"line_number":37,"context_line":"# fixtures that monkey patch fixtures.StringStream onto sys.stdout)."},{"line_number":38,"context_line":"# Below we always want the _real_ well-known 0,1,2 Unix fds during"},{"line_number":39,"context_line":"# os.dup2 manipulation."},{"line_number":40,"context_line":"STDIN_FILENO \u003d 0"},{"line_number":41,"context_line":"STDOUT_FILENO \u003d 1"},{"line_number":42,"context_line":"STDERR_FILENO \u003d 2"},{"line_number":43,"context_line":""}],"source_content_type":"text/x-python","patch_set":8,"id":"9a41bdd9_1cd5a9e6","line":40,"updated":"2015-07-15 15:33:38.000000000","message":"Could we do the following (done at module load time)?\n\nSTD*_FILENO \u003d sys.std*.fileno()","commit_id":"9b56ef34f76eb1aaf129c1e34df1a6ccfa172c2c"},{"author":{"_account_id":11279,"name":"Angus Lees","email":"gus@inodes.org","username":"gus"},"change_message_id":"5f6fc70a60940f1c4a4dc5e67125d02cf3157f29","unresolved":false,"context_lines":[{"line_number":37,"context_line":"# fixtures that monkey patch fixtures.StringStream onto sys.stdout)."},{"line_number":38,"context_line":"# Below we always want the _real_ well-known 0,1,2 Unix fds during"},{"line_number":39,"context_line":"# os.dup2 manipulation."},{"line_number":40,"context_line":"STDIN_FILENO \u003d 0"},{"line_number":41,"context_line":"STDOUT_FILENO \u003d 1"},{"line_number":42,"context_line":"STDERR_FILENO \u003d 2"},{"line_number":43,"context_line":""}],"source_content_type":"text/x-python","patch_set":8,"id":"9a41bdd9_a74813cd","line":40,"in_reply_to":"9a41bdd9_1cd5a9e6","updated":"2015-07-16 00:53:52.000000000","message":"Provided the sys.std* objects hadn\u0027t already been mocked out at that point, yes.  If I have to add \"assert sys.stdin.fileno() \u003d\u003d 0\" then we haven\u0027t really gained anything ;)","commit_id":"9b56ef34f76eb1aaf129c1e34df1a6ccfa172c2c"}]}
