modifier const, error message if 'system' fails

This commit is contained in:
Jim Monte 2020-04-25 19:09:30 +02:00 committed by Holger Vogt
parent e9b995bd34
commit d8d9dddece
1 changed files with 18 additions and 8 deletions

View File

@ -1,6 +1,7 @@
/************* /*************
* com_shell.c * com_shell.c
************/ ************/
#include <stdio.h>
#include "ngspice/ngspice.h" #include "ngspice/ngspice.h"
#include "ngspice/wordlist.h" #include "ngspice/wordlist.h"
@ -20,7 +21,7 @@
void void
com_shell(wordlist *wl) com_shell(wordlist *wl)
{ {
char *com, *shell = NULL; char *shell = NULL;
shell = getenv("SHELL"); shell = getenv("SHELL");
if (shell == NULL) { if (shell == NULL) {
@ -39,8 +40,9 @@ com_shell(wordlist *wl)
execl(shell, shell, 0); execl(shell, shell, 0);
_exit(99); _exit(99);
} else { } else {
com = wl_flatten(wl); char * const com = wl_flatten(wl);
execl("/bin/sh", "sh", "-c", com, 0); execl("/bin/sh", "sh", "-c", com, 0);
txfree(com);
} }
} else { } else {
/* XXX Better have all these signals */ /* XXX Better have all these signals */
@ -58,12 +60,20 @@ com_shell(wordlist *wl)
#else #else
/* Easier to forget about changing the io descriptors. */ /* Easier to forget about changing the io descriptors. */
if (wl) { if (wl) {
com = wl_flatten(wl); char * const com = wl_flatten(wl);
system(com); if (system(com) == -1) {
tfree(com); (void) fprintf(cp_err, "Unable to execute \"%s\".\n", com);
} else { }
system(shell); txfree(com);
}
else {
if (system(shell) == -1) {
(void) fprintf(cp_err, "Unable to execute \"%s\".\n", shell);
}
} }
#endif #endif
} } /* end of function com_shell */