|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 4050 (0xfd2)
Types: TextFile
Names: »main.c«
└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
└─⟦this⟧ »EUUGD11/euug-87hel/sec8/mcp/src/main.c«
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <setjmp.h>
#include <signal.h>
#include "sysdep.h"
#include "macros.h"
#include "mem.h"
#include "command.h"
#define ROOT_PROMPT "\r(mcp) "
#define PROMPT "\r( ) "
#define CARGS 32 /* # command line args allowed */
#ifdef sun
#define sighandler (void (*)())
#else
#define sighandler (int (*)())
#endif
extern int scommcmp(), kids, root, ModBits, NCommands, goodbye(), DevTty;
extern struct command Ctable[];
extern char Working_Directory[];
extern int ReportGoop();
extern Summarize();
extern char *sprintf();
jmp_buf interrupt, in_continue; /* setjmp vectors */
main(argc, argv)
int argc;
char **argv;
{
static char *prompt;
static addr v[CARGS+1];
int sjval, index, c, found, goop = 0;
int buildit, checkem, summary, listem, printversion;
char errmsg[MEDIUM_BUF];
(void) umask(022);
/*
* Find out if this is the superuser, what the current working
* directory is, seed random number generator.
* For Sun systems, also find out about file server, etc.
*/
init_identities();
buildit = checkem = summary = listem = printversion = 0;
while (--argc && **++argv == '-')
for (++*argv; **argv; ++*argv)
switch (**argv) {
case 'v':
printversion++; break;
case 'l':
listem++; break;
case 'B':
buildit++; break;
case 'c':
checkem++; break;
case 's':
summary++; break;
default:
(void) sprintf(errmsg, "mcp: bad option '%c' (ignored)",
**argv);
err(errmsg);
break;
}
/*
* Set up descriptor for /dev/tty or just attached to stderr
* if not running interactively.
*/
init_tty(buildit || (!checkem && !summary && !listem));
if (buildit && (checkem || summary || listem))
fatal("mcp: can't use -B with any other option.");
if (buildit && !root)
fatal("mcp: must be the super-user to use -B");
if (argc)
err("mcp: extra arguments ignored");
if (printversion && !buildit) {
ShowVersion();
if (!(checkem || summary || listem))
goodbye(0);
}
/*
* Must set up some sort of quick 'n dirty signal handling lest
* an interrupt cause the program to exit with the password
* file locked. So we block all signals except SIGINT, and trap
* SIGINT to goodbye().
*/
(void) sigsetmask(~mask(SIGINT));
(void) signal(SIGINT, sighandler goodbye);
if ( root && !(checkem || summary || listem)) {
msg("Locking password file...");
if (!lockpw())
fatal("mcp: password file busy");
prompt = ROOT_PROMPT;
}
else
prompt = PROMPT;
if (buildit) Build(); /* Build() doesn't return */
/*
* Pass a flag to init_lists() to indicate whether all or
* or only some of the global lists need be initialized.
*/
init_lists(!(checkem || summary || listem));
if (checkem) goop = ReportGoop();
if (listem) ListThemThangs();
if (summary) Summarize();
if (checkem || summary || listem) goodbye(goop ? 1 : 0);
#if CKPTIME > 0
if (root)
(void) alarm(CKPTIME * 60); /* start checkpointing timer */
#endif
/*
* Trap interrupts back to the main command interpreter.
*/
sjval = setjmp(interrupt);
if (sjval)
msg("\r\n");
setsignals(); /* connect signal handlers */
/*
* Main command line interpreting loop
*/
for (;;) {
if (kids) reapchild();
closefiles();
freeargv(v);
free_gpa();
freetmplists();
(void) chdir(Working_Directory);
GetCommandLine(prompt, CARGS, &c, v);
if (c == 0)
continue;
index = search_array((char *)Ctable, (char *)v[0], NCommands,
sizeof (struct command), scommcmp, &found);
if (!found) {
err1("%s: unknown command", (char *)v[0]);
continue;
}
(*Ctable[index].c_func)(c, v);
}
}
reapchild()
{
if (wait3((union wait *)0, WNOHANG, (struct rusage *)0) > 0)
kids--;
return;
}
#if CKPTIME > 0
wakeup()
{
kids && reapchild();
ModBits && ckpchanges();
(void) alarm(CKPTIME * 60);
return;
}
#endif
closefiles()
{
register int i, nd = getdtablesize();
for (i=3; i < nd; i++)
if (i != DevTty)
(void) close(i);
return;
}