Deleted Added
full compact
eval.c (222907) eval.c (223024)
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>
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 $");
39__FBSDID("$FreeBSD: head/bin/sh/eval.c 223024 2011-06-12 23:06:04Z 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{
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
574
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;
575 return (n->type == NCMD);
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;
576}
577
578/*
579 * Execute a command inside back quotes. If it's a builtin command, we
580 * want to save its output in a block obtained from malloc. Otherwise
581 * we fork off a subprocess and get the output of the command via a pipe.
582 * Should be called with interrupts off.
583 */
584
585void
586evalbackcmd(union node *n, struct backcmd *result)
587{
588 int pip[2];
589 struct job *jp;
590 struct stackmark smark; /* unnecessary */
591 struct jmploc jmploc;
592 struct jmploc *savehandler;
593 struct localvar *savelocalvars;
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;
594
595 setstackmark(&smark);
596 result->fd = -1;
597 result->buf = NULL;
598 result->nleft = 0;
599 result->jp = NULL;
600 if (n == NULL) {
601 exitstatus = 0;
602 goto out;
603 }
604 if (is_valid_fast_cmdsubst(n)) {
605 exitstatus = oexitstatus;
606 savelocalvars = localvars;
607 localvars = NULL;
608 forcelocal++;
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;
609 savehandler = handler;
610 if (setjmp(jmploc.loc)) {
611 if (exception == EXERROR || exception == EXEXEC)
612 exitstatus = 2;
613 else if (exception != 0) {
614 handler = savehandler;
615 forcelocal--;
616 poplocalvars();
617 localvars = savelocalvars;
617 longjmp(handler->loc, 1);
618 }
619 } else {
620 handler = &jmploc;
621 evalcommand(n, EV_BACKCMD, result);
622 }
623 handler = savehandler;
618 longjmp(handler->loc, 1);
619 }
620 } else {
621 handler = &jmploc;
622 evalcommand(n, EV_BACKCMD, result);
623 }
624 handler = savehandler;
625 forcelocal--;
626 poplocalvars();
627 localvars = savelocalvars;
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 ---
628 } else {
629 exitstatus = 0;
630 if (pipe(pip) < 0)
631 error("Pipe call failed: %s", strerror(errno));
632 jp = makejob(n, 1);
633 if (forkshell(jp, n, FORK_NOJOB) == 0) {
634 FORCEINTON;
635 close(pip[0]);

--- 640 unchanged lines hidden ---