2005-05-30 22:28:29 +02:00
|
|
|
/*************
|
|
|
|
|
* com_shell.c
|
|
|
|
|
************/
|
|
|
|
|
|
2011-12-11 19:05:00 +01:00
|
|
|
#include "ngspice/ngspice.h"
|
|
|
|
|
#include "ngspice/wordlist.h"
|
2000-07-07 16:06:33 +02:00
|
|
|
|
2005-05-30 22:28:29 +02:00
|
|
|
#include "com_shell.h"
|
2010-10-09 14:49:34 +02:00
|
|
|
#include "streams.h"
|
2011-12-11 19:05:00 +01:00
|
|
|
#include "ngspice/cpextern.h"
|
2000-07-07 16:06:33 +02:00
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2019-06-14 23:01:59 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
#define SHELL "cmd /k"
|
|
|
|
|
#else
|
|
|
|
|
#define SHELL "/bin/csh"
|
|
|
|
|
#endif
|
2000-07-07 16:06:33 +02:00
|
|
|
|
2019-06-14 23:01:59 +02:00
|
|
|
/* Fork a shell. */
|
2000-07-07 16:06:33 +02:00
|
|
|
void
|
|
|
|
|
com_shell(wordlist *wl)
|
|
|
|
|
{
|
|
|
|
|
char *com, *shell = NULL;
|
|
|
|
|
|
|
|
|
|
shell = getenv("SHELL");
|
2019-06-14 23:01:59 +02:00
|
|
|
if (shell == NULL) {
|
|
|
|
|
shell = SHELL;
|
|
|
|
|
}
|
2000-07-07 16:06:33 +02:00
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
cp_ccon(FALSE);
|
2000-07-07 16:06:33 +02:00
|
|
|
|
|
|
|
|
#ifdef HAVE_VFORK_H
|
2012-09-20 20:30:53 +02:00
|
|
|
/* XXX Needs to switch process groups. Also, worry about suspend */
|
|
|
|
|
/* Only bother for efficiency */
|
|
|
|
|
pid = vfork();
|
|
|
|
|
if (pid == 0) {
|
|
|
|
|
fixdescriptors();
|
|
|
|
|
if (wl == NULL) {
|
|
|
|
|
execl(shell, shell, 0);
|
|
|
|
|
_exit(99);
|
2000-07-07 16:06:33 +02:00
|
|
|
} else {
|
2012-09-20 20:30:53 +02:00
|
|
|
com = wl_flatten(wl);
|
|
|
|
|
execl("/bin/sh", "sh", "-c", com, 0);
|
2000-07-07 16:06:33 +02:00
|
|
|
}
|
2012-09-20 20:30:53 +02:00
|
|
|
} else {
|
|
|
|
|
/* XXX Better have all these signals */
|
|
|
|
|
svint = signal(SIGINT, SIG_DFL);
|
|
|
|
|
svquit = signal(SIGQUIT, SIG_DFL);
|
|
|
|
|
svtstp = signal(SIGTSTP, SIG_DFL);
|
|
|
|
|
/* XXX Sig on proc group */
|
|
|
|
|
do
|
|
|
|
|
r = wait(NULL);
|
|
|
|
|
while ((r != pid) && pid != -1);
|
|
|
|
|
signal(SIGINT, (SIGNAL_FUNCTION) svint);
|
|
|
|
|
signal(SIGQUIT, (SIGNAL_FUNCTION) svquit);
|
|
|
|
|
signal(SIGTSTP, (SIGNAL_FUNCTION) svtstp);
|
|
|
|
|
}
|
2000-07-07 16:06:33 +02:00
|
|
|
#else
|
|
|
|
|
/* Easier to forget about changing the io descriptors. */
|
|
|
|
|
if (wl) {
|
|
|
|
|
com = wl_flatten(wl);
|
|
|
|
|
system(com);
|
2012-08-14 21:00:21 +02:00
|
|
|
tfree(com);
|
2012-09-20 20:30:53 +02:00
|
|
|
} else {
|
2000-07-07 16:06:33 +02:00
|
|
|
system(shell);
|
2012-09-20 20:30:53 +02:00
|
|
|
}
|
2000-07-07 16:06:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|