]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - usr.sbin/sade/main.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / usr.sbin / sade / main.c
1 /*
2  * $FreeBSD$
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
36 const char *StartName;          /* Initial contents of argv[0] */
37 const char *ProgName = "sade";
38
39 int
40 main(int argc, char **argv)
41 {
42     int choice, scroll, curr, max, status;
43     
44     /* Record name to be able to restart */
45     StartName = argv[0];
46
47     signal(SIGPIPE, SIG_IGN);
48
49     /* We don't work too well when running as non-root anymore */
50     if (geteuid() != 0) {
51         fprintf(stderr, "Error: This utility should only be run as root.\n");
52         return 1;
53     }
54
55 #ifdef PC98
56     {
57         /* XXX */
58         char *p = getenv("TERM");
59         if (p && strcmp(p, "cons25") == 0)
60             setenv("TERM", "cons25w", 1);
61     }
62 #endif
63
64     /* Set up whatever things need setting up */
65     systemInitialize(argc, argv);
66
67     /* Set default flag and variable values */
68     installVarDefaults(NULL);
69
70     if (argc > 1 && !strcmp(argv[1], "-fake")) {
71         variable_set2(VAR_DEBUG, "YES", 0);
72         Fake = TRUE;
73         msgConfirm("I'll be just faking it from here on out, OK?");
74     }
75     if (argc > 1 && !strcmp(argv[1], "-restart"))
76         Restarting = TRUE;
77
78     /* Try to preserve our scroll-back buffer */
79     if (OnVTY) {
80         for (curr = 0; curr < 25; curr++)
81             putchar('\n');
82     }
83     /* Move stderr aside */
84     if (DebugFD)
85         dup2(DebugFD, 2);
86
87     /* Initialize driver modules, if we haven't already done so (ie,
88        the user hit Ctrl-C -> Restart. */
89     if (!pvariable_get("modulesInitialize")) {
90         pvariable_set("modulesInitialize=1");
91     }
92
93     /* Probe for all relevant devices on the system */
94     deviceGetAll();
95
96     /* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */
97
98     status = setjmp(BailOut);
99     if (status) {
100         msgConfirm("A signal %d was caught - I'm saving what I can and shutting\n"
101                    "down.  If you can reproduce the problem, please turn Debug on\n"
102                    "in the Options menu for the extra information it provides\n"
103                    "in debugging problems like this.", status);
104   ;
105     }
106
107     /* Begin user dialog at outer menu */
108     dialog_clear();
109     while (1) {
110         choice = scroll = curr = max = 0;
111         dmenuOpen(&MenuMain, &choice, &scroll, &curr, &max, FALSE);
112         if (getpid() != 1
113             || !msgNoYes("Are you sure you wish to exit?")
114             )
115             break;
116     }
117
118     /* Shut down curses */
119     endwin();
120
121     return 0;
122 }