summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErwan Velu <erwan@mandriva.org>2002-10-31 15:58:02 +0000
committerErwan Velu <erwan@mandriva.org>2002-10-31 15:58:02 +0000
commit60057d8e5e333659cfc2cf0f29c7fd48a5bd5981 (patch)
treedd7f7178623c7d73b62946c8fdf28aab87df25ef
parent8785f12640289bff4b9c34e11c5fd961afdd0adc (diff)
downloaddrakx-60057d8e5e333659cfc2cf0f29c7fd48a5bd5981.tar
drakx-60057d8e5e333659cfc2cf0f29c7fd48a5bd5981.tar.gz
drakx-60057d8e5e333659cfc2cf0f29c7fd48a5bd5981.tar.bz2
drakx-60057d8e5e333659cfc2cf0f29c7fd48a5bd5981.tar.xz
drakx-60057d8e5e333659cfc2cf0f29c7fd48a5bd5981.zip
Including ka-deploy for stage 2
-rw-r--r--mdk-stage1/network.c23
-rw-r--r--mdk-stage1/stage1.c36
-rw-r--r--mdk-stage1/tools.c2
-rw-r--r--mdk-stage1/tools.h3
-rw-r--r--mdk-stage1/url.c44
-rw-r--r--mdk-stage1/url.h5
6 files changed, 84 insertions, 29 deletions
diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c
index d4517883d..5852ffa6f 100644
--- a/mdk-stage1/network.c
+++ b/mdk-stage1/network.c
@@ -837,7 +837,19 @@ enum return_type http_prepare(void)
enum return_type ka_prepare(void)
{
kadeploy=1; /* We are in a ka deploy mode*/
- enum return_type results = intf_select_and_up();
+
+ 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)
@@ -845,10 +857,15 @@ enum return_type ka_prepare(void)
fclose(f);
}
- if (results != RETURN_OK)
- return results;
+ log_message("KA: Trying to retrieve stage2 from server");
+ results=ka_wait_for_stage2();
+
+ if (results != RETURN_OK)
+ return results;
+
method_name = strdup("ka");
+
return RETURN_OK;
}
diff --git a/mdk-stage1/stage1.c b/mdk-stage1/stage1.c
index d47cdf316..6a0efb9a1 100644
--- a/mdk-stage1/stage1.c
+++ b/mdk-stage1/stage1.c
@@ -446,27 +446,21 @@ int main(int argc __attribute__ ((unused)), char **argv __attribute__ ((unused))
return 0;
argptr = stage2_args;
- if ( kadeploy == 0) {
- *argptr++ = "/usr/bin/runinstall2";
- *argptr++ = "--method";
- *argptr++ = method_name;
- #ifdef ENABLE_PCMCIA
- if (pcmcia_adapter) {
- *argptr++ = "--pcmcia";
- *argptr++ = pcmcia_adapter;
- }
- #endif
- if (disable_modules)
- *argptr++ = "--blank";
- if (stage2_kickstart) {
- *argptr++ = "--kickstart";
- *argptr++ = stage2_kickstart;
- }
- }
-else {
- *argptr++ = "/etc/rc.sysinit";
-}
-
+ *argptr++ = "/usr/bin/runinstall2";
+ *argptr++ = "--method";
+ *argptr++ = method_name;
+#ifdef ENABLE_PCMCIA
+ if (pcmcia_adapter) {
+ *argptr++ = "--pcmcia";
+ *argptr++ = pcmcia_adapter;
+ }
+#endif
+ if (disable_modules)
+ *argptr++ = "--blank";
+ if (stage2_kickstart) {
+ *argptr++ = "--kickstart";
+ *argptr++ = stage2_kickstart;
+ }
*argptr++ = NULL;
execve(stage2_args[0], stage2_args, grab_env());
diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c
index a921883a8..0df0cd31b 100644
--- a/mdk-stage1/tools.c
+++ b/mdk-stage1/tools.c
@@ -214,7 +214,7 @@ int ramdisk_possible(void)
}
-static void save_stuff_for_rescue(void)
+void save_stuff_for_rescue(void)
{
void save_this_file(char * file) {
char buf[5000];
diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h
index e168ebe9f..e944f9621 100644
--- a/mdk-stage1/tools.h
+++ b/mdk-stage1/tools.h
@@ -40,7 +40,8 @@ void handle_env(char ** env);
char ** grab_env(void);
char ** list_directory(char * direct);
int string_array_length(char ** a);
-
+void save_stuff_for_rescue(void);
+
struct param_elem
{
char * name;
diff --git a/mdk-stage1/url.c b/mdk-stage1/url.c
index ada5696cd..2061264cb 100644
--- a/mdk-stage1/url.c
+++ b/mdk-stage1/url.c
@@ -35,8 +35,10 @@
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
+#include <sys/mount.h>
#include <unistd.h>
#include <sys/poll.h>
+#include <sys/wait.h>
#include <netinet/in.h>
#include <netinet/ip.h>
@@ -47,11 +49,15 @@
#include "tools.h"
#include "url.h"
-
+#include "config-stage1.h"
+#include "stage1.h"
+#include "mount.h"
#define TIMEOUT_SECS 60
#define BUFFER_SIZE 4096
+void pause(void) { unsigned char t; fflush(stdout); read(0, &t, 1); }
+
static int ftp_check_response(int sock, char ** str)
{
@@ -499,3 +505,39 @@ int http_download_file(char * hostname, char * remotename, int * size)
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/getStage2.sh", ramdisk, IMAGE_LOCATION, NULL };
+
+ log_message("KA: Waiting for stage 2....");
+
+ log_message("KA: Launching %s",ka_launch[0]);
+
+ int pid,wait_status;
+
+ if (!(pid = fork())) {
+ execve(ka_launch[0], ka_launch,grab_env());
+ printf("KA: Can't execute %s\n<press Enter>\n", ka_launch[0]);
+ pause();
+ return KAERR_CANTFORK;
+ }
+ while (wait4(-1, &wait_status, 0, NULL) != pid) {};
+
+ log_message("KA: Stage 2 downloaded successfully");
+
+ log_message("KA: Preparing chroot");
+
+ set_param(MODE_RAMDISK);
+
+ if (IS_RESCUE) {
+ save_stuff_for_rescue();
+ if (umount (IMAGE_LOCATION)) {
+ log_perror("KA: Unable to umount STAGE2");
+ return RETURN_ERROR;
+ }
+ }
+
+
+ return RETURN_OK;
+}
diff --git a/mdk-stage1/url.h b/mdk-stage1/url.h
index 5a59bd814..6789ef43f 100644
--- a/mdk-stage1/url.h
+++ b/mdk-stage1/url.h
@@ -21,13 +21,14 @@
#ifndef _URL_H_
#define _URL_H_
+#include "frontend.h"
int ftp_open_connection(char * host, char * name, char * password, char * proxy);
int ftp_start_download(int sock, char * remotename, int * size);
int ftp_end_data_command(int sock);
int http_download_file(char * hostname, char * remotename, int * size);
-
+enum return_type ka_wait_for_stage2(void);
#define FTPERR_BAD_SERVER_RESPONSE -1
#define FTPERR_SERVER_IO_ERROR -2
@@ -40,5 +41,5 @@ int http_download_file(char * hostname, char * remotename, int * size);
#define FTPERR_FAILED_DATA_CONNECT -9
#define FTPERR_FILE_NOT_FOUND -10
#define FTPERR_UNKNOWN -100
-
+#define KAERR_CANTFORK -20
#endif