home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume43 / cwish / part05 / system.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-10  |  4.6 KB  |  132 lines

  1. /*---------------------------------------------------------------------------*
  2.  *
  3.  *                  cwish - windowing user friendly shell
  4.  *                  -------------------------------------
  5.  *
  6.  *               Copyright (c) 1988-1994 Hellmuth Michaelis
  7.  *
  8.  *                  Eggerstedtstr. 28
  9.  *                  22765 Hamburg
  10.  *                  Europe
  11.  *
  12.  *                  Tel:    +49 / 40 / 384298    (private)
  13.  *                  Tel:    +49 / 40 / 55903-170 (at work)
  14.  *                  e-mail: hm@hcswork.hcs.de
  15.  *
  16.  *                          --------oOo--------
  17.  *
  18.  *   This program is free software; you can redistribute it and/or modify
  19.  *   it under the terms of the GNU General Public License as published by
  20.  *   the Free Software Foundation; either version 2 of the License, or
  21.  *   (at your option) any later version.
  22.  *
  23.  *   This program is distributed in the hope that it will be useful,
  24.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  25.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26.  *   GNU General Public License for more details.
  27.  *
  28.  *   You should have received a copy of the GNU General Public License
  29.  *   along with this program; if not, write to the Free Software
  30.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  *
  32.  *===========================================================================
  33.  *
  34.  *    The source for the mysystem() routine below is taken from NetBSD
  35.  *    (pre 1.0) current as of February 5, 1994.
  36.  *
  37.  *    It was modified to suit my needs, i.e.: i added the ability to
  38.  *    exec a configurable shell and reformatted it a bit to make it
  39.  *    consitent with the rest of cwish.
  40.  *
  41.  * Copyright (c) 1988 The Regents of the University of California.
  42.  * All rights reserved.
  43.  *
  44.  * Redistribution and use in source and binary forms, with or without
  45.  * modification, are permitted provided that the following conditions
  46.  * are met:
  47.  * 1. Redistributions of source code must retain the above copyright
  48.  *    notice, this list of conditions and the following disclaimer.
  49.  * 2. Redistributions in binary form must reproduce the above copyright
  50.  *    notice, this list of conditions and the following disclaimer in the
  51.  *    documentation and/or other materials provided with the distribution.
  52.  * 3. All advertising materials mentioning features or use of this software
  53.  *    must display the following acknowledgement:
  54.  *    This product includes software developed by the University of
  55.  *    California, Berkeley and its contributors.
  56.  * 4. Neither the name of the University nor the names of its contributors
  57.  *    may be used to endorse or promote products derived from this software
  58.  *    without specific prior written permission.
  59.  *
  60.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  61.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  62.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  64.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  65.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  66.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  67.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  69.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  70.  * SUCH DAMAGE.
  71.  *
  72.  *---------------------------------------------------------------------------*
  73.  *
  74.  *    Last Edit-Date: [Mon Mar  7 10:35:46 1994]
  75.  *
  76.  *    -hm    user configurable shell program
  77.  *    -hm    converting to a xxx(x)BSD system()
  78.  *
  79.  *----------------------------------------------------------------------------*/
  80.  
  81. #include "cwish.h"
  82.  
  83. #ifdef USE_OWN_SYSTEM
  84.  
  85. int
  86. mysystem(const char *cmdstring)
  87. {
  88.     pid_t pid;
  89.     void *intsave, *quitsave;
  90.     int omask;
  91.     int pstat;
  92.     static char *pname;
  93.  
  94.     if (!cmdstring)                /* just checking... */
  95.         return (1);
  96.  
  97.     if ((pname = rindex(opt_shell, '/')) == NULL)
  98.         pname = opt_shell;
  99.     else
  100.         pname++;
  101.  
  102.     omask = sigblock(sigmask(SIGCHLD));
  103.  
  104.     switch (pid = vfork())
  105.     {
  106.         case 0:            /* child */
  107.             (void) sigsetmask(omask);
  108.             execl(opt_shell, pname, "-c", cmdstring, (char *) NULL);
  109.             _exit(127);
  110.  
  111.         case -1:            /* error */
  112.             (void) sigsetmask(omask);
  113.             return (-1);
  114.     }
  115.  
  116.     intsave = signal(SIGINT, SIG_IGN);
  117.     quitsave = signal(SIGQUIT, SIG_IGN);
  118.  
  119.     pid = waitpid(pid, (int *) &pstat, 0);
  120.  
  121.     (void) sigsetmask(omask);
  122.  
  123.     (void) signal(SIGINT, intsave);
  124.     (void) signal(SIGQUIT, quitsave);
  125.  
  126.     return (pid == -1 ? -1 : pstat);
  127. }
  128.  
  129. #endif /* USE_OWN_SYSTEM */
  130.  
  131. /*--------------------------------- EOF -------------------------------------*/
  132.