diff options
author | Guillaume Cottenceau <gc@mandriva.com> | 2001-02-06 16:54:36 +0000 |
---|---|---|
committer | Guillaume Cottenceau <gc@mandriva.com> | 2001-02-06 16:54:36 +0000 |
commit | ab79ffa49720328bdf9e44b842e7b015e7835cfd (patch) | |
tree | 2b6eaced12858569d794621dbb8255f555a72cd9 /mdk-stage1 | |
parent | ed27fb7a0964b12e0bf96bc7fa8b4ba6a50a18d6 (diff) | |
download | drakx-ab79ffa49720328bdf9e44b842e7b015e7835cfd.tar drakx-ab79ffa49720328bdf9e44b842e7b015e7835cfd.tar.gz drakx-ab79ffa49720328bdf9e44b842e7b015e7835cfd.tar.bz2 drakx-ab79ffa49720328bdf9e44b842e7b015e7835cfd.tar.xz drakx-ab79ffa49720328bdf9e44b842e7b015e7835cfd.zip |
- slighty change the message when exiting successfully from install, to not mess with abnormal termination
- get back dialog for hostname and domain in case of unable to guess domain
- try to resolve DNS if self-ip can't resolve, to guess domain
- remember entries so that when there is a problem you don't have to re-enter everything (ncurses sucking stuff in case of stdio-frontend..)
- use larger buffer for list_directory since in /dev there can be *many* files
Diffstat (limited to 'mdk-stage1')
-rw-r--r-- | mdk-stage1/disk.c | 2 | ||||
-rw-r--r-- | mdk-stage1/init.c | 2 | ||||
-rw-r--r-- | mdk-stage1/modules.c | 2 | ||||
-rw-r--r-- | mdk-stage1/network.c | 66 | ||||
-rw-r--r-- | mdk-stage1/newt-frontend.c | 12 | ||||
-rw-r--r-- | mdk-stage1/stage1.c | 2 | ||||
-rw-r--r-- | mdk-stage1/stdio-frontend.c | 70 | ||||
-rw-r--r-- | mdk-stage1/tools.c | 2 |
8 files changed, 119 insertions, 39 deletions
diff --git a/mdk-stage1/disk.c b/mdk-stage1/disk.c index 02a9e95b2..c7ad9c7f0 100644 --- a/mdk-stage1/disk.c +++ b/mdk-stage1/disk.c @@ -54,7 +54,7 @@ static char * disk_extract_list_directory(char * direct) static enum return_type try_with_device(char *dev_name) { char * questions_location[] = { "Directory or ISO image", NULL }; - char ** answers_location; + static char ** answers_location = NULL; char device_fullname[50]; char location_full[500]; diff --git a/mdk-stage1/init.c b/mdk-stage1/init.c index 202993b47..fb33c7480 100644 --- a/mdk-stage1/init.c +++ b/mdk-stage1/init.c @@ -431,7 +431,7 @@ int main(int argc, char **argv) printf("exiting stage1-initializer -- giving hand to rescue\n"); return 0; } else - printf("back to stage1-initializer control -- install exited normally\n"); + printf("back to stage1-initializer control (install succeeded)\n"); if (testing) return 0; diff --git a/mdk-stage1/modules.c b/mdk-stage1/modules.c index c6bdb4afb..3f9647a35 100644 --- a/mdk-stage1/modules.c +++ b/mdk-stage1/modules.c @@ -282,7 +282,7 @@ int my_insmod(const char * mod_name, enum driver_type type, char * options) static enum return_type insmod_with_options(char * mod, enum driver_type type) { char * questions[] = { "Options", NULL }; - char ** answers; + static char ** answers = NULL; enum return_type results; char options[500] = "options "; diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c index b4c16eec6..d469cbe31 100644 --- a/mdk-stage1/network.c +++ b/mdk-stage1/network.c @@ -336,9 +336,9 @@ static enum return_type setup_network_interface(struct interface_info * intf) return results; if (!strcmp(choice, "Static")) { - char * questions[] = { "IP of this machine", "IP of Domain Name Server", "IP of default gateway", "Netmask", NULL }; + char * questions[] = { "IP of this machine", "IP of DNS", "IP of default gateway", "Netmask", NULL }; char * questions_auto[] = { "ip", "dns", "gateway", "netmask" }; - char ** answers; + static char ** answers = NULL; struct in_addr addr; results = ask_from_entries_auto("Please enter the network information. (leave netmask void for Internet standard)", @@ -399,46 +399,64 @@ static enum return_type setup_network_interface(struct interface_info * intf) return add_default_route(); } -/* + static enum return_type configure_network(struct interface_info * intf) { char ips[50]; char * name; - wait_message("Trying to guess hostname and domain..."); + wait_message("Trying to resolve hostname..."); strcpy(ips, inet_ntoa(intf->ip)); name = mygethostbyaddr(ips); remove_wait_message(); - if (!name) { + if (name) { + hostname = strdup(name); + domain = strchr(strdup(name), '.') + 1; + log_message("got hostname and domain from dns entry, %s and %s", hostname, domain); + return RETURN_OK; + } + + log_message("reverse name lookup on self failed"); + + if (domain != NULL) + return RETURN_OK; + + if (dns_server.s_addr != 0) { + wait_message("Trying to resolve dns..."); + strcpy(ips, inet_ntoa(dns_server)); + name = mygethostbyaddr(ips); + remove_wait_message(); + } + + if (name) { + domain = strchr(strdup(name), '.') + 1; + log_message("got domain from DNS fullname, %s", domain); + } else { enum return_type results; char * questions[] = { "Host name", "Domain name", NULL }; char * questions_auto[] = { "hostname", "domain" }; - char ** answers; + static char ** answers = NULL; char * boulet; - - log_message("reverse name lookup on self failed"); - + + log_message("reverse name lookup on DNS failed"); + results = ask_from_entries_auto("I could not guess hostname and domain name; please fill in this information. " - "Valid answers are for example: `mybox' for hostname and `mynetwork.com' for domain name, " - "for a machine called `mybox.mynetwork.com' on the Internet.", + "Valid answers are for example: `mybox' for hostname and `mynetwork.com' for " + "domain name, for a machine called `mybox.mynetwork.com' on the Internet.", questions, &answers, 32, questions_auto); if (results != RETURN_OK) return results; - + hostname = answers[0]; if ((boulet = strchr(hostname, '.')) != NULL) boulet[0] = '\0'; domain = answers[1]; } - else { - hostname = strdup(name); - domain = strchr(strdup(name), '.') + 1; - } return RETURN_OK; } -*/ + static enum return_type bringup_networking(struct interface_info * intf) { @@ -450,15 +468,15 @@ static enum return_type bringup_networking(struct interface_info * intf) // if (intf->is_up == 1) // log_message("interface already up (with IP %s)", inet_ntoa(intf->ip)); -// while (results != RETURN_OK) { + while (results != RETURN_OK) { results = setup_network_interface(intf); if (results != RETURN_OK) return results; write_resolvconf(); -// results = configure_network(intf); -// } + results = configure_network(intf); + } -// write_resolvconf(); /* maybe we have now domain to write also */ + write_resolvconf(); /* maybe we have now domain to write also */ if (loopback.is_up == 0) { int rc; @@ -554,7 +572,7 @@ enum return_type nfs_prepare(void) { char * questions[] = { "NFS server name", DISTRIB_NAME " directory", NULL }; char * questions_auto[] = { "server", "directory", NULL }; - char ** answers; + static char ** answers = NULL; char * nfsmount_location; enum return_type results = intf_select_and_up(); @@ -608,7 +626,7 @@ enum return_type ftp_prepare(void) { char * questions[] = { "FTP server", DISTRIB_NAME " directory", "Login", "Password", NULL }; char * questions_auto[] = { "server", "directory", "user", "pass", NULL }; - char ** answers; + static char ** answers = NULL; enum return_type results; if (!ramdisk_possible()) { @@ -692,7 +710,7 @@ enum return_type http_prepare(void) { char * questions[] = { "HTTP server", DISTRIB_NAME " directory", NULL }; char * questions_auto[] = { "server", "directory", NULL }; - char ** answers; + static char ** answers = NULL; enum return_type results; if (!ramdisk_possible()) { diff --git a/mdk-stage1/newt-frontend.c b/mdk-stage1/newt-frontend.c index 494751d90..6d55c9ab7 100644 --- a/mdk-stage1/newt-frontend.c +++ b/mdk-stage1/newt-frontend.c @@ -242,6 +242,7 @@ enum return_type ask_from_entries(char *msg, char ** questions, char *** answers struct newtWinEntry entries[50]; int j, i = 0; int rc; + char ** already_answers = NULL; while (questions && *questions) { entries[i].text = *questions; @@ -252,11 +253,18 @@ enum return_type ask_from_entries(char *msg, char ** questions, char *** answers entries[i].text = NULL; entries[i].value = NULL; - *answers = (char **) malloc(sizeof(char *) * i); + if (*answers == NULL) + *answers = (char **) malloc(sizeof(char *) * i); + else + already_answers = *answers; for (j = 0 ; j < i ; j++) { entries[j].value = &((*answers)[j]); - *(entries[j].value) = NULL; + if (already_answers && *already_answers) { + *(entries[j].value) = *already_answers; + already_answers++; + } else + *(entries[j].value) = NULL; } rc = newtWinEntries("Please fill entries...", msg, 52, 5, 5, entry_size, entries, "Ok", "Cancel", NULL); diff --git a/mdk-stage1/stage1.c b/mdk-stage1/stage1.c index 01316fee0..2332c8c2d 100644 --- a/mdk-stage1/stage1.c +++ b/mdk-stage1/stage1.c @@ -126,7 +126,7 @@ static void expert_third_party_modules(void) char * choice; int rc; char * questions[] = { "Options", NULL }; - char ** answers; + static char ** answers = NULL; results = ask_yes_no("If you want to insert third-party kernel modules, insert " "a Linux (ext2fs) formatted floppy containing the modules and confirm. Otherwise, select \"no\".");; diff --git a/mdk-stage1/stdio-frontend.c b/mdk-stage1/stdio-frontend.c index 85b8c94ad..0eac0e173 100644 --- a/mdk-stage1/stdio-frontend.c +++ b/mdk-stage1/stdio-frontend.c @@ -24,6 +24,8 @@ #include <stdio.h> #include <stdarg.h> #include <fcntl.h> +#include <sys/ioctl.h> +#include <termios.h> #include "stage1.h" #include "log.h" #include "newt.h" @@ -44,6 +46,7 @@ void finish_frontend(void) static void get_any_response(void) { unsigned char t; + printf("> Press <enter> to proceed."); fflush(stdout); read(0, &t, 1); fcntl(0, F_SETFL, O_NONBLOCK); @@ -67,17 +70,60 @@ static int get_int_response(void) return j; } -static char * get_string_response(void) +static char * get_string_response(char * initial_string) { - /* I won't use a scanf/%s since I also want the null string to be accepted */ + /* I won't use a scanf/%s since I also want the null string to be accepted -- also, I want the initial_string */ char s[50]; int i = 0; + struct termios t; + + if (initial_string) { + printf(initial_string); + strcpy(s, initial_string); + i = strlen(s); + } + + /* from ncurses/tinfo/lib_raw.c:(cbreak) */ + tcgetattr(0, &t); + t.c_lflag &= ~ICANON; + t.c_lflag |= ISIG; + t.c_lflag &= ~ECHO; + t.c_iflag &= ~ICRNL; + t.c_cc[VMIN] = 1; + t.c_cc[VTIME] = 0; + tcsetattr(0, TCSADRAIN, &t); + fflush(stdout); - read(0, &(s[i++]), 1); + fcntl(0, F_SETFL, O_NONBLOCK); - while (read(0, &(s[i++]), 1) > 0 && i < sizeof(s)); + + while (1) { + if (read(0, &(s[i]), 1) > 0) { + if (s[i] == 13) + break; + if (s[i] == 127) { + if (i > 0) { + printf("\033[D"); + printf(" "); + printf("\033[D"); + i--; + } + } else { + printf("%c", s[i]); + i++; + } + } + } + + t.c_lflag |= ICANON; + t.c_lflag |= ECHO; + t.c_iflag |= ICRNL; + tcsetattr(0, TCSADRAIN, &t); + fcntl(0, F_SETFL, 0); - s[i-2] = '\0'; + + printf("\n"); + s[i] = '\0'; return strdup(s); } @@ -86,7 +132,6 @@ static void blocking_msg(char *type, char *fmt, va_list args) printf(type); vprintf(fmt, args); get_any_response(); -// printf("\n"); } void error_message(char *msg, ...) @@ -245,6 +290,7 @@ enum return_type ask_yes_no(char *msg) enum return_type ask_from_entries(char *msg, char ** questions, char *** answers, int entry_size) { int j, i = 0; + char ** already_answers = NULL; printf("> %s\n", msg); @@ -254,13 +300,21 @@ enum return_type ask_from_entries(char *msg, char ** questions, char *** answers questions++; } - *answers = (char **) malloc(sizeof(char *) * i); + if (*answers == NULL) + *answers = (char **) malloc(sizeof(char *) * i); + else + already_answers = *answers; while (1) { int r; for (j = 0 ; j < i ; j++) { printf("(%c) ? ", j + 'a'); - (*answers)[j] = get_string_response(); + if (already_answers && *already_answers) { + (*answers)[j] = get_string_response(*already_answers); + already_answers++; + } else + (*answers)[j] = get_string_response(NULL); + } printf("(0) Cancel (1) Accept (2) Re-enter answers\n? "); r = get_int_response(); diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index db4b847e9..84c53a2d6 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -347,7 +347,7 @@ void add_to_env(char * name, char * value) char ** list_directory(char * direct) { - char * tmp[500]; + char * tmp[50000]; /* in /dev there can be many many files.. */ int i = 0; struct dirent *ep; DIR *dp = opendir(direct); |