--- - branch: MAIN date: Sun Aug 19 23:50:27 UTC 2018 files: - new: '1.21' old: '1.20' path: src/bin/sh/error.h pathrev: src/bin/sh/error.h@1.21 type: modified - new: '1.21' old: '1.20' path: src/bin/sh/input.h pathrev: src/bin/sh/input.h@1.21 type: modified - new: '1.159' old: '1.158' path: src/bin/sh/eval.c pathrev: src/bin/sh/eval.c@1.159 type: modified - new: '1.63' old: '1.62' path: src/bin/sh/input.c pathrev: src/bin/sh/input.c@1.63 type: modified - new: '1.75' old: '1.74' path: src/bin/sh/main.c pathrev: src/bin/sh/main.c@1.75 type: modified - new: '1.150' old: '1.149' path: src/bin/sh/parser.c pathrev: src/bin/sh/parser.c@1.150 type: modified - new: '1.45' old: '1.44' path: src/bin/sh/trap.c pathrev: src/bin/sh/trap.c@1.45 type: modified - new: '1.23' old: '1.22' path: src/bin/sh/trap.h pathrev: src/bin/sh/trap.h@1.23 type: modified id: 20180819T235027Z.52abba14560b85336a571b2be65534d49e25530b log: "PR bin/48875 (is related, and ameliorated, but not exactly \"fixed\")\n\nImport a whole set of tree evaluation enhancements from FreeBSD.\n\nWith these, before forking, the shell predicts (often) when all it will\nhave to do after forking (in the parent) is wait for the child and then\nexit with the status from the child, and in such a case simply does not\nfork, but rather allows the child to take over the parent's role.\n\nThis turns out to handle the particular test case from PR bin/48875 in\nsuch a way that it works as hoped, rather than as it did (the delay there\nwas caused by an extra copy of the shell hanging around waiting for the\nbackground child to complete ... and keeping the command substitution\nstdout open, so the \"real\" parent had to wait in case more output appeared).\n\nAs part of doing this, redirection processing for compound commands gets\nmoved out of evalsubshell() and into a new evalredir(), which allows us\nto properly handle errors occurring while performing those redirects,\nand not mishandle (as in simply forget) fd's which had been moved out\nof the way temporarily.\n\nevaltree() has its degree of recursion reduced by making it loop to\nhandle the subsequent operation: that is instead of (for any binop\nlike ';' '&&' (etc)) where it used to\n\tevaltree(node->left);\n\tevaltree(node->right);\n\treturn;\nit now does (kind of)\n\tnext = node;\n\twhile ((node = next) != NULL) {\n\t\tnext = NULL;\n\n\t\tif (node is a binary op) {\n\t\t\tevaltree(node->left);\n\t\t\tif appropriate /* if && test for success, etc */\n\t\t\t\tnext = node->right;\n\t\t\tcontinue;\n\t\t}\n\t\t/* similar for loops, etc */\n\t}\nwhich can be a good saving, as while the left side (now) tends to be\n(usually) a simple (or simpleish) command, the right side can be many\ncommands (in a command sequence like a; b; c; d; ... the node at the\ntop of the tree will now have \"a\" as its left node, and the tree for\nb; c; d; ... as its right node - until now everything was evaluated\nrecursively so it made no difference, and the tree was constructed\nthe other way).\n\nif/while/... statements are done similarly, recurse to evaluate the\ncondition, then if the (or one of the) body parts is to be evaluated,\nset next to that, and loop (previously it recursed).\n\nThere is more to do in this area (particularly in the way that case\nstatements are processed - we can avoid recursion there as well) but\nthat can wait for another day.\n\nWhile doing all of this we keep much better track of when the shell is\njust going to exit once the current tree is evaluated (with a new\npredicate at_eof() to tell us that we have, for sure, reached the end\nof the input stream, that is, this shell will, for certain, not be reading\nmore command input) and use that info to avoid unneeded forks. For that\nwe also need another new predicate (have_traps()) to determine of there\nare any caught traps which might occur - if there are, we need to remain\nto (potentially) handle them, so these optimisations will not occur (to\nmake the issue in PR 48875 appear again, run the same code, but with a\ntrap set to execute some code when a signal (or EXIT) occurs - note that\nthe trap must be set in the appropriate level of sub-shell to have this\neffect, any caught traps are cleared in a subshell whenever one is created).\n\nThere is still work to be done to handle traps properly, whatever\nweirdness they do (some of which is related to some of this.)\n\nThese changes do not need man page updates, but 48875 does - an update\nto sh.1 will be forthcoming once it is decided what it should say...\n\nOnce again, all the heavy lifting for this set of changes comes directly\n(with thanks) from the FreeBSD shell.\n\nXXX pullup-8 (but not very soon)\n" module: src subject: 'CVS commit: src/bin/sh' unixtime: '1534722627' user: kre