From 92460f66390ef105485b40c4dd8e98e2e2d60163 Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Fri, 31 Oct 2003 16:13:14 +0000 Subject: save /etc/resolv.conf in move mode --- mdk-stage1/stage1.c | 47 ++++++++------------------------ mdk-stage1/tools.c | 78 ++++++++++++++++++++++++++++++++++------------------- mdk-stage1/tools.h | 1 + 3 files changed, 62 insertions(+), 64 deletions(-) (limited to 'mdk-stage1') diff --git a/mdk-stage1/stage1.c b/mdk-stage1/stage1.c index 876c40867..88d4eaf6a 100644 --- a/mdk-stage1/stage1.c +++ b/mdk-stage1/stage1.c @@ -424,6 +424,7 @@ int mandrake_move_post(void) char* clp = IMAGE_LOCATION "/live_tree_boot.clp"; char* clp_tmpfs = SLASH_LOCATION "/live_tree_boot.clp"; char* live = IMAGE_LOCATION "/live_tree_boot/usr/bin/runstage2.pl"; + int ret; if (IS_LIVE || access(clp, R_OK)) { log_message("no %s found (or disabled), trying to fallback on plain tree", clp); @@ -438,42 +439,13 @@ int mandrake_move_post(void) } } - { - FILE * from, * to; - size_t quantity __attribute__((aligned(16))), overall = 0; - char buf[4096] __attribute__((aligned(4096))); - - log_message("move: copying live_tree_boot.clp to tmpfs"); - if (scall(!(from = fopen(clp, "rb")), "fopen")) - return RETURN_ERROR; - if (scall(!(to = fopen(clp_tmpfs, "w")), "fopen")) - return RETURN_ERROR; - - init_progression("Loading startup program into memory...", file_size(clp)); - - do { - if ((quantity = fread(buf, 1, sizeof(buf), from)) > 0) { - if (fwrite(buf, 1, quantity, to) != quantity) { - log_message("short write (%s)", strerror(errno)); - return RETURN_ERROR; - } - } - overall += quantity; - update_progression(overall); - } while (!feof(from) && !ferror(from) && !ferror(to)); - - end_progression(); - - if (ferror(from) || ferror(to)) { - log_message("an error occured while copying live_tree_boot.clp (%s)", strerror(errno)); - return RETURN_ERROR; - } - fclose(from); - fclose(to); - - if (lomount(clp_tmpfs, BOOT_LOCATION, NULL, 1)) - stg1_error_message("Could not mount boot compressed loopback :(."); - } + init_progression("Loading startup program into memory...", file_size(clp)); + ret = copy_file(clp, clp_tmpfs, update_progression); + end_progression(); + if (ret != RETURN_OK) + return ret; + if (lomount(clp_tmpfs, BOOT_LOCATION, NULL, 1)) + stg1_error_message("Could not mount boot compressed loopback :(."); handle_clps: if (handle_clp(IMAGE_LOCATION "/live_tree_always.clp", IMAGE_LOCATION "/live_tree_always/bin/bash", @@ -537,6 +509,9 @@ int mandrake_move_post(void) return RETURN_ERROR; } + mkdir(SLASH_LOCATION "/etc", 0755); + copy_file("/etc/resolv.conf", SLASH_LOCATION "/etc/resolv.conf", NULL); + if (IS_DEBUGSTAGE1) while (1); diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index 7a2c0480f..c16694744 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "stage1.h" #include "log.h" #include "mount.h" @@ -224,37 +225,58 @@ int ramdisk_possible(void) } -static void save_stuff_for_rescue(void) +enum return_type copy_file(char * from, char * to, void (*callback_func)(int overall)) { - void save_this_file(char * file) { - char buf[5000]; - int fd_r, fd_w, i; - char location[100]; - - if ((fd_r = open(file, O_RDONLY)) < 0) { - log_message("can't open %s for read", file); - return; - } - strcpy(location, STAGE2_LOCATION); - strcat(location, file); - if ((fd_w = open(location, O_WRONLY)) < 0) { - log_message("can't open %s for write", location); - close(fd_r); - return; - } - if ((i = read(fd_r, buf, sizeof(buf))) <= 0) { - log_message("can't read from %s", file); - close(fd_r); close(fd_w); - return; - } - if (write(fd_w, buf, i) != i) - log_message("can't write %d bytes to %s", i, location); - close(fd_r); close(fd_w); - log_message("saved file %s for rescue (%d bytes)", file, i); - } - save_this_file("/etc/resolv.conf"); + FILE * f_from, * f_to; + size_t quantity __attribute__((aligned(16))), overall = 0; + char buf[4096] __attribute__((aligned(4096))); + int ret = RETURN_ERROR; + + log_message("copy_file: %s -> %s", from, to); + + if (!(f_from = fopen(from, "rb"))) { + log_perror(from); + return RETURN_ERROR; + } + + if (!(f_to = fopen(to, "w"))) { + log_perror(to); + goto close_from; + return RETURN_ERROR; + } + + do { + if ((quantity = fread(buf, 1, sizeof(buf), f_from)) > 0) { + if (fwrite(buf, 1, quantity, f_to) != quantity) { + log_message("short write (%s)", strerror(errno)); + goto cleanup; + } + } + if (callback_func) { + overall += quantity; + callback_func(overall); + } + } while (!feof(f_from) && !ferror(f_from) && !ferror(f_to)); + + if (ferror(f_from) || ferror(f_to)) { + log_message("an error occured: %s", strerror(errno)); + goto cleanup; + } + + ret = RETURN_OK; + + cleanup: + fclose(f_to); + close_from: + fclose(f_from); + + return ret; } +static void save_stuff_for_rescue(void) +{ + copy_file("/etc/resolv.conf", STAGE2_LOCATION "/resolv.conf", NULL); +} enum return_type load_ramdisk_fd(int ramdisk_fd, int size) { diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h index 29bfc5f62..851480d2d 100644 --- a/mdk-stage1/tools.h +++ b/mdk-stage1/tools.h @@ -33,6 +33,7 @@ off_t file_size(const char * path); int total_memory(void); int ramdisk_possible(void); char * get_ramdisk_realname(void); +enum return_type copy_file(char * from, char * to, void (*callback_func)(int overall)); enum return_type load_ramdisk(void); enum return_type load_ramdisk_fd(int ramdisk_fd, int size); void * memdup(void *src, size_t size); -- cgit v1.2.1