main.c revision 48625
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 * $Id: main.c,v 1.52 1999/06/17 19:04:55 markm Exp $ 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 "pccard_conf.h" 39#include <sys/signal.h> 40#include <sys/fcntl.h> 41 42static void 43screech(int sig) 44{ 45 msgDebug("\007Signal %d caught! That's bad!\n", sig); 46 longjmp(BailOut, sig); 47} 48 49int 50main(int argc, char **argv) 51{ 52 int choice, scroll, curr, max, status; 53 54 /* Catch fatal signals and complain about them if running as init */ 55 if (getpid() == 1) { 56 signal(SIGBUS, screech); 57 signal(SIGSEGV, screech); 58 } 59 60 /* We don't work too well when running as non-root anymore */ 61 if (geteuid() != 0) { 62 fprintf(stderr, "Error: This utility should only be run as root.\n"); 63 return 1; 64 } 65 66 /* Set up whatever things need setting up */ 67 systemInitialize(argc, argv); 68 69 /* Set default flag and variable values */ 70 installVarDefaults(NULL); 71 /* only when multi-user is it reasonable to do this here */ 72 if (!RunningAsInit) 73 installEnvironment(); 74 75 if (argc > 1 && !strcmp(argv[1], "-fake")) { 76 variable_set2(VAR_DEBUG, "YES", 0); 77 Fake = TRUE; 78 msgConfirm("I'll be just faking it from here on out, OK?"); 79 } 80 81 /* Try to preserve our scroll-back buffer */ 82 if (OnVTY) { 83 for (curr = 0; curr < 25; curr++) 84 putchar('\n'); 85 } 86 /* Move stderr aside */ 87 if (DebugFD) 88 dup2(DebugFD, 2); 89 90#ifdef PCCARD 91 /* Initialize PC-card */ 92 pccardInitialize(); 93#endif 94 95 /* Probe for all relevant devices on the system */ 96 deviceGetAll(); 97 98 /* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */ 99 if (!RunningAsInit) { 100 int i, start_arg; 101 102 if (!strstr(argv[0], "sysinstall")) 103 start_arg = 0; 104 else if (Fake) 105 start_arg = 2; 106 else 107 start_arg = 1; 108 for (i = start_arg; i < argc; i++) { 109 if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS) 110 systemShutdown(1); 111 } 112 if (argc > start_arg) 113 systemShutdown(0); 114 } 115 else 116 dispatch_load_file_int(TRUE); 117 118 status = setjmp(BailOut); 119 if (status) { 120 msgConfirm("A signal %d was caught - I'm saving what I can and shutting\n" 121 "If you can reproduce the problem, please turn Debug on in\n" 122 "the Options menu for the extra information it provides in\n" 123 "debugging problems like this.", status); 124 systemShutdown(status); 125 } 126 127 /* Begin user dialog at outer menu */ 128 dialog_clear(); 129 while (1) { 130 choice = scroll = curr = max = 0; 131 dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE); 132 if (getpid() != 1 133#ifdef __alpha__ 134 || !msgYesNo("Are you sure you wish to exit? The system will halt.") 135#else 136 || !msgYesNo("Are you sure you wish to exit? The system will reboot\n" 137 "(be sure to remove any floppies from the drives).") 138#endif 139 ) 140 break; 141 } 142 143 /* Say goodnight, Gracie */ 144 systemShutdown(0); 145 146 return 0; /* We should never get here */ 147} 148