Deleted Added
sdiff udiff text old ( 222907 ) new ( 223024 )
full compact
1/*-
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 */
32
33#ifndef lint
34#if 0
35static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
36#endif
37#endif /* not lint */
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/bin/sh/eval.c 222907 2011-06-09 23:12:23Z jilles $");
40
41#include <paths.h>
42#include <signal.h>
43#include <stdlib.h>
44#include <unistd.h>
45#include <sys/resource.h>
46#include <sys/wait.h> /* For WIFSIGNALED(status) */
47#include <errno.h>

--- 518 unchanged lines hidden (view full) ---

566 exitstatus = 0;
567}
568
569
570
571static int
572is_valid_fast_cmdsubst(union node *n)
573{
574 union node *argp;
575
576 if (n->type != NCMD)
577 return 0;
578 for (argp = n->ncmd.args ; argp ; argp = argp->narg.next)
579 if (expandhassideeffects(argp->narg.text))
580 return 0;
581 return 1;
582}
583
584/*
585 * Execute a command inside back quotes. If it's a builtin command, we
586 * want to save its output in a block obtained from malloc. Otherwise
587 * we fork off a subprocess and get the output of the command via a pipe.
588 * Should be called with interrupts off.
589 */
590
591void
592evalbackcmd(union node *n, struct backcmd *result)
593{
594 int pip[2];
595 struct job *jp;
596 struct stackmark smark; /* unnecessary */
597 struct jmploc jmploc;
598 struct jmploc *savehandler;
599
600 setstackmark(&smark);
601 result->fd = -1;
602 result->buf = NULL;
603 result->nleft = 0;
604 result->jp = NULL;
605 if (n == NULL) {
606 exitstatus = 0;
607 goto out;
608 }
609 if (is_valid_fast_cmdsubst(n)) {
610 exitstatus = oexitstatus;
611 savehandler = handler;
612 if (setjmp(jmploc.loc)) {
613 if (exception == EXERROR || exception == EXEXEC)
614 exitstatus = 2;
615 else if (exception != 0) {
616 handler = savehandler;
617 longjmp(handler->loc, 1);
618 }
619 } else {
620 handler = &jmploc;
621 evalcommand(n, EV_BACKCMD, result);
622 }
623 handler = savehandler;
624 } else {
625 exitstatus = 0;
626 if (pipe(pip) < 0)
627 error("Pipe call failed: %s", strerror(errno));
628 jp = makejob(n, 1);
629 if (forkshell(jp, n, FORK_NOJOB) == 0) {
630 FORCEINTON;
631 close(pip[0]);

--- 640 unchanged lines hidden ---