main.c revision 161099
1/*
2 * $FreeBSD: head/usr.sbin/sade/main.c 161099 2006-08-08 13:45:46Z delphij $
3 *
4 * Copyright (c) 1995
5 *     Jordan Hubbard.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer,
12 *    verbatim and that no modifications are made prior to this
13 *    point in the file.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 */
31
32#include "sade.h"
33#include <sys/signal.h>
34#include <sys/fcntl.h>
35
36const char *StartName;		/* Initial contents of argv[0] */
37
38int
39main(int argc, char **argv)
40{
41    int choice, scroll, curr, max, status;
42
43    /* Record name to be able to restart */
44    StartName = argv[0];
45
46    signal(SIGPIPE, SIG_IGN);
47
48    /* We don't work too well when running as non-root anymore */
49    if (geteuid() != 0) {
50	fprintf(stderr, "Error: This utility should only be run as root.\n");
51	return 1;
52    }
53
54#ifdef PC98
55    {
56	/* XXX */
57	char *p = getenv("TERM");
58	if (p && strcmp(p, "cons25") == 0)
59	    putenv("TERM=cons25w");
60    }
61#endif
62
63    /* Set up whatever things need setting up */
64    systemInitialize(argc, argv);
65
66    /* Set default flag and variable values */
67    installVarDefaults(NULL);
68
69    if (argc > 1 && !strcmp(argv[1], "-fake")) {
70	variable_set2(VAR_DEBUG, "YES", 0);
71	Fake = TRUE;
72	msgConfirm("I'll be just faking it from here on out, OK?");
73    }
74    if (argc > 1 && !strcmp(argv[1], "-restart"))
75	Restarting = TRUE;
76
77    /* Try to preserve our scroll-back buffer */
78    if (OnVTY) {
79	for (curr = 0; curr < 25; curr++)
80	    putchar('\n');
81    }
82    /* Move stderr aside */
83    if (DebugFD)
84	dup2(DebugFD, 2);
85
86    /* Initialize driver modules, if we haven't already done so (ie,
87       the user hit Ctrl-C -> Restart. */
88    if (!pvariable_get("modulesInitialize")) {
89	pvariable_set("modulesInitialize=1");
90    }
91
92    /* Probe for all relevant devices on the system */
93    deviceGetAll();
94
95    /* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */
96
97    status = setjmp(BailOut);
98    if (status) {
99	msgConfirm("A signal %d was caught - I'm saving what I can and shutting\n"
100		   "down.  If you can reproduce the problem, please turn Debug on\n"
101		   "in the Options menu for the extra information it provides\n"
102		   "in debugging problems like this.", status);
103  ;
104    }
105
106    /* Begin user dialog at outer menu */
107    dialog_clear();
108    while (1) {
109	choice = scroll = curr = max = 0;
110	dmenuOpen(&MenuMain, &choice, &scroll, &curr, &max, FALSE);
111	if (getpid() != 1
112	    || !msgNoYes("Are you sure you wish to exit?")
113	    )
114	    break;
115    }
116
117    /* Shut down curses */
118    endwin();
119
120    return 0;
121}
122