diff options
Diffstat (limited to 'mdk-stage1/network.c')
-rw-r--r-- | mdk-stage1/network.c | 89 |
1 files changed, 87 insertions, 2 deletions
diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c index ef9dd2814..3270c5593 100644 --- a/mdk-stage1/network.c +++ b/mdk-stage1/network.c @@ -31,6 +31,7 @@ #include <stdio.h> #include <netdb.h> #include <resolv.h> +#include <dirent.h> #include "stage1.h" #include "frontend.h" @@ -46,7 +47,6 @@ #include "network.h" - static void error_message_net(void) /* reduce code size */ { stg1_error_message("Could not configure network."); @@ -187,6 +187,7 @@ char * domain = NULL; struct in_addr gateway = { 0 }; struct in_addr dns_server = { 0 }; struct in_addr dns_server2 = { 0 }; +struct in_addr next_server = { 0 }; static int add_default_route(void) { @@ -823,7 +824,7 @@ enum return_type http_prepare(void) return RETURN_ERROR; method_name = strdup("http"); - sprintf(location_full, "http://%s%s", answers[0], answers[1]); + sprintf(location_full, "http://%s/%s", answers[0], answers[1]); add_to_env("URLPREFIX", location_full); } while (results == RETURN_BACK); @@ -831,3 +832,87 @@ enum return_type http_prepare(void) return RETURN_OK; } + +enum return_type ka_prepare(void) +{ + int server_failure=1; /* Number of time we've failed to find a ka server */ + + enum return_type results; + + if (!ramdisk_possible()) { + stg1_error_message("KA install needs more than %d Mbytes of memory (detected %d Mbytes).", + MEM_LIMIT_RAMDISK, total_memory()); + return RETURN_ERROR; + } + + results = intf_select_and_up(); + + if (results != RETURN_OK) + return results; + + FILE *f = fopen ("/ka/tftpserver","w"); + if (f != NULL) + { fprintf(f,"%s\n",inet_ntoa(next_server)); /* Writing the NEXT_SERVER value of the DHCP Request in the /ka/tftpserver file */ + fclose(f); + } + + log_message("KA: Trying to retrieve stage2 from server"); + do { + results=ka_wait_for_stage2(); /* We are trying to get a valid stage 2 (rescue) */ + if (results != RETURN_OK) + return results; + + char dir[255] = STAGE2_LOCATION; + strcat(dir,"/ka"); + DIR *dp = opendir(dir); /* Trying to open STAGE2_LOCATION/ka directory */ + + if (! dp) { /* Does the STAGE2_LOCATION/ka directory exists ? = Does the rescue with ka well downloaded ?*/ + log_message("KA: Server not found !"); + if (umount (STAGE2_LOCATION)) { /* Be sure that the STAGE2_LOCATION isn't mounted after receiving a wrong rescue */ + log_perror("KA: Unable to umount STAGE2"); + } + int cpt; + + if (server_failure++ == KA_MAX_RETRY){ /* if the KA server can't be reach KA_MAX_RETRY times */ + char * reboot_launch[] = { "/sbin/reboot", NULL}; + for (cpt=5; cpt>0; cpt--) { + wait_message("!!! Can t reach a valid KA server !!! (Rebooting in %d sec)",cpt); + sleep (1); + } + execve(reboot_launch[0], reboot_launch, grab_env()); /* Rebooting the computer to avoid infinite loop on ka mode */ + } + + for (cpt=5; cpt>0; cpt--) { + wait_message("KA server not found ! (Try %d/%d in %d sec)",server_failure,KA_MAX_RETRY,cpt); + sleep (1); + } + remove_wait_message(); + results=RETURN_BACK; /* We should try another time*/ + continue; + } + else{ + log_message("KA: Stage 2 downloaded successfully"); + closedir(dp); /* Closing the /ka directory */ + server_failure=1; /* Resetting server_failure */ + results=RETURN_OK; + } + + log_message("KA: Preparing chroot"); + + set_param(MODE_RAMDISK); + + if (IS_RESCUE) { /* if we are in rescue mode */ + save_stuff_for_rescue(); /* Saving resolve.conf */ + if (umount (STAGE2_LOCATION)) { /* Unmounting STAGE2 elseif kernel can't mount it ! */ + log_perror("KA: Unable to umount STAGE2"); + return RETURN_ERROR; + } + } + } while (results == RETURN_BACK); + + + method_name = strdup("ka"); + + return RETURN_OK; +} + |