From 0b303833828e4fee859ada3fce22d986bc94da55 Mon Sep 17 00:00:00 2001 From: "Jordan K. Hubbard" Date: Thu, 18 May 1995 02:42:33 +0000 Subject: [PATCH] Use my own version of system() everywhere - it knows where to find the shell! --- release/sysinstall/command.c | 4 ++-- release/sysinstall/system.c | 25 +++++++++++++++++++++++-- usr.sbin/sade/command.c | 4 ++-- usr.sbin/sade/system.c | 25 +++++++++++++++++++++++-- usr.sbin/sysinstall/command.c | 4 ++-- usr.sbin/sysinstall/system.c | 25 +++++++++++++++++++++++-- 6 files changed, 75 insertions(+), 12 deletions(-) diff --git a/release/sysinstall/command.c b/release/sysinstall/command.c index 03989cc716fe..ee7ce78d24a7 100644 --- a/release/sysinstall/command.c +++ b/release/sysinstall/command.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: command.c,v 1.3 1995/05/16 02:52:56 jkh Exp $ + * $Id: command.c,v 1.4 1995/05/16 11:37:07 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -166,7 +166,7 @@ command_execute(void) if (commandStack[i]->cmds[j].type == CMD_SHELL) { msgNotify("Executing command: %s", commandStack[i]->cmds[j].ptr); - ret = system((char *)commandStack[i]->cmds[j].ptr); + ret = vsystem((char *)commandStack[i]->cmds[j].ptr); msgDebug("Command `%s' returns status %d\n", commandStack[i]->cmds[j].ptr, ret); } diff --git a/release/sysinstall/system.c b/release/sysinstall/system.c index 90e1ed36e694..cb620feb0186 100644 --- a/release/sysinstall/system.c +++ b/release/sysinstall/system.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: system.c,v 1.11 1995/05/16 11:37:26 jkh Exp $ + * $Id: system.c,v 1.12 1995/05/17 16:16:10 jkh Exp $ * * Jordan Hubbard * @@ -265,6 +265,10 @@ int vsystem(char *fmt, ...) { va_list args; + union wait pstat; + pid_t pid; + int omask; + sig_t intsave, quitsave; char *cmd; int i; @@ -273,8 +277,25 @@ vsystem(char *fmt, ...) va_start(args, fmt); vsnprintf(cmd, FILENAME_MAX, fmt, args); va_end(args); + omask = sigblock(sigmask(SIGCHLD)); msgNotify("Executing command: %s", cmd); - i = system(cmd); + switch(pid = vfork()) { + case -1: /* error */ + (void)sigsetmask(omask); + i = 127; + + case 0: /* child */ + (void)sigsetmask(omask); + execl("/stand/sh", "sh", "-c", cmd, (char *)NULL); + i = 127; + } + intsave = signal(SIGINT, SIG_IGN); + quitsave = signal(SIGQUIT, SIG_IGN); + pid = waitpid(pid, (int *)&pstat, 0); + (void)sigsetmask(omask); + (void)signal(SIGINT, intsave); + (void)signal(SIGQUIT, quitsave); + i = (pid == -1) ? -1 : pstat.w_status; msgDebug("Command `%s' returns status of %d\n", cmd, i); free(cmd); return i; diff --git a/usr.sbin/sade/command.c b/usr.sbin/sade/command.c index 03989cc716fe..ee7ce78d24a7 100644 --- a/usr.sbin/sade/command.c +++ b/usr.sbin/sade/command.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: command.c,v 1.3 1995/05/16 02:52:56 jkh Exp $ + * $Id: command.c,v 1.4 1995/05/16 11:37:07 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -166,7 +166,7 @@ command_execute(void) if (commandStack[i]->cmds[j].type == CMD_SHELL) { msgNotify("Executing command: %s", commandStack[i]->cmds[j].ptr); - ret = system((char *)commandStack[i]->cmds[j].ptr); + ret = vsystem((char *)commandStack[i]->cmds[j].ptr); msgDebug("Command `%s' returns status %d\n", commandStack[i]->cmds[j].ptr, ret); } diff --git a/usr.sbin/sade/system.c b/usr.sbin/sade/system.c index 90e1ed36e694..cb620feb0186 100644 --- a/usr.sbin/sade/system.c +++ b/usr.sbin/sade/system.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: system.c,v 1.11 1995/05/16 11:37:26 jkh Exp $ + * $Id: system.c,v 1.12 1995/05/17 16:16:10 jkh Exp $ * * Jordan Hubbard * @@ -265,6 +265,10 @@ int vsystem(char *fmt, ...) { va_list args; + union wait pstat; + pid_t pid; + int omask; + sig_t intsave, quitsave; char *cmd; int i; @@ -273,8 +277,25 @@ vsystem(char *fmt, ...) va_start(args, fmt); vsnprintf(cmd, FILENAME_MAX, fmt, args); va_end(args); + omask = sigblock(sigmask(SIGCHLD)); msgNotify("Executing command: %s", cmd); - i = system(cmd); + switch(pid = vfork()) { + case -1: /* error */ + (void)sigsetmask(omask); + i = 127; + + case 0: /* child */ + (void)sigsetmask(omask); + execl("/stand/sh", "sh", "-c", cmd, (char *)NULL); + i = 127; + } + intsave = signal(SIGINT, SIG_IGN); + quitsave = signal(SIGQUIT, SIG_IGN); + pid = waitpid(pid, (int *)&pstat, 0); + (void)sigsetmask(omask); + (void)signal(SIGINT, intsave); + (void)signal(SIGQUIT, quitsave); + i = (pid == -1) ? -1 : pstat.w_status; msgDebug("Command `%s' returns status of %d\n", cmd, i); free(cmd); return i; diff --git a/usr.sbin/sysinstall/command.c b/usr.sbin/sysinstall/command.c index 03989cc716fe..ee7ce78d24a7 100644 --- a/usr.sbin/sysinstall/command.c +++ b/usr.sbin/sysinstall/command.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: command.c,v 1.3 1995/05/16 02:52:56 jkh Exp $ + * $Id: command.c,v 1.4 1995/05/16 11:37:07 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -166,7 +166,7 @@ command_execute(void) if (commandStack[i]->cmds[j].type == CMD_SHELL) { msgNotify("Executing command: %s", commandStack[i]->cmds[j].ptr); - ret = system((char *)commandStack[i]->cmds[j].ptr); + ret = vsystem((char *)commandStack[i]->cmds[j].ptr); msgDebug("Command `%s' returns status %d\n", commandStack[i]->cmds[j].ptr, ret); } diff --git a/usr.sbin/sysinstall/system.c b/usr.sbin/sysinstall/system.c index 90e1ed36e694..cb620feb0186 100644 --- a/usr.sbin/sysinstall/system.c +++ b/usr.sbin/sysinstall/system.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: system.c,v 1.11 1995/05/16 11:37:26 jkh Exp $ + * $Id: system.c,v 1.12 1995/05/17 16:16:10 jkh Exp $ * * Jordan Hubbard * @@ -265,6 +265,10 @@ int vsystem(char *fmt, ...) { va_list args; + union wait pstat; + pid_t pid; + int omask; + sig_t intsave, quitsave; char *cmd; int i; @@ -273,8 +277,25 @@ vsystem(char *fmt, ...) va_start(args, fmt); vsnprintf(cmd, FILENAME_MAX, fmt, args); va_end(args); + omask = sigblock(sigmask(SIGCHLD)); msgNotify("Executing command: %s", cmd); - i = system(cmd); + switch(pid = vfork()) { + case -1: /* error */ + (void)sigsetmask(omask); + i = 127; + + case 0: /* child */ + (void)sigsetmask(omask); + execl("/stand/sh", "sh", "-c", cmd, (char *)NULL); + i = 127; + } + intsave = signal(SIGINT, SIG_IGN); + quitsave = signal(SIGQUIT, SIG_IGN); + pid = waitpid(pid, (int *)&pstat, 0); + (void)sigsetmask(omask); + (void)signal(SIGINT, intsave); + (void)signal(SIGQUIT, quitsave); + i = (pid == -1) ? -1 : pstat.w_status; msgDebug("Command `%s' returns status of %d\n", cmd, i); free(cmd); return i;