dispatch.c (161059) | dispatch.c (161060) |
---|---|
1/* | 1/* |
2 * The new sysinstall program. | 2 * $FreeBSD: head/usr.sbin/sade/dispatch.c 161060 2006-08-07 23:35:49Z netchild $ |
3 * | 3 * |
4 * This is probably the last program in the `sysinstall' line - the next 5 * generation being essentially a complete rewrite. 6 * 7 * $FreeBSD: head/usr.sbin/sade/dispatch.c 154925 2006-01-27 21:00:31Z jkim $ 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, --- 12 unchanged lines hidden (view full) --- 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 | 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 unchanged lines hidden (view full) --- 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 |
37#include "sysinstall.h" | 32#include "sade.h" |
38#include <ctype.h> 39#include <errno.h> 40#include <sys/signal.h> 41#include <sys/fcntl.h> 42 43#include "list.h" 44 | 33#include <ctype.h> 34#include <errno.h> 35#include <sys/signal.h> 36#include <sys/fcntl.h> 37 38#include "list.h" 39 |
45static int dispatch_shutdown(dialogMenuItem *unused); | |
46static int dispatch_systemExecute(dialogMenuItem *unused); 47static int dispatch_msgConfirm(dialogMenuItem *unused); | 40static int dispatch_systemExecute(dialogMenuItem *unused); 41static int dispatch_msgConfirm(dialogMenuItem *unused); |
48static int dispatch_mediaOpen(dialogMenuItem *unused); 49static int dispatch_mediaClose(dialogMenuItem *unused); | |
50 51static struct _word { 52 char *name; 53 int (*handler)(dialogMenuItem *self); 54} resWords[] = { | 42 43static struct _word { 44 char *name; 45 int (*handler)(dialogMenuItem *self); 46} resWords[] = { |
55 { "configAnonFTP", configAnonFTP }, 56 { "configRouter", configRouter }, 57 { "configInetd", configInetd }, 58 { "configNFSServer", configNFSServer }, 59 { "configNTP", configNTP }, 60 { "configPCNFSD", configPCNFSD }, 61 { "configPackages", configPackages }, 62 { "configUsers", configUsers }, | |
63#ifdef WITH_SLICES 64 { "diskPartitionEditor", diskPartitionEditor }, 65#endif 66 { "diskPartitionWrite", diskPartitionWrite }, 67 { "diskLabelEditor", diskLabelEditor }, 68 { "diskLabelCommit", diskLabelCommit }, | 47#ifdef WITH_SLICES 48 { "diskPartitionEditor", diskPartitionEditor }, 49#endif 50 { "diskPartitionWrite", diskPartitionWrite }, 51 { "diskLabelEditor", diskLabelEditor }, 52 { "diskLabelCommit", diskLabelCommit }, |
69 { "distReset", distReset }, 70 { "distSetCustom", distSetCustom }, 71 { "distUnsetCustom", distUnsetCustom }, 72 { "distSetDeveloper", distSetDeveloper }, 73 { "distSetXDeveloper", distSetXDeveloper }, 74 { "distSetKernDeveloper", distSetKernDeveloper }, 75 { "distSetUser", distSetUser }, 76 { "distSetXUser", distSetXUser }, 77 { "distSetMinimum", distSetMinimum }, 78 { "distSetEverything", distSetEverything }, 79 { "distSetSrc", distSetSrc }, 80 { "distExtractAll", distExtractAll }, 81 { "docBrowser", docBrowser }, 82 { "docShowDocument", docShowDocument }, 83 { "installCommit", installCommit }, 84 { "installExpress", installExpress }, 85 { "installStandard", installStandard }, 86 { "installUpgrade", installUpgrade }, 87 { "installFixupBase", installFixupBase }, 88 { "installFixitHoloShell", installFixitHoloShell }, 89 { "installFixitCDROM", installFixitCDROM }, 90 { "installFixitFloppy", installFixitFloppy }, 91 { "installFilesystems", installFilesystems }, 92 { "installVarDefaults", installVarDefaults }, 93 { "loadConfig", dispatch_load_file }, 94 { "loadFloppyConfig", dispatch_load_floppy }, 95 { "mediaOpen", dispatch_mediaOpen }, 96 { "mediaClose", dispatch_mediaClose }, 97 { "mediaSetCDROM", mediaSetCDROM }, 98 { "mediaSetFloppy", mediaSetFloppy }, 99 { "mediaSetDOS", mediaSetDOS }, 100 { "mediaSetTape", mediaSetTape }, 101 { "mediaSetFTP", mediaSetFTP }, 102 { "mediaSetFTPActive", mediaSetFTPActive }, 103 { "mediaSetFTPPassive", mediaSetFTPPassive }, 104 { "mediaSetHTTP", mediaSetHTTP }, 105 { "mediaSetUFS", mediaSetUFS }, 106 { "mediaSetNFS", mediaSetNFS }, 107 { "mediaSetFTPUserPass", mediaSetFTPUserPass }, 108 { "mediaSetCPIOVerbosity", mediaSetCPIOVerbosity }, 109 { "mediaGetType", mediaGetType }, | |
110 { "msgConfirm", dispatch_msgConfirm }, | 53 { "msgConfirm", dispatch_msgConfirm }, |
111 { "optionsEditor", optionsEditor }, 112 { "packageAdd", packageAdd }, 113 { "addGroup", userAddGroup }, 114 { "addUser", userAddUser }, 115 { "shutdown", dispatch_shutdown }, | |
116 { "system", dispatch_systemExecute }, 117 { "dumpVariables", dump_variables }, | 54 { "system", dispatch_systemExecute }, 55 { "dumpVariables", dump_variables }, |
118 { "tcpMenuSelect", tcpMenuSelect }, | |
119 { NULL, NULL }, 120}; 121 122/* 123 * Helper routines for buffering data. 124 * 125 * We read an entire configuration into memory before executing it 126 * so that we are truely standalone and can do things like nuke the --- 34 unchanged lines hidden (view full) --- 161 if (!new) 162 return NULL; 163 164 new->string = strdup(string); 165 INSQUEUE(new, head->q_back); 166 167 return new; 168} | 56 { NULL, NULL }, 57}; 58 59/* 60 * Helper routines for buffering data. 61 * 62 * We read an entire configuration into memory before executing it 63 * so that we are truely standalone and can do things like nuke the --- 34 unchanged lines hidden (view full) --- 98 if (!new) 99 return NULL; 100 101 new->string = strdup(string); 102 INSQUEUE(new, head->q_back); 103 104 return new; 105} |
169 | 106 |
170/* 171 * Command processing 172 */ 173 | 107/* 108 * Command processing 109 */ 110 |
174/* Just convenience */ | |
175static int | 111static int |
176dispatch_shutdown(dialogMenuItem *unused) 177{ 178 systemShutdown(0); 179 return DITEM_FAILURE; 180} 181 182static int | |
183dispatch_systemExecute(dialogMenuItem *unused) 184{ 185 char *cmd = variable_get(VAR_COMMAND); 186 187 if (cmd) 188 return systemExecute(cmd) ? DITEM_FAILURE : DITEM_SUCCESS; 189 else 190 msgDebug("_systemExecute: No command passed in `command' variable.\n"); --- 10 unchanged lines hidden (view full) --- 201 return DITEM_SUCCESS; 202 } 203 204 msgDebug("_msgConfirm: No message passed in `command' variable.\n"); 205 return DITEM_FAILURE; 206} 207 208static int | 112dispatch_systemExecute(dialogMenuItem *unused) 113{ 114 char *cmd = variable_get(VAR_COMMAND); 115 116 if (cmd) 117 return systemExecute(cmd) ? DITEM_FAILURE : DITEM_SUCCESS; 118 else 119 msgDebug("_systemExecute: No command passed in `command' variable.\n"); --- 10 unchanged lines hidden (view full) --- 130 return DITEM_SUCCESS; 131 } 132 133 msgDebug("_msgConfirm: No message passed in `command' variable.\n"); 134 return DITEM_FAILURE; 135} 136 137static int |
209dispatch_mediaOpen(dialogMenuItem *unused) 210{ 211 return mediaOpen(); 212} 213 214static int 215dispatch_mediaClose(dialogMenuItem *unused) 216{ 217 mediaClose(); 218 return DITEM_SUCCESS; 219} 220 221static int | |
222call_possible_resword(char *name, dialogMenuItem *value, int *status) 223{ 224 int i, rval; 225 226 rval = 0; 227 for (i = 0; resWords[i].name; i++) { 228 if (!strcmp(name, resWords[i].name)) { 229 *status = resWords[i].handler(value); --- 115 unchanged lines hidden (view full) --- 345 variable_unset(VAR_NONINTERACTIVE); 346 else { 347 variable_set2(VAR_NONINTERACTIVE, old_interactive, 0); 348 free(old_interactive); 349 } 350 351 return result; 352} | 138call_possible_resword(char *name, dialogMenuItem *value, int *status) 139{ 140 int i, rval; 141 142 rval = 0; 143 for (i = 0; resWords[i].name; i++) { 144 if (!strcmp(name, resWords[i].name)) { 145 *status = resWords[i].handler(value); --- 115 unchanged lines hidden (view full) --- 261 variable_unset(VAR_NONINTERACTIVE); 262 else { 263 variable_set2(VAR_NONINTERACTIVE, old_interactive, 0); 264 free(old_interactive); 265 } 266 267 return result; 268} |
353 354int 355dispatch_load_file_int(int quiet) 356{ 357 FILE *fp; 358 char *cp; 359 int i; 360 qelement *list; 361 362 static const char *names[] = { 363 "install.cfg", 364 "/stand/install.cfg", 365 "/tmp/install.cfg", 366 NULL 367 }; 368 369 fp = NULL; 370 cp = variable_get(VAR_CONFIG_FILE); 371 if (!cp) { 372 for (i = 0; names[i]; i++) 373 if ((fp = fopen(names[i], "r")) != NULL) 374 break; 375 } else 376 fp = fopen(cp, "r"); 377 378 if (!fp) { 379 if (!quiet) 380 msgConfirm("Unable to open %s: %s", cp, strerror(errno)); 381 return DITEM_FAILURE; 382 } 383 384 list = dispatch_load_fp(fp); 385 fclose(fp); 386 387 return dispatch_execute(list); 388} 389 390int 391dispatch_load_file(dialogMenuItem *self) 392{ 393 return dispatch_load_file_int(FALSE); 394} 395 396int 397dispatch_load_floppy(dialogMenuItem *self) 398{ 399 int what = DITEM_SUCCESS; 400 extern char *distWanted; 401 char *cp; 402 FILE *fp; 403 qelement *list; 404 405 mediaClose(); 406 cp = variable_get_value(VAR_INSTALL_CFG, 407 "Specify the name of a configuration file\n" 408 "residing on a MSDOS or UFS floppy.", 0); 409 if (!cp || !*cp) { 410 variable_unset(VAR_INSTALL_CFG); 411 what |= DITEM_FAILURE; 412 return what; 413 } 414 415 distWanted = cp; 416 /* Try to open the floppy drive */ 417 if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE) { 418 msgConfirm("Unable to set media device to floppy."); 419 what |= DITEM_FAILURE; 420 mediaClose(); 421 return what; 422 } 423 424 if (!DEVICE_INIT(mediaDevice)) { 425 msgConfirm("Unable to mount floppy filesystem."); 426 what |= DITEM_FAILURE; 427 mediaClose(); 428 return what; 429 } 430 431 fp = DEVICE_GET(mediaDevice, cp, TRUE); 432 if (fp) { 433 list = dispatch_load_fp(fp); 434 fclose(fp); 435 mediaClose(); 436 437 what |= dispatch_execute(list); 438 } 439 else { 440 if (!variable_get(VAR_NO_ERROR)) 441 msgConfirm("Configuration file '%s' not found.", cp); 442 variable_unset(VAR_INSTALL_CFG); 443 what |= DITEM_FAILURE; 444 mediaClose(); 445 } 446 return what; 447} 448 | |