2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: ex_shell.c,v 8.16 1993/12/19 12:59:05 bostic Exp $ (Berkeley) $Date: 1993/12/19 12:59:05 $";
12 #include <sys/param.h>
22 #include "../svi/svi_screen.h"
25 * ex_shell -- :sh[ell]
26 * Invoke the program named in the SHELL environment variable
27 * with the argument -i.
30 ex_shell(sp
, ep
, cmdp
)
37 (void)snprintf(buf
, sizeof(buf
), "%s -i", O_STR(sp
, O_SHELL
));
38 return (ex_exec_proc(sp
, buf
, "\n", NULL
));
43 * Run a separate process.
46 ex_exec_proc(sp
, cmd
, p1
, p2
)
50 struct sigaction act
, oact
;
57 /* Clear the rest of the screen. */
61 /* Save ex/vi terminal settings, and restore the original ones. */
62 EX_LEAVE(sp
, isig
, act
, oact
, sb
, osb
, term
);
64 /* Put out various messages. */
66 (void)write(STDOUT_FILENO
, p1
, strlen(p1
));
68 (void)write(STDOUT_FILENO
, p2
, strlen(p2
));
71 switch (pid
= vfork()) {
73 msgq(sp
, M_SYSERR
, "vfork");
76 case 0: /* Utility. */
78 * The utility has default signal behavior. Don't bother
79 * using sigaction(2) 'cause we want the default behavior.
81 (void)signal(SIGINT
, SIG_DFL
);
82 (void)signal(SIGQUIT
, SIG_DFL
);
84 if ((name
= strrchr(O_STR(sp
, O_SHELL
), '/')) == NULL
)
85 name
= O_STR(sp
, O_SHELL
);
88 execl(O_STR(sp
, O_SHELL
), name
, "-c", cmd
, NULL
);
89 msgq(sp
, M_ERR
, "Error: execl: %s: %s",
90 O_STR(sp
, O_SHELL
), strerror(errno
));
95 rval
= proc_wait(sp
, (long)pid
, cmd
, 0);
97 /* Restore ex/vi terminal settings. */
98 err
: EX_RETURN(sp
, isig
, act
, oact
, sb
, osb
, term
);