home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------*
- *
- * cwish - windowing user friendly shell
- * -------------------------------------
- *
- * Copyright (c) 1988-1994 Hellmuth Michaelis
- *
- * Eggerstedtstr. 28
- * 22765 Hamburg
- * Europe
- *
- * Tel: +49 / 40 / 384298 (private)
- * Tel: +49 / 40 / 55903-170 (at work)
- * e-mail: hm@hcswork.hcs.de
- *
- * --------oOo--------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *===========================================================================
- *
- * The source for the mysystem() routine below is taken from NetBSD
- * (pre 1.0) current as of February 5, 1994.
- *
- * It was modified to suit my needs, i.e.: i added the ability to
- * exec a configurable shell and reformatted it a bit to make it
- * consitent with the rest of cwish.
- *
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *---------------------------------------------------------------------------*
- *
- * Last Edit-Date: [Mon Mar 7 10:35:46 1994]
- *
- * -hm user configurable shell program
- * -hm converting to a xxx(x)BSD system()
- *
- *----------------------------------------------------------------------------*/
-
- #include "cwish.h"
-
- #ifdef USE_OWN_SYSTEM
-
- int
- mysystem(const char *cmdstring)
- {
- pid_t pid;
- void *intsave, *quitsave;
- int omask;
- int pstat;
- static char *pname;
-
- if (!cmdstring) /* just checking... */
- return (1);
-
- if ((pname = rindex(opt_shell, '/')) == NULL)
- pname = opt_shell;
- else
- pname++;
-
- omask = sigblock(sigmask(SIGCHLD));
-
- switch (pid = vfork())
- {
- case 0: /* child */
- (void) sigsetmask(omask);
- execl(opt_shell, pname, "-c", cmdstring, (char *) NULL);
- _exit(127);
-
- case -1: /* error */
- (void) sigsetmask(omask);
- return (-1);
- }
-
- 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);
-
- return (pid == -1 ? -1 : pstat);
- }
-
- #endif /* USE_OWN_SYSTEM */
-
- /*--------------------------------- EOF -------------------------------------*/
-