Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!mips!prls!pyramid!cbmvax!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: How to issue a C SHELL command within a C program Message-ID: <3985@auspex.auspex.com> Date: 29 Aug 90 22:26:59 GMT References: <852@hls0.hls.oz> <3923@auspex.auspex.com> <1990Aug28.214551.6759@gtisqr.uucp> Organization: Auspex Systems, Santa Clara Lines: 42 > if (!sh) >#if BSD || SUN > sh = "/bin/csh"; >#endif /* BSD || SUN */ >#if USG || SMOS || HPUX || XENIX > sh = "/bin/sh"; >#endif /* USG || SMOS || HPUX || XENIX */ This isn't really necessary. Some of the systems in the latter category *do* have the C shell, and some of the users in systems in the former category don't use it if they have an alternative they like better. In addition, most UNIX systems these days arrange for the SHELL environment variable to be set. Just doing if (!sh) sh = "/bin/sh"; shouldn't annoy any C shell users, and removes some ugly #ifdefs. (BTW, even on BSD and SunOS systems, if the user's "/etc/passwd" entry doesn't specify a shell, they get "/bin/sh", not "/bin/csh".) >#if USG || SMOS || HPUX || XENIX > /* Parent disables signals and waits. */ > oldsigint = signal(SIGINT, SIG_IGN); > oldsigquit = signal(SIGQUIT, SIG_IGN); > wait(&status); > signal(SIGINT, oldsigint); > signal(SIGQUIT, oldsigquit); >#else /* BSD || SUN */ > /* BSD should disable signals while waiting for child too, */ > /* but I can't remember how. -- RLD 08-28-90 */ > wait(&status); >#endif /* USG || SMOS || HPUX || XENIX */ BSD does it exactly the same way the other systems do. On BSD and SunOS systems - and on some systems that fall into the first category - you can block, rather than ignore, the signal, so that if the user types ^C it'll be "held" until they unblock it. If you don't want to do that, though, the same calls to "signal()" you use for the other systems will do the job on BSD and SunOS.