1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  *	@(#)system_.c	5.1	6/7/85
   7:  */
   8: 
   9: /*
  10:  * execute a unix command
  11:  *
  12:  * calling sequence:
  13:  *	iexit = system(command)
  14:  * where:
  15:  *	iexit will return the exit status of the command
  16:  *	command is a character string containing the command to be executed
  17:  */
  18: 
  19: #include    "../libI77/fiodefs.h"
  20: #include    "../libI77/f_errno.h"
  21: #include <sys/param.h>
  22: #ifndef NCARGS
  23: #define NCARGS  256
  24: #endif
  25: 
  26: 
  27: long system_(s, n)
  28: char *s;
  29: long n;
  30: {
  31:     char buf[NCARGS - 50];
  32:     long i;
  33: 
  34:     if (n >= sizeof buf)
  35:         return(-(long)(errno=F_ERARG));
  36:     for (i = 0; i < MXUNIT; i++)
  37:         flush_(&i);
  38:     g_char(s, n, buf);
  39:     return((long)system(buf));
  40: }
  41: 
  42: /*
  43:  * this is a sane version of the libc/stdio routine.
  44:  */
  45: 
  46: #include    <signal.h>
  47: 
  48: char    *getenv();
  49: char    *rindex();
  50: 
  51: system(s)
  52: char *s;
  53: {
  54:     register int (*istat)(), (*qstat)();
  55:     int status, pid, w;
  56:     char    *shname, *shell;
  57: 
  58:     if ((shell = getenv("SHELL")) == NULL)
  59:         shell = "/bin/sh";
  60: 
  61:     if (shname = rindex(shell, '/'))
  62:         shname++;
  63:     else
  64:         shname = shell;
  65: 
  66:     if ((pid = fork()) == 0) {
  67:         execl(shell, shname, "-c", s, 0);
  68:         _exit(127);
  69:     }
  70:     istat = signal(SIGINT, SIG_IGN);
  71:     qstat = signal(SIGQUIT, SIG_IGN);
  72:     while ((w = wait(&status)) != pid && w != -1)
  73:         ;
  74:     if (w == -1)
  75:         status = -1;
  76:     signal(SIGINT, istat);
  77:     signal(SIGQUIT, qstat);
  78:     return(status);
  79: }

Defined functions

system defined in line 51; used 2 times
system_ defined in line 27; never used

Defined macros

NCARGS defined in line 23; used 2 times
Last modified: 1987-02-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2126
Valid CSS Valid XHTML 1.0 Strict