summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Ginies <aginies@mandriva.com>2004-10-13 06:39:38 +0000
committerAntoine Ginies <aginies@mandriva.com>2004-10-13 06:39:38 +0000
commit536f4e80aa75e99ba38e9f3037f169336ad10f61 (patch)
tree763ce5183ecbe1f05b1feb5a6680b480973aab11
parent6cc57924776dd164351f363ba48f4c453792ba62 (diff)
downloaddrakx-backup-do-not-use-536f4e80aa75e99ba38e9f3037f169336ad10f61.tar
drakx-backup-do-not-use-536f4e80aa75e99ba38e9f3037f169336ad10f61.tar.gz
drakx-backup-do-not-use-536f4e80aa75e99ba38e9f3037f169336ad10f61.tar.bz2
drakx-backup-do-not-use-536f4e80aa75e99ba38e9f3037f169336ad10f61.tar.xz
drakx-backup-do-not-use-536f4e80aa75e99ba38e9f3037f169336ad10f61.zip
add new installation method (ka)
-rw-r--r--mdk-stage1/network.c89
-rw-r--r--mdk-stage1/network.h2
-rw-r--r--mdk-stage1/stage1.c7
-rw-r--r--mdk-stage1/stage1.h1
-rw-r--r--mdk-stage1/tools.c5
-rw-r--r--mdk-stage1/tools.h1
-rw-r--r--mdk-stage1/url.c80
-rw-r--r--mdk-stage1/url.h6
8 files changed, 187 insertions, 4 deletions
diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c
index 13085cfcc..3e6039494 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"
@@ -85,7 +86,7 @@ int configure_net_device(struct interface_info * intf)
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
log_perror("socket");
- error_message_net();
+ error_message_net();
return 1;
}
@@ -187,6 +188,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)
{
@@ -888,3 +890,88 @@ 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; }
+ else {
+ 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;
+ }
+
+ if (dp) {
+ 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);
+ return RETURN_OK;
+
+ // 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;
+}
diff --git a/mdk-stage1/network.h b/mdk-stage1/network.h
index 02eea45b6..6c72146c8 100644
--- a/mdk-stage1/network.h
+++ b/mdk-stage1/network.h
@@ -30,6 +30,8 @@
enum return_type nfs_prepare(void);
enum return_type ftp_prepare(void);
enum return_type http_prepare(void);
+enum return_type ka_prepare(void);
+enum return_type ka_wait_for_stage2(void);
enum boot_proto_type { BOOTPROTO_STATIC, BOOTPROTO_DHCP, BOOTPROTO_ADSL_PPPOE };
diff --git a/mdk-stage1/stage1.c b/mdk-stage1/stage1.c
index 03f809cd8..7977a95d2 100644
--- a/mdk-stage1/stage1.c
+++ b/mdk-stage1/stage1.c
@@ -315,6 +315,8 @@ static void method_select_and_prepare(void)
char * network_nfs_install = "NFS server"; char * network_nfs_install_auto = "nfs";
char * network_ftp_install = "FTP server"; char * network_ftp_install_auto = "ftp";
char * network_http_install = "HTTP server"; char * network_http_install_auto = "http";
+ char * network_ka_install = "KA server"; char * network_ka_install_auto = "ka";
+
#endif
i = 0;
@@ -322,6 +324,7 @@ static void method_select_and_prepare(void)
means[i] = network_nfs_install; means_auto[i++] = network_nfs_install_auto;
means[i] = network_ftp_install; means_auto[i++] = network_ftp_install_auto;
means[i] = network_http_install; means_auto[i++] = network_http_install_auto;
+ means[i] = network_ka_install; means_auto[i++] = network_ka_install_auto;
#endif
#ifndef DISABLE_CDROM
means[i] = cdrom_install; means_auto[i++] = cdrom_install_auto;
@@ -352,6 +355,9 @@ static void method_select_and_prepare(void)
if (!strcmp(choice, network_nfs_install))
results = nfs_prepare();
+ if (!strcmp(choice, network_ka_install))
+ results = ka_prepare();
+
if (!strcmp(choice, network_ftp_install))
results = ftp_prepare();
@@ -361,6 +367,7 @@ static void method_select_and_prepare(void)
if (results != RETURN_OK)
return method_select_and_prepare();
+
}
#ifdef MANDRAKE_MOVE
diff --git a/mdk-stage1/stage1.h b/mdk-stage1/stage1.h
index 926f84151..94f9c6bfc 100644
--- a/mdk-stage1/stage1.h
+++ b/mdk-stage1/stage1.h
@@ -44,6 +44,7 @@ extern char * stage2_kickstart;
#define MODE_NOAUTO (1 << 12)
#define MODE_NETAUTO (1 << 13)
#define MODE_RECOVERY (1 << 14)
+#define KA_MAX_RETRY 5
#define IS_TESTING (get_param(MODE_TESTING))
#define IS_EXPERT (get_param(MODE_EXPERT))
diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c
index dbbd45772..59d4a1ddf 100644
--- a/mdk-stage1/tools.c
+++ b/mdk-stage1/tools.c
@@ -228,7 +228,8 @@ int ramdisk_possible(void)
}
-enum return_type copy_file(char * from, char * to, void (*callback_func)(int overall))
+
+ enum return_type copy_file(char * from, char * to, void (*callback_func)(int overall))
{
FILE * f_from, * f_to;
size_t quantity __attribute__((aligned(16))), overall = 0;
@@ -276,7 +277,7 @@ enum return_type copy_file(char * from, char * to, void (*callback_func)(int ove
return ret;
}
-static void save_stuff_for_rescue(void)
+void save_stuff_for_rescue(void)
{
copy_file("/etc/resolv.conf", STAGE2_LOCATION "/etc/resolv.conf", NULL);
}
diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h
index 3b95a2f26..d5668c4d0 100644
--- a/mdk-stage1/tools.h
+++ b/mdk-stage1/tools.h
@@ -47,6 +47,7 @@ char * floppy_device(void);
char * asprintf_(const char *msg, ...);
int scall_(int retval, char * msg, char * file, int line);
#define scall(retval, msg) scall_(retval, msg, __FILE__, __LINE__)
+void save_stuff_for_rescue(void);
struct param_elem
{
diff --git a/mdk-stage1/url.c b/mdk-stage1/url.c
index 0c4dbbedf..6b48c3c9b 100644
--- a/mdk-stage1/url.c
+++ b/mdk-stage1/url.c
@@ -37,6 +37,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <sys/poll.h>
+#include <sys/mount.h>
#include <netinet/in.h>
#include <netinet/ip.h>
@@ -47,11 +48,14 @@
#include "tools.h"
#include "url.h"
+#include "mount.h"
+#include <sys/wait.h>
#define TIMEOUT_SECS 60
#define BUFFER_SIZE 4096
+void my_pause(void) { unsigned char t; fflush(stdout); read(0, &t, 1); }
static int ftp_check_response(int sock, char ** str)
{
@@ -509,6 +513,80 @@ int http_download_file(char * hostname, char * remotename, int * size, char * pr
*size = charstar_to_int(buf + strlen(header_content_length));
else
*size = 0;
-
return sock;
}
+
+enum return_type ka_wait_for_stage2(void)
+{
+ char * ramdisk = "/dev/ram3"; /* warning, verify that this file exists in the initrd*/
+ char * ka_launch[] = { "/ka/ka-d-client", "-w","-s","getstage2","-e","(cd /tmp/stage2; tar --extract --read-full-records --same-permissions --numeric-owner --sparse --file - )", NULL }; /* The command line for ka_launch */
+ char * mkfs_launch[] = { "/sbin/mke2fs", ramdisk, NULL}; /* The mkfs command for formating the ramdisk */
+
+
+ log_message("KA: Preparing to receive stage 2....");
+ int pida, wait_status;
+
+ if (!(pida = fork())) { /* Forking current process for running mkfs */
+ close(1);
+ close(2);
+ execve(mkfs_launch[0], mkfs_launch,grab_env()); /* Formating the ramdisk */
+ printf("KA: Can't execute %s\n<press Enter>\n", mkfs_launch[0]);
+ my_pause();
+ return KAERR_CANTFORK;
+ }
+ while (wait4(-1, &wait_status, 0, NULL) != pida) {}; /* Waiting the end of mkfs */
+
+ if (my_mount(ramdisk, STAGE2_LOCATION, "ext2", 1)) {/* Trying to mount the ramdisk */
+ return RETURN_ERROR;
+ }
+
+ log_message("KA: Waiting for stage 2....");
+ wait_message("Waiting for rescue from KA server");
+ pid_t pid; /* Process ID of the child process */
+ pid_t wpid; /* Process ID from wait() */
+ int status; /* Exit status from wait() */
+
+ pid = fork();
+ if ( pid == -1 ) {
+ fprintf(stderr, "%s: Failed to fork()\n", strerror(errno));
+ exit(13);
+ } else if ( pid == 0 ) {
+ execve(ka_launch[0], ka_launch, grab_env());
+ } else {
+ // wpid = wait(&status); /* Child's exit status */
+ wpid = wait4(-1, &status, 0, NULL);
+ if ( wpid == -1 ) {
+ fprintf(stderr,"%s: wait()\n", strerror(errno));
+ return RETURN_ERROR;
+ } else if ( wpid != pid )
+ abort();
+ else {
+ if ( WIFEXITED(status) ) {
+ printf("Exited: $? = %d\n", WEXITSTATUS(status));
+ } else if ( WIFSIGNALED(status) ) {
+ printf("Signal: %d%s\n", WTERMSIG(status), WCOREDUMP(status) ? " with core file." : "");
+ }
+ }
+
+ }
+
+ remove_wait_message();
+ return RETURN_OK;
+ // if (!(pid = fork())) { /* Froking current process for running ka-deploy (client side) */
+ // close(1); /* Closing stdout */
+ // close(2); /* Closing stderr */
+ // execve(ka_launch[0], ka_launch,grab_env()); /* Running ka-deploy (client side) */
+ // printf("KA: Can't execute %s\n<press Enter>\n", ka_launch[0]);
+ // log_message("KA: Can't execute %s\n<press Enter>\n", ka_launch[0]);
+ // my_pause();
+ // return KAERR_CANTFORK;
+ //}
+
+ //while (wait4(-1, &wait_status, 0, NULL) != pid) {}; /* Waiting the end of duplication */
+ // log_message("kalaunch ret %d\n", WIFEXITED(wait_status));
+ // remove_wait_message();
+ //sleep(100000);
+ // return RETURN_OK;
+}
+
+
diff --git a/mdk-stage1/url.h b/mdk-stage1/url.h
index d4f7f3992..5441ca40b 100644
--- a/mdk-stage1/url.h
+++ b/mdk-stage1/url.h
@@ -19,6 +19,10 @@
*
*/
+#include "wait.h"
+#include "config-stage1.h"
+#include "frontend.h"
+
#ifndef _URL_H_
#define _URL_H_
@@ -40,5 +44,7 @@ int http_download_file(char * hostname, char * remotename, int * size, char * pr
#define FTPERR_FAILED_DATA_CONNECT -9
#define FTPERR_FILE_NOT_FOUND -10
#define FTPERR_UNKNOWN -100
+#define KAERR_CANTFORK -20
+
#endif