|
|
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: 5219 (0x1463)
Types: TextFile
Names: »main.c«
└─⟦9ae75bfbd⟧ Bits:30007242 EUUGD3: Starter Kit
└─⟦653021b30⟧ »EurOpenD3/utils/downtime.tar.Z«
└─⟦946c717da⟧
└─⟦this⟧ »main.c«
/*
* Copyright (c) 1988 Michael A. Cooper, University of Southern California.
* This program may be used, copied, modified, and redistributed freely
* for noncommercial purposes, so long as this notice remains intact.
*/
#ifndef lint
static char *RCSid = "$Header: main.c,v 4.2 88/07/05 16:00:14 mcooper Exp $";
#endif
/*
*------------------------------------------------------------------
*
* $Source: /usr/skat3/src/common/usc/etc/downtime/RCS/main.c,v $
* $Revision: 4.2 $
* $Date: 88/07/05 16:00:14 $
* $State: Exp $
*
*------------------------------------------------------------------
*
* Michael A. Cooper
* Research and Development Group
* University Computing Services
* University of Southern California
* (mcooper@oberon.USC.EDU)
*
*------------------------------------------------------------------
*
* $Log: main.c,v $
* Revision 4.2 88/07/05 16:00:14 mcooper
* Added copyright notice.
*
* Revision 4.1 88/06/30 10:08:57 mcooper
* Fixed -u problem that caused no checktime()
* to be run.
*
* Revision 4.0 88/04/20 15:42:42 mcooper
* Version 4.
*
* Revision 3.4 88/04/19 18:25:51 mcooper
* Replace debug with verbose.
*
* Revision 3.3 88/04/11 19:48:27 mcooper
* Converted all dt_flags to use flag
* bits.
*
* Revision 3.2 88/03/01 15:48:00 mcooper
* Cleaned up header files.
*
* Revision 3.1 88/02/11 19:00:28 mcooper
* Fixed bug that caused cancel messages
* to be send when shutdown time arrived.
*
* Revision 3.0 87/07/24 14:19:50 mcooper
* Version 3.
*
*------------------------------------------------------------------
*/
#include "defs.h"
#include <signal.h>
#include "parse.h"
#define USAGE "Usage: %s [ -qf ] [ -krh ] command [ arguments ]\n"
int killflg = TRUE; /* Kill on shutdown */
int reboot = FALSE; /* Reboot on shutdown */
int halt = FALSE; /* Halt on shutdown */
int fake = FALSE; /* Fake shutdown */
int fastboot = FALSE; /* Do a fastboot(8) */
int nosync = FALSE; /* No disk sync */
int iflag = FALSE; /* Force interactive session */
int uflag = FALSE; /* Unlock all entries (at boot) */
int force = FALSE; /* Force mode */
int quiet = FALSE; /* Be quiet about what we're doing */
int shortshutmsg = TRUE;
int verbose = 1; /* Verbosity level */
char *prog = "DownTime"; /* The name of this program */
char *nologin = NOLOGIN; /* File to turn off logins */
/*
* Ccmd buffers
*/
int cmdbuf[STRSIZE];
char atmbuf[STRSIZE];
char wrkbuf[STRSIZE];
char command[STRSIZE];
main(argc, argv)
int argc;
char **argv;
{
register int x;
int catch(), catchcont();
extern int okayuser;
for (x = 1; x < argc; x++) {
if (argv[x][0] != '-')
break;
switch (argv[x][1]) {
case 'k':
killflg = FALSE;
fake = TRUE;
break;
case 'd':
verbose = 10;
break;
case 'r':
reboot = TRUE;
break;
case 'h':
halt = TRUE;
break;
case 'i':
iflag = TRUE;
break;
case 'q':
quiet = TRUE;
break;
case 'F':
force = TRUE;
break;
case 'u':
uflag = TRUE;
break;
case 'f':
fastboot = TRUE;
break;
case 'n':
nosync = TRUE;
break;
case '?':
default:
usage();
exit(2);
}
}
argc -= x;
argv += x;
if (nosync && fastboot) {
fprintf(stderr, "%s: -f and -n are not compatible options.\n", prog);
exit(1);
}
/*
* If we're super-user and config fails, its okay.
*/
if (config(CFFILE) < 0) {
fprintf(stderr, "%s: Configuration failed.\n", prog);
if (getuid() != ROOT) {
exit(1);
} else {
fprintf(stderr, "But you are the super-user.\n");
}
}
if (!okayuser) {
fprintf(stderr, "%s: You are not authorized to run this program.\n", prog);
exit(1);
}
signal(SIGINT, catch);
signal(SIGQUIT, catch);
/*
* set umask for file creation
*/
umask(02);
if (uflag) {
dtlock(NULL, L_UNLOCK);
checktime();
exit(0);
}
if (argc == 0) {
iflag = TRUE;
}
command[0] = 0;
if (!iflag) {
while(*argv != NULL) {
strcat(command, *argv++);
strcat(command, " ");
}
command[strlen(command)-1] = '\n';
}
signal(SIGCONT, catchcont);
cmbufs(cmdbuf, STRSIZE, atmbuf, STRSIZE, wrkbuf, STRSIZE);
cmseti(stdin,stdout,stderr);
toplevel();
cmdone();
}
/*
* usage - Print usage information.
*/
usage()
{
fprintf(stderr, USAGE, prog);
}
/*
* catchcont - Catch SIGCONT (after suspend).
*/
catchcont()
{
printf("\n%s", PROMPT);
fflush(stdout);
return;
}
/*
* catch - Catch interupts and make sure user really wants to exit.
*/
catch()
{
pval val;
fdb *used;
dprintf("catch called.\n");
if (iflag) {
prompt("Do you really want to exit? ");
parse(&ynfdb, &val, &used);
confirm();
if (val._pvint == YES) {
unlink(nologin);
cmdone();
exit(1);
}
toplevel();
} else {
unlink(nologin);
exit(1);
}
}