main.c revision 104940
11638Srgrimes/* 21638Srgrimes * The new sysinstall program. 31638Srgrimes * 41638Srgrimes * This is probably the last attempt in the `sysinstall' line, the next 51638Srgrimes * generation being slated for what's essentially a complete rewrite. 61638Srgrimes * 71638Srgrimes * $FreeBSD: head/usr.sbin/sade/main.c 104940 2002-10-11 22:30:09Z obrien $ 81638Srgrimes * 91638Srgrimes * Copyright (c) 1995 101638Srgrimes * Jordan Hubbard. All rights reserved. 111638Srgrimes * 121638Srgrimes * Redistribution and use in source and binary forms, with or without 131638Srgrimes * modification, are permitted provided that the following conditions 141638Srgrimes * are met: 151638Srgrimes * 1. Redistributions of source code must retain the above copyright 161638Srgrimes * notice, this list of conditions and the following disclaimer, 171638Srgrimes * verbatim and that no modifications are made prior to this 181638Srgrimes * point in the file. 191638Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 201638Srgrimes * notice, this list of conditions and the following disclaimer in the 211638Srgrimes * documentation and/or other materials provided with the distribution. 221638Srgrimes * 231638Srgrimes * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND 241638Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251638Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261638Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE 271638Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281638Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291638Srgrimes * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) 301638Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311638Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321638Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331638Srgrimes * SUCH DAMAGE. 341638Srgrimes * 351638Srgrimes */ 361638Srgrimes 371638Srgrimes#include "sysinstall.h" 381638Srgrimes#include <sys/signal.h> 391638Srgrimes#include <sys/fcntl.h> 401638Srgrimes 411638Srgrimesconst char *StartName; /* Initial contents of argv[0] */ 421638Srgrimes 431638Srgrimesstatic void 441638Srgrimesscreech(int sig) 451638Srgrimes{ 461638Srgrimes msgDebug("\007Signal %d caught! That's bad!\n", sig); 471638Srgrimes longjmp(BailOut, sig); 481638Srgrimes} 491638Srgrimes 501638Srgrimesint 511638Srgrimesmain(int argc, char **argv) 521638Srgrimes{ 531638Srgrimes int choice, scroll, curr, max, status; 541638Srgrimes 551638Srgrimes /* Record name to be able to restart */ 561638Srgrimes StartName = argv[0]; 571638Srgrimes 581638Srgrimes /* Catch fatal signals and complain about them if running as init */ 591638Srgrimes if (getpid() == 1) { 601638Srgrimes signal(SIGBUS, screech); 611638Srgrimes signal(SIGSEGV, screech); 621638Srgrimes } 631638Srgrimes signal(SIGPIPE, SIG_IGN); 641638Srgrimes 651638Srgrimes /* We don't work too well when running as non-root anymore */ 661638Srgrimes if (geteuid() != 0) { 671638Srgrimes fprintf(stderr, "Error: This utility should only be run as root.\n"); 681638Srgrimes return 1; 691638Srgrimes } 701638Srgrimes 711638Srgrimes#ifdef PC98 721638Srgrimes { 731638Srgrimes /* XXX */ 741638Srgrimes char *p = getenv("TERM"); 751638Srgrimes if (p && strcmp(p, "cons25") == 0) 761638Srgrimes putenv("TERM=cons25w"); 771638Srgrimes } 781638Srgrimes#endif 791638Srgrimes 801638Srgrimes /* Set up whatever things need setting up */ 811638Srgrimes systemInitialize(argc, argv); 821638Srgrimes 831638Srgrimes /* Set default flag and variable values */ 841638Srgrimes installVarDefaults(NULL); 851638Srgrimes /* 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 (!pvariable_get("pccardInitialize")) { 116 pccardInitialize(); 117 pvariable_set("pccardInitialize=1"); 118 } 119#endif 120 121 /* Initialize USB, if we haven't already done so. */ 122 if (!pvariable_get("usbInitialize")) { 123 usbInitialize(); 124 pvariable_set("usbInitialize=1"); 125 } 126 127 /* Probe for all relevant devices on the system */ 128 deviceGetAll(); 129 130 /* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */ 131 if (!RunningAsInit) { 132 int i, start_arg; 133 134 if (!strstr(argv[0], "sysinstall")) 135 start_arg = 0; 136 else if (Fake || Restarting) 137 start_arg = 2; 138 else 139 start_arg = 1; 140 for (i = start_arg; i < argc; i++) { 141 if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS) 142 systemShutdown(1); 143 } 144 if (argc > start_arg) 145 systemShutdown(0); 146 } 147 else 148 dispatch_load_file_int(TRUE); 149 150 status = setjmp(BailOut); 151 if (status) { 152 msgConfirm("A signal %d was caught - I'm saving what I can and shutting\n" 153 "down. If you can reproduce the problem, please turn Debug on\n" 154 "in the Options menu for the extra information it provides\n" 155 "in debugging problems like this.", status); 156 systemShutdown(status); 157 } 158 159 /* Begin user dialog at outer menu */ 160 dialog_clear(); 161 while (1) { 162 choice = scroll = curr = max = 0; 163 dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE); 164 if (getpid() != 1 165#if defined(__alpha__) || defined(__sparc64__) 166 || !msgNoYes("Are you sure you wish to exit? The system will halt.") 167#else 168 || !msgNoYes("Are you sure you wish to exit? The system will reboot\n" 169 "(be sure to remove any floppies/CDs/DVDs from the drives).") 170#endif 171 ) 172 break; 173 } 174 175 /* Say goodnight, Gracie */ 176 systemShutdown(0); 177 178 return 0; /* We should never get here */ 179} 180