summaryrefslogtreecommitdiff
path: root/sys/kern/exec_script.c
diff options
context:
space:
mode:
authorcgd <cgd@NetBSD.org>1994-02-16 01:21:00 +0000
committercgd <cgd@NetBSD.org>1994-02-16 01:21:00 +0000
commita790e23e879f5fe80fc5ef8288a36b1d74584fd6 (patch)
tree588321641acf3dd772a26996cbfcb5007cdb1338 /sys/kern/exec_script.c
parentfe0c74f41f0adbaafbf46327547e0144a3098de0 (diff)
simplify error returns, and fix bugs
Diffstat (limited to 'sys/kern/exec_script.c')
-rw-r--r--sys/kern/exec_script.c55
1 files changed, 36 insertions, 19 deletions
diff --git a/sys/kern/exec_script.c b/sys/kern/exec_script.c
index c53912f40dc..2ebfccc08b9 100644
--- a/sys/kern/exec_script.c
+++ b/sys/kern/exec_script.c
@@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: exec_script.c,v 1.3 1994/01/28 23:47:07 jtc Exp $
+ * $Id: exec_script.c,v 1.4 1994/02/16 01:21:00 cgd Exp $
*/
#if defined(SETUIDSCRIPTS) && !defined(FDSCRIPTS)
@@ -170,7 +170,7 @@ check_shell:
#endif
if (error = falloc(p, &fp, &epp->ep_fd))
- return error;
+ goto fail;
epp->ep_flags |= EXEC_HASFD;
fp->f_type = DTYPE_VNODE;
@@ -223,14 +223,18 @@ check_shell:
scriptvp = epp->ep_vp;
oldpnbuf = epp->ep_ndp->ni_pnbuf;
+ VOP_UNLOCK(scriptvp);
+
if ((error = check_exec(p, epp)) == 0) {
+ /* note that we've clobbered the header */
+ epp->ep_flags |= EXEC_DESTR;
+
/*
* It succeeded. Unlock the script and
* close it if we aren't using it any more.
- * Also, et things up so that the fake args
+ * Also, set things up so that the fake args
* list will be used.
*/
- VOP_UNLOCK(scriptvp);
if ((epp->ep_flags & EXEC_HASFD) == 0)
vn_close(scriptvp, FREAD, p->p_ucred, p);
@@ -250,22 +254,35 @@ check_shell:
if (script_sbits & VSGID)
epp->ep_vap->va_gid = script_gid;
#endif
- } else {
- /*
- * Failed. restore the vnode ptr and pnbuf so that
- * check_exec() will be able to kill them when it punts.
- */
- epp->ep_vp = scriptvp;
- epp->ep_ndp->ni_pnbuf = oldpnbuf;
+ return (0);
+ }
- /* free the fake arg list, because we're not returning it */
- tmpsap = shellargp;
- while (*tmpsap != NULL) {
- FREE(*tmpsap, M_EXEC);
- tmpsap++;
- }
- FREE(shellargp, M_EXEC);
+fail:
+ /* note that we've clobbered the header */
+ epp->ep_flags |= EXEC_DESTR;
+
+ /* kill the opened file descriptor, else close the file */
+ if (epp->ep_flags & EXEC_HASFD) {
+ epp->ep_flags &= ~EXEC_HASFD;
+ exec_closefd(p, epp->ep_fd);
+ } else
+ vn_close(scriptvp, FREAD, p->p_ucred, p);
+
+ FREE(oldpnbuf, M_NAMEI);
+
+ /* free the fake arg list, because we're not returning it */
+ tmpsap = shellargp;
+ while (*tmpsap != NULL) {
+ FREE(*tmpsap, M_EXEC);
+ tmpsap++;
}
+ FREE(shellargp, M_EXEC);
+
+ /*
+ * free any vmspace-creation commands,
+ * and release their references
+ */
+ kill_vmcmds(&epp->ep_vmcmds);
- return error;
+ return error;
}