From e6753ef16e759aa1ef0095aad84a2d72046c2caf Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Tue, 13 Feb 2001 14:46:20 +0000 Subject: - save /etc/resolv.conf for rescue --- mdk-stage1/tools.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'mdk-stage1') diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index 8b2931ad2..c67748ff5 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "stage1.h" #include "log.h" #include "mount.h" @@ -157,7 +158,6 @@ void set_param_valued(char *param_name, char *param_value) void set_param(int i) { - log_message("setting param %d", i); stage1_mode |= i; if (i == MODE_RESCUE) { set_param_valued("special_stage2", "rescue"); @@ -167,7 +167,6 @@ void set_param(int i) void unset_param(int i) { - log_message("unsetting param %d", i); stage1_mode &= ~i; } @@ -207,6 +206,38 @@ int ramdisk_possible(void) } +static void save_stuff_for_rescue(void) +{ + 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"); +} + + enum return_type load_ramdisk_fd(int ramdisk_fd, int size) { BZFILE * st2; @@ -258,14 +289,20 @@ enum return_type load_ramdisk_fd(int ramdisk_fd, int size) BZ2_bzclose(st2); /* opened by gzdopen, but also closes the associated fd */ close(ram_fd); - if (IS_RESCUE) - return RETURN_OK; /* fucksike, I lost several hours wondering why the kernel won't see the rescue if it is alreay mounted */ - if (my_mount(ramdisk, STAGE2_LOCATION, "ext2")) return RETURN_ERROR; set_param(MODE_RAMDISK); + if (IS_RESCUE) { + save_stuff_for_rescue(); + if (umount(STAGE2_LOCATION)) { + log_perror(ramdisk); + return RETURN_ERROR; + } + return RETURN_OK; /* fucksike, I lost several hours wondering why the kernel won't see the rescue if it is alreay mounted */ + } + return RETURN_OK; } -- cgit v1.2.1