home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume26
/
sysinfo-1.0
/
part01
/
run.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-10
|
4KB
|
180 lines
/*
* Copyright (c) 1992 Michael A. Cooper.
* This software may be freely distributed provided it is not sold for
* profit and the author is credited appropriately.
*/
#ifndef lint
static char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/run.c,v 1.4 1992/04/26 23:32:06 mcooper Exp $";
#endif
/*
* $Log: run.c,v $
* Revision 1.4 1992/04/26 23:32:06 mcooper
* Add Copyright notice
*
* Revision 1.3 1992/04/17 01:07:59 mcooper
* More de-linting
*
* Revision 1.2 1992/04/16 02:25:39 mcooper
* Bug fixes, de-linting, and other changes found with CodeCenter.
*
* Revision 1.1 1992/03/22 00:20:10 mcooper
* Initial revision
*
*/
/*
* Things related to running system commands.
*/
#include <stdio.h>
#include "system.h"
#include "defs.h"
/*
* Specific command to determine our model name.
*/
#if defined(MODEL_COMMAND)
char *ModelCommand[] = { MODEL_COMMAND, NULL };
#endif /* MODEL_COMMAND */
/*
* Application architecture commands.
* These commands should print the system's application architecture.
*/
char *AppArchCmds[] = {
"/bin/arch",
"/bin/mach",
"/bin/machine",
NULL };
/*
* Kernel architecture commands.
* These commands should print the system's kernel architecture.
*/
char *KernArchCmds[] = {
"/bin/arch -k",
"/bin/mach",
"/bin/machine",
NULL };
/*
* Architecture test files.
* Each test file is run and if the exit status is 0,
* the basename of the command is the name of the system architecture.
*/
char *ArchFiles[] = {
"/bin/alliant",
"/bin/vax",
"/bin/sun",
NULL };
/*
* CPU type test files.
* Each test file is run and if the exit status is 0,
* the basename of the command is the name of the system CPU type.
*/
char *CPUFiles[] = {
"/bin/sparc",
"/bin/mc68010",
"/bin/mc68020",
"/bin/mc68030",
"/bin/mc68040",
"/bin/m68k",
"/bin/vax",
"/bin/alliant",
"/bin/i386",
"/bin/i860",
"/bin/iAPX286",
"/bin/pdp11",
"/bin/u370",
"/bin/u3b15",
"/bin/u3b2",
"/bin/u3b5",
"/bin/u3b",
NULL };
/*
* Run a list of commands (found in cmds) and return command output.
*/
extern char *RunCmds(Cmds)
char **Cmds;
{
static char Buf[BUFSIZ];
int l;
FILE *pf;
register char *p;
char **Cmd;
for (Cmd = Cmds; Cmd != NULL && *Cmd != NULL; ++Cmd) {
/*
* If this command has any args, nuke them for the access() test.
*/
strcpy(Buf, *Cmd);
p = index(Buf, ' ');
if (p != NULL)
*p = C_NULL;
if (access(Buf, X_OK) != 0)
continue;
if ((pf = popen(*Cmd, "r")) == NULL)
continue;
if (fgets(Buf, sizeof(Buf), pf) == NULL) {
pclose(pf);
continue;
}
pclose(pf);
l = strlen(Buf);
if (Buf[l-1] == '\n')
Buf[l-1] = C_NULL;
return(Buf);
}
return((char *) NULL);
}
/*
* Run a list of test files. Each test file is run and if the
* exit status is 0, we return the basename of the command.
* e.g. If "/bin/vax" exists and returns status 0, return string "vax".
*/
extern char *RunTestFiles(Cmds)
char **Cmds;
{
char **Cmd;
register char *p;
static char Buf[BUFSIZ];
for (Cmd = Cmds; Cmd != NULL && *Cmd != NULL; ++Cmd) {
/*
* If this command has any args, nuke them for the access() test.
*/
strcpy(Buf, *Cmd);
p = index(Buf, ' ');
if (p != NULL)
*p = C_NULL;
if (access(Buf, X_OK) != 0)
continue;
if (system(*Cmd) != 0)
continue;
/*
* The name of this architecture is the last part of the Cmd name.
*/
strcpy(Buf, *Cmd);
p = rindex(Buf, '/');
if (p != NULL)
++p;
return(p);
}
return(NULL);
}