1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1982-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* David Korn <dgk@research.att.com> * 1N/A***********************************************************************/ 1N/A * Create and manage subshells avoiding forks when possible 1N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. 1N/A * Note that the following structure must be the same 1N/A * size as the Dtlink_t structure 1N/A * The following structure is used for command substitution and (...) 1N/A Dt_t *
var;
/* variable table at time of subshell */ 1N/A char *
pwd;
/* present working directory */ 1N/A const char *
shpwd;
/* saved pointer to sh.pwd */ 1N/A short tmpfd;
/* saved tmp file descriptor */ 1N/A short pipefd;
/* read fd if pipe is created */ 1N/A#
endif /* SHOPT_COSHELL */ 1N/A * This routine will turn the sftmp() file into a real /tmp file or pipe 1N/A * if the /tmp file create fails 1N/A /* save file descriptor 1 if open */ 1N/A /* popping a discipline forces a /tmp file create */ 1N/A /* unable to create the /tmp file so use a pipe */ 1N/A /* write the data to the pipe */ 1N/A * This routine creates a temp file if necessary and creates a subshell. 1N/A * The parent routine longjmps back to sh_subshell() 1N/A * The child continues possibly with its standard output replaced by temp file 1N/A /* see whether inside $(...) */ 1N/A /* this is the parent part of the fork */ 1N/A /* this is the child part of the fork */ 1N/A /* setting subpid to 1 causes subshell to exit when reached */ 1N/A * This routine will make a copy of the given node in the 1N/A * layer created by the most recent subshell_fork if the 1N/A * node hasn't already been copied 1N/A /* don't bother with this */ 1N/A /* first two pointers use linkage from np */ 1N/A * restore the variables 1N/A sp->
shpwd = 0;
/* make sure sh_assignok doesn't save with nv_unset() */ 1N/A * return pointer to alias tree 1N/A * create new one if in a subshell and one doesn't exist and create is non-zero 1N/A * return pointer to function tree 1N/A * create new one if in a subshell and one doesn't exist and create is non-zero 1N/A * Run command tree <t> in a virtual sub-shell 1N/A * If comsub is not null, then output will be placed in temp file (or buffer) 1N/A * If comsub is not null, the return value will be a stream consisting of 1N/A * output of command <t>. Otherwise, NULL will be returned. 1N/A#
endif /* SHOPT_COSHELL */ 1N/A /* make sure initialization has occurred */ 1N/A /* save trap table */ 1N/A /* this nonsense needed for $(trap) */ 1N/A /* disable job control */ 1N/A /* save sfstdout and status */ 1N/A /* use sftmp() file for standard output */ 1N/A /* trap on EXIT not handled by child */ 1N/A /* re-enable job control */ 1N/A /* sftmp() file has been returned into pipe */ 1N/A /* move tmp file to iop and restore sfstdout */ 1N/A /* maybe locked try again */ 1N/A /* check if standard output was preserved */ 1N/A /* restore PWDNOD */ 1N/A#
endif /* SHOPT_COSHELL */