diff options
Diffstat (limited to 'mdk-stage1/url.c')
-rw-r--r-- | mdk-stage1/url.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/mdk-stage1/url.c b/mdk-stage1/url.c index ada5696cd..fb6c5de74 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 my_pause(void) { unsigned char t; fflush(stdout); read(0, &t, 1); } + static int ftp_check_response(int sock, char ** str) { @@ -499,3 +505,42 @@ 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/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 pid,wait_status; + + if (!(pid = 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) != pid) {}; /* 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"); + 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]); + my_pause(); + return KAERR_CANTFORK; + } + while (wait4(-1, &wait_status, 0, NULL) != pid) {}; /* Waiting the end of duplication */ + remove_wait_message(); + + return RETURN_OK; +} |