main.c revision 119167
1/* 2 * The new sysinstall program. 3 * 4 * This is probably the last attempt in the `sysinstall' line, the next 5 * generation being slated for what's essentially a complete rewrite. 6 * 7 * $FreeBSD: head/usr.sbin/sade/main.c 119167 2003-08-20 06:24:12Z imp $ 8 * 9 * Copyright (c) 1995 10 * Jordan Hubbard. All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer, 17 * verbatim and that no modifications are made prior to this 18 * point in the file. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 23 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 */ 36 37#include "sysinstall.h" 38#include <sys/signal.h> 39#include <sys/fcntl.h> 40 41const char *StartName; /* Initial contents of argv[0] */ 42 43static void 44screech(int sig) 45{ 46 msgDebug("\007Signal %d caught! That's bad!\n", sig); 47 longjmp(BailOut, sig); 48} 49 50int 51main(int argc, char **argv) 52{ 53 int choice, scroll, curr, max, status; 54 55 /* Record name to be able to restart */ 56 StartName = argv[0]; 57 58 /* Catch fatal signals and complain about them if running as init */ 59 if (getpid() == 1) { 60 signal(SIGBUS, screech); 61 signal(SIGSEGV, screech); 62 } 63 signal(SIGPIPE, SIG_IGN); 64 65 /* We don't work too well when running as non-root anymore */ 66 if (geteuid() != 0) { 67 fprintf(stderr, "Error: This utility should only be run as root.\n"); 68 return 1; 69 } 70 71#ifdef PC98 72 { 73 /* XXX */ 74 char *p = getenv("TERM"); 75 if (p && strcmp(p, "cons25") == 0) 76 putenv("TERM=cons25w"); 77 } 78#endif 79 80 /* Set up whatever things need setting up */ 81 systemInitialize(argc, argv); 82 83 /* Set default flag and variable values */ 84 installVarDefaults(NULL); 85 /* only when multi-user is it reasonable to do this here */ 86 if (!RunningAsInit) 87 installEnvironment(); 88 89 if (argc > 1 && !strcmp(argv[1], "-fake")) { 90 variable_set2(VAR_DEBUG, "YES", 0); 91 Fake = TRUE; 92 msgConfirm("I'll be just faking it from here on out, OK?"); 93 } 94 if (argc > 1 && !strcmp(argv[1], "-restart")) 95 Restarting = TRUE; 96 97 /* Try to preserve our scroll-back buffer */ 98 if (OnVTY) { 99 for (curr = 0; curr < 25; curr++) 100 putchar('\n'); 101 } 102 /* Move stderr aside */ 103 if (DebugFD) 104 dup2(DebugFD, 2); 105 106 /* Initialize driver modules, if we haven't already done so (ie, 107 the user hit Ctrl-C -> Restart. */ 108 if (!pvariable_get("modulesInitialize")) { 109 moduleInitialize(); 110 pvariable_set("modulesInitialize=1"); 111 } 112 113 /* Initialize PC-card, if we haven't already done so. */ 114#ifdef PCCARD_ARCH 115 if (!variable_cmp(VAR_SKIP_PCCARD, "YES") && 116 variable_get(VAR_SKIP_PCCARD)!=1 && 117 !pvariable_get("pccardInitialize")) { 118 pccardInitialize(); 119 pvariable_set("pccardInitialize=1"); 120 } 121#endif 122 123 /* Initialize USB, if we haven't already done so. */ 124 if (!pvariable_get("usbInitialize")) { 125 usbInitialize(); 126 pvariable_set("usbInitialize=1"); 127 } 128 129 /* Probe for all relevant devices on the system */ 130 deviceGetAll(); 131 132 /* Prompt for the driver floppy if appropriate. */ 133 if (!pvariable_get("driverFloppyCheck")) { 134 driverFloppyCheck(); 135 pvariable_set("driverFloppyCheck=1"); 136 } 137 138 /* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */ 139 if (!RunningAsInit) { 140 int i, start_arg; 141 142 if (!strstr(argv[0], "sysinstall")) 143 start_arg = 0; 144 else if (Fake || Restarting) 145 start_arg = 2; 146 else 147 start_arg = 1; 148 for (i = start_arg; i < argc; i++) { 149 if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS) 150 systemShutdown(1); 151 } 152 if (argc > start_arg) 153 systemShutdown(0); 154 } 155 else 156 dispatch_load_file_int(TRUE); 157 158 status = setjmp(BailOut); 159 if (status) { 160 msgConfirm("A signal %d was caught - I'm saving what I can and shutting\n" 161 "down. If you can reproduce the problem, please turn Debug on\n" 162 "in the Options menu for the extra information it provides\n" 163 "in debugging problems like this.", status); 164 systemShutdown(status); 165 } 166 167 /* Begin user dialog at outer menu */ 168 dialog_clear(); 169 while (1) { 170 choice = scroll = curr = max = 0; 171 dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE); 172 if (getpid() != 1 173#if defined(__alpha__) || defined(__sparc64__) 174 || !msgNoYes("Are you sure you wish to exit? The system will halt.") 175#else 176 || !msgNoYes("Are you sure you wish to exit? The system will reboot\n" 177 "(be sure to remove any floppies/CDs/DVDs from the drives).") 178#endif 179 ) 180 break; 181 } 182 183 /* Say goodnight, Gracie */ 184 systemShutdown(0); 185 186 return 0; /* We should never get here */ 187} 188