Mercurial > hg > octave-avbm
changeset 3153:94fc53d82561
[project @ 1998-02-13 04:08:17 by jwe]
author | jwe |
---|---|
date | Fri, 13 Feb 1998 04:08:17 +0000 |
parents | a34a56e2e567 |
children | 352a80c32765 |
files | src/ChangeLog src/Makefile.in src/system.c |
diffstat | 3 files changed, 100 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +Thu Feb 12 22:07:00 1998 John W. Eaton <jwe@bevo.che.wisc.edu> + + * system.c: New file. + * Makefile.in (SOURCES): Add it to the list. + Fri Feb 6 01:23:18 1998 John W. Eaton <jwe@bevo.che.wisc.edu> * oct-stream.cc (octave_base_stream::file_number): Rename from fileno.
--- a/src/Makefile.in +++ b/src/Makefile.in @@ -124,7 +124,7 @@ oct-procbuf.cc oct-stdstrm.cc oct-stream.cc oct-strstrm.cc \ oct-lvalue.cc pager.cc parse.y pr-output.cc procstream.cc \ sighandlers.cc strcasecmp.c strncase.c strfns.cc \ - strftime.c symtab.cc syscalls.cc sysdep.cc token.cc \ + strftime.c symtab.cc syscalls.cc sysdep.cc system.c token.cc \ toplev.cc unwind-prot.cc utils.cc variables.cc xdiv.cc \ xpow.cc $(OV_SRC) $(PT_SRC)
new file mode 100644 --- /dev/null +++ b/src/system.c @@ -0,0 +1,94 @@ +#if defined (__CYGWIN32__) + +#include <sys/types.h> +#include <sys/wait.h> +#include <errno.h> +#include <signal.h> +#include <unistd.h> +#include <stdio.h> + +int +system (const char *cmd) +{ + pid_t pid; + + int status = 1; + + struct sigaction ignore, saved_sigint, saved_sigquit; + + sigset_t child_mask, saved_mask; + + if (cmd) + { + ignore.sa_handler = SIG_IGN; + + sigemptyset (&ignore.sa_mask); + + ignore.sa_flags = 0; + + if (sigaction (SIGINT, &ignore, &saved_sigint) < 0) + return -1; + + if (sigaction (SIGQUIT, &ignore, &saved_sigquit) < 0) + return -1; + + sigemptyset (&child_mask); + + sigaddset (&child_mask, SIGCHLD); + + if (sigprocmask (SIG_BLOCK, &child_mask, &saved_mask) < 0) + return -1; + + if ((pid = fork ()) < 0) + status = -1; + else if (pid == 0) + { + sigaction (SIGINT, &saved_sigint, 0); + sigaction (SIGQUIT, &saved_sigquit, 0); + + sigprocmask (SIG_SETMASK, &saved_mask, 0); + + execl ("/bin/sh", "sh", "-c", cmd, 0); + + exit (127); + } + else + { + while (waitpid (pid, &status, 0) < 0) + { + if (errno != EINTR) + { + status = -1; + break; + } + } + } + + if (sigaction (SIGINT, &saved_sigint, 0) < 0) + return -1; + + if (sigaction (SIGQUIT, &saved_sigquit, 0) < 0) + return -1; + + if (sigprocmask (SIG_SETMASK, &saved_mask, 0) < 0) + return -1; + } + + return status; +} + +#if defined (TEST) +int +main (void) +{ + system ("info"); + while (1) + { + printf ("foo-i-hithere\n"); + sleep (1); + } + return 0; +} +#endif + +#endif