diff options
author | Guillaume Cottenceau <gc@mandriva.com> | 2001-05-17 16:53:32 +0000 |
---|---|---|
committer | Guillaume Cottenceau <gc@mandriva.com> | 2001-05-17 16:53:32 +0000 |
commit | 067ea25e278d221724425e492452d4341ab2e669 (patch) | |
tree | 6abef88f0bf831cd6316cc5adbb550d337c7275a /mdk-stage1 | |
parent | 93796296016933af1c23f13fc2ae6d5f62299527 (diff) | |
download | drakx-backup-do-not-use-067ea25e278d221724425e492452d4341ab2e669.tar drakx-backup-do-not-use-067ea25e278d221724425e492452d4341ab2e669.tar.gz drakx-backup-do-not-use-067ea25e278d221724425e492452d4341ab2e669.tar.bz2 drakx-backup-do-not-use-067ea25e278d221724425e492452d4341ab2e669.tar.xz drakx-backup-do-not-use-067ea25e278d221724425e492452d4341ab2e669.zip |
don't write nonsense code to separate frontend from stage1,
but rather, try to do some clever things
Diffstat (limited to 'mdk-stage1')
-rw-r--r-- | mdk-stage1/Makefile | 5 | ||||
-rw-r--r-- | mdk-stage1/cdrom.c | 2 | ||||
-rw-r--r-- | mdk-stage1/dhcp.c | 4 | ||||
-rw-r--r-- | mdk-stage1/disk.c | 20 | ||||
-rw-r--r-- | mdk-stage1/frontend.h | 11 | ||||
-rw-r--r-- | mdk-stage1/modules.c | 2 | ||||
-rw-r--r-- | mdk-stage1/network.c | 34 | ||||
-rw-r--r-- | mdk-stage1/newt-frontend.c | 31 | ||||
-rw-r--r-- | mdk-stage1/probing.c | 4 | ||||
-rw-r--r-- | mdk-stage1/stage1.c | 40 | ||||
-rw-r--r-- | mdk-stage1/stage1.h | 4 | ||||
-rw-r--r-- | mdk-stage1/stdio-frontend.c | 33 | ||||
-rw-r--r-- | mdk-stage1/tools.c | 8 |
13 files changed, 87 insertions, 111 deletions
diff --git a/mdk-stage1/Makefile b/mdk-stage1/Makefile index 5dbef79af..75857a408 100644 --- a/mdk-stage1/Makefile +++ b/mdk-stage1/Makefile @@ -79,7 +79,7 @@ STAGE1_NETWORK_LIBS = endif #- stage1 itself -STAGE1SRC = stage1.c log.c tools.c modules.c probing.c mount.c automatic.c +STAGE1SRC = stage1.c log.c tools.c modules.c probing.c mount.c automatic.c frontend-common.c CDROMSRC = cdrom.c DISKSRC = disk.c lomount.c NETWORKSRC = network.c nfsmount.c dhcp.c url.c dns.c @@ -174,9 +174,6 @@ $(STAGE1OBJS-NETWORK): %-NETWORK.o: %.c .depend $(INITOBJS): %.o: %.c $(COMPILE) $(INIT_DEFS) -c $< -$(FRONTEND_OBJS): %.o: %.c - $(COMPILE) $(INCLUDES) -D__FRONTEND_NEED_BACKEND__ -c $< - .c.o: .depend $(COMPILE) $(INCLUDES) $(PCMCIA_DEFS) -c $< diff --git a/mdk-stage1/cdrom.c b/mdk-stage1/cdrom.c index f05bc0341..d99877b7f 100644 --- a/mdk-stage1/cdrom.c +++ b/mdk-stage1/cdrom.c @@ -116,7 +116,7 @@ enum return_type cdrom_prepare(void) } if (count == 0) { - error_message("No CDROM device found."); + stg1_error_message("No CDROM device found."); i = ask_insmod(SCSI_ADAPTERS); if (i == RETURN_BACK) return RETURN_BACK; diff --git a/mdk-stage1/dhcp.c b/mdk-stage1/dhcp.c index 230e8757b..78a0712f9 100644 --- a/mdk-stage1/dhcp.c +++ b/mdk-stage1/dhcp.c @@ -471,7 +471,7 @@ static int handle_transaction(int s, struct bootp_request * breq, struct bootp_r timeout = 5; } - error_message("No DHCP reply received."); + stg1_error_message("No DHCP reply received."); return -1; } @@ -511,7 +511,7 @@ enum return_type perform_dhcp(struct interface_info * intf) char requested_options[50]; if (strncmp(intf->device, "eth", 3)) { - error_message("DHCP available only for Ethernet networking."); + stg1_error_message("DHCP available only for Ethernet networking."); return RETURN_ERROR; } diff --git a/mdk-stage1/disk.c b/mdk-stage1/disk.c index 23f865380..9b47ce466 100644 --- a/mdk-stage1/disk.c +++ b/mdk-stage1/disk.c @@ -76,7 +76,7 @@ static enum return_type try_with_device(char *dev_name) if (!(f = fopen("/proc/partitions", "rb")) || !fgets(buf, sizeof(buf), f) || !fgets(buf, sizeof(buf), f)) { log_perror(dev_name); - error_message("Could not read partitions information."); + stg1_error_message("Could not read partitions information."); return RETURN_ERROR; } @@ -94,7 +94,7 @@ static enum return_type try_with_device(char *dev_name) fclose(f); if (parts[0] == NULL) { - error_message("No partitions found."); + stg1_error_message("No partitions found."); return RETURN_ERROR; } @@ -109,7 +109,7 @@ static enum return_type try_with_device(char *dev_name) if (my_mount(device_fullname, disk_own_mount, "ext2") == -1 && my_mount(device_fullname, disk_own_mount, "vfat") == -1 && my_mount(device_fullname, disk_own_mount, "reiserfs") == -1) { - error_message("I can't find a valid filesystem (tried: ext2, vfat, reiserfs)."); + stg1_error_message("I can't find a valid filesystem (tried: ext2, vfat, reiserfs)."); return try_with_device(dev_name); } @@ -124,7 +124,7 @@ static enum return_type try_with_device(char *dev_name) strcat(location_full, answers_location[0]); if (access(location_full, R_OK)) { - error_message("Directory or ISO image file could not be found on partition.\n" + stg1_error_message("Directory or ISO image file could not be found on partition.\n" "Here's a short extract of the files in the root of the partition:\n" "%s", disk_extract_list_directory(disk_own_mount)); umount(disk_own_mount); @@ -136,7 +136,7 @@ static enum return_type try_with_device(char *dev_name) if (!stat(location_full, &statbuf) && !S_ISDIR(statbuf.st_mode)) { log_message("%s exists and is not a directory, assuming this is an ISO image", location_full); if (lomount(location_full, IMAGE_LOCATION)) { - error_message("Could not mount file %s as an ISO image of the " DISTRIB_NAME " Distribution.", answers_location[0]); + stg1_error_message("Could not mount file %s as an ISO image of the " DISTRIB_NAME " Distribution.", answers_location[0]); umount(disk_own_mount); return try_with_device(dev_name); } @@ -146,7 +146,7 @@ static enum return_type try_with_device(char *dev_name) if (IS_SPECIAL_STAGE2 || ramdisk_possible()) { /* RAMDISK install */ if (access(IMAGE_LOCATION RAMDISK_LOCATION, R_OK)) { - error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. " + stg1_error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. " "(I need the subdirectory " RAMDISK_LOCATION ")\n" "Here's a short extract of the files in the directory:\n" "%s", disk_extract_list_directory(IMAGE_LOCATION)); @@ -155,7 +155,7 @@ static enum return_type try_with_device(char *dev_name) return try_with_device(dev_name); } if (load_ramdisk() != RETURN_OK) { - error_message("Could not load program into memory."); + stg1_error_message("Could not load program into memory."); loumount(); umount(disk_own_mount); return try_with_device(dev_name); @@ -164,7 +164,7 @@ static enum return_type try_with_device(char *dev_name) /* LIVE install */ char p; if (access(IMAGE_LOCATION LIVE_LOCATION, R_OK)) { - error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. " + stg1_error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. " "(I need the subdirectory " LIVE_LOCATION ")\n" "Here's a short extract of the files in the directory:\n" "%s", disk_extract_list_directory(IMAGE_LOCATION)); @@ -173,7 +173,7 @@ static enum return_type try_with_device(char *dev_name) return try_with_device(dev_name); } if (readlink(IMAGE_LOCATION LIVE_LOCATION "/usr/bin/runinstall2", &p, 1) != 1) { - error_message("The " DISTRIB_NAME " Distribution seems to be copied on a Windows partition. " + stg1_error_message("The " DISTRIB_NAME " Distribution seems to be copied on a Windows partition. " "You need more memory to perform an installation from a Windows partition. " "Another solution if to copy the " DISTRIB_NAME " Distribution on a Linux partition."); loumount(); @@ -210,7 +210,7 @@ enum return_type disk_prepare(void) } if (count == 0) { - error_message("No DISK drive found."); + stg1_error_message("No DISK drive found."); i = ask_insmod(SCSI_ADAPTERS); if (i == RETURN_BACK) return RETURN_BACK; diff --git a/mdk-stage1/frontend.h b/mdk-stage1/frontend.h index 9658858eb..167291798 100644 --- a/mdk-stage1/frontend.h +++ b/mdk-stage1/frontend.h @@ -19,10 +19,14 @@ #ifndef _FRONTEND_H_ #define _FRONTEND_H_ +#include <stdarg.h> + + enum return_type { RETURN_OK, RETURN_BACK, RETURN_ERROR }; void init_frontend(char * welcome_msg); void finish_frontend(void); + void error_message(char *msg, ...) __attribute__ ((format (printf, 1, 2))); /* blocking */ void info_message(char *msg, ...) __attribute__ ((format (printf, 1, 2))); /* blocking */ void wait_message(char *msg, ...) __attribute__ ((format (printf, 1, 2))); /* non-blocking */ @@ -38,10 +42,9 @@ enum return_type ask_from_list_comments(char *msg, char ** elems, char ** elems_ enum return_type ask_from_entries(char *msg, char ** questions, char *** answers, int entry_size, void (*callback_func)(char ** strings)); -#ifdef __FRONTEND_NEED_BACKEND__ -int error_message_backend(void); -int info_message_backend(void); -#endif +void verror_message(char *msg, va_list ap); +void vinfo_message(char *msg, va_list ap); +void vwait_message(char *msg, va_list ap); #endif diff --git a/mdk-stage1/modules.c b/mdk-stage1/modules.c index 37f251685..0a84f612b 100644 --- a/mdk-stage1/modules.c +++ b/mdk-stage1/modules.c @@ -319,7 +319,7 @@ static enum return_type insmod_with_options(char * mod, enum driver_type type) strcat(options, answers[0]); // because my_insmod will eventually modify the string if (my_insmod(mod, type, answers[0]) != INSMOD_OK) { - error_message("Insmod failed."); + stg1_error_message("Insmod failed."); return RETURN_ERROR; } diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c index 770094893..7e154de2a 100644 --- a/mdk-stage1/network.c +++ b/mdk-stage1/network.c @@ -47,7 +47,7 @@ static void error_message_net(void) /* reduce code size */ { - error_message("Could not configure network."); + stg1_error_message("Could not configure network."); } @@ -373,7 +373,7 @@ static enum return_type setup_network_interface(struct interface_info * intf) return setup_network_interface(intf); if (!inet_aton(answers[0], &addr)) { - error_message("Invalid IP address."); + stg1_error_message("Invalid IP address."); return setup_network_interface(intf); } memcpy(&intf->ip, &addr, sizeof(addr)); @@ -541,7 +541,7 @@ static char * interface_select(void) } if (count == 0) { - error_message("No NET device found."); + stg1_error_message("No NET device found."); i = ask_insmod(NETWORK_DEVICES); if (i == RETURN_BACK) return NULL; @@ -628,13 +628,13 @@ enum return_type nfs_prepare(void) strcat(nfsmount_location, answers[1]); if (my_mount(nfsmount_location, IMAGE_LOCATION, "nfs") == -1) { - error_message("I can't mount the directory from the NFS server."); + stg1_error_message("I can't mount the directory from the NFS server."); results = RETURN_BACK; continue; } if (access(IMAGE_LOCATION LIVE_LOCATION, R_OK)) { - error_message("That NFS volume does not seem to contain the " DISTRIB_NAME " Distribution."); + stg1_error_message("That NFS volume does not seem to contain the " DISTRIB_NAME " Distribution."); umount(IMAGE_LOCATION); results = RETURN_BACK; } @@ -645,7 +645,7 @@ enum return_type nfs_prepare(void) if (IS_SPECIAL_STAGE2) { if (load_ramdisk() != RETURN_OK) { - error_message("Could not load program into memory."); + stg1_error_message("Could not load program into memory."); return nfs_prepare(); } } @@ -666,7 +666,7 @@ enum return_type ftp_prepare(void) enum return_type results; if (!ramdisk_possible()) { - error_message("FTP install needs more than %d Mbytes of memory (detected %d Mbytes).", + stg1_error_message("FTP install needs more than %d Mbytes of memory (detected %d Mbytes).", MEM_LIMIT_RAMDISK, total_memory()); return RETURN_ERROR; } @@ -694,11 +694,11 @@ enum return_type ftp_prepare(void) if (ftp_serv_response < 0) { log_message("FTP: error connect %d", ftp_serv_response); if (ftp_serv_response == FTPERR_BAD_HOSTNAME) - error_message("Error: bad hostname."); + stg1_error_message("Error: bad hostname."); else if (ftp_serv_response == FTPERR_FAILED_CONNECT) - error_message("Error: failed to connect to remote host."); + stg1_error_message("Error: failed to connect to remote host."); else - error_message("Error: couldn't connect."); + stg1_error_message("Error: couldn't connect."); results = RETURN_BACK; continue; } @@ -712,13 +712,13 @@ enum return_type ftp_prepare(void) if (fd < 0) { log_message("FTP: error get %d", fd); if (fd == FTPERR_PASSIVE_ERROR) - error_message("Error: error with passive connection."); + stg1_error_message("Error: error with passive connection."); else if (fd == FTPERR_FILE_NOT_FOUND) - error_message("Error: file not found (%s).", location_full); + stg1_error_message("Error: file not found (%s).", location_full); else if (fd == FTPERR_BAD_SERVER_RESPONSE) - error_message("Error: bad server response (server too busy?)."); + stg1_error_message("Error: bad server response (server too busy?)."); else - error_message("Error: couldn't retrieve Installation program."); + stg1_error_message("Error: couldn't retrieve Installation program."); results = RETURN_BACK; continue; } @@ -752,7 +752,7 @@ enum return_type http_prepare(void) enum return_type results; if (!ramdisk_possible()) { - error_message("HTTP install needs more than %d Mbytes of memory (detected %d Mbytes).", + stg1_error_message("HTTP install needs more than %d Mbytes of memory (detected %d Mbytes).", MEM_LIMIT_RAMDISK, total_memory()); return RETURN_ERROR; } @@ -781,9 +781,9 @@ enum return_type http_prepare(void) if (fd < 0) { log_message("HTTP: error %d", fd); if (fd == FTPERR_FAILED_CONNECT) - error_message("Error: couldn't connect to server."); + stg1_error_message("Error: couldn't connect to server."); else - error_message("Error: couldn't get file (%s).", location_full); + stg1_error_message("Error: couldn't get file (%s).", location_full); results = RETURN_BACK; continue; } diff --git a/mdk-stage1/newt-frontend.c b/mdk-stage1/newt-frontend.c index e2b95eb92..95bf9847f 100644 --- a/mdk-stage1/newt-frontend.c +++ b/mdk-stage1/newt-frontend.c @@ -52,32 +52,18 @@ void finish_frontend(void) } -void error_message(char *msg, ...) +void verror_message(char *msg, va_list ap) { - va_list args; -#ifdef __FRONTEND_NEED_BACKEND__ - if (error_message_backend()) - return; -#endif - va_start(args, msg); - newtWinMessagev("Error", "Ok", msg, args); - va_end(args); + newtWinMessagev("Error", "Ok", msg, ap); } -void info_message(char *msg, ...) +void vinfo_message(char *msg, va_list ap) { - va_list args; -#ifdef __FRONTEND_NEED_BACKEND__ - if (info_message_backend()) - return; -#endif - va_start(args, msg); - newtWinMessagev("Notice", "Ok", msg, args); - va_end(args); + newtWinMessagev("Notice", "Ok", msg, ap); } -void wait_message(char *msg, ...) +void vwait_message(char *msg, va_list ap) { int width, height; char * title = "Please wait..."; @@ -87,21 +73,16 @@ void wait_message(char *msg, ...) char * flowed; int size = 0; int i = 0; - va_list args; - - va_start(args, msg); do { size += 1000; if (buf) free(buf); buf = malloc(size); - i = vsnprintf(buf, size, msg, args); + i = vsnprintf(buf, size, msg, ap); } while (i >= size || i == -1); flowed = newtReflowText(buf, 60, 5, 5, &width, &height); - va_end(args); - c = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP); newtTextboxSetText(c, flowed); diff --git a/mdk-stage1/probing.c b/mdk-stage1/probing.c index 721f29dcf..fa4df5aa8 100644 --- a/mdk-stage1/probing.c +++ b/mdk-stage1/probing.c @@ -63,7 +63,7 @@ static void warning_insmod_failed(enum insmod_return r) { if (r != INSMOD_OK && !(IS_AUTOMATIC && r == INSMOD_FAILED_FILE_NOT_FOUND)) - error_message("Warning, installation of driver failed. (please include msg from <Alt-F3> for bugreports)"); + stg1_error_message("Warning, installation of driver failed. (please include msg from <Alt-F3> for bugreports)"); } #ifndef DISABLE_NETWORK @@ -173,7 +173,7 @@ static void probe_that_type(enum driver_type type) #ifndef DISABLE_NETWORK if (type == NETWORK_DEVICES) { /* insmod is quick, let's use the info message */ - info_message("Detected network device:\n \n%s", pcidb[i].name); + stg1_info_message("Detected network device:\n \n%s", pcidb[i].name); prepare_intf_descr(pcidb[i].name); warning_insmod_failed(my_insmod(pcidb[i].module, NETWORK_DEVICES, NULL)); if (intf_descr_for_discover) /* for modules providing more than one net intf */ diff --git a/mdk-stage1/stage1.c b/mdk-stage1/stage1.c index db9a4a15c..1f39489a1 100644 --- a/mdk-stage1/stage1.c +++ b/mdk-stage1/stage1.c @@ -22,19 +22,18 @@ * */ -#include <sys/mount.h> +#include <stdlib.h> +#include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <unistd.h> -#include <sys/ioctl.h> -#include <signal.h> - -#include <stdlib.h> #include <stdio.h> +#include <sys/ioctl.h> +#include <sys/mount.h> #include <string.h> #include <errno.h> #include <ctype.h> +#include <stdarg.h> #include "stage1.h" @@ -78,18 +77,29 @@ void fatal_error(char *msg) /************************************************************ - * backend functs - * the principle is to not pollute frontend code with stage1-specific stuff */ + * special frontend functs + * (the principle is to not pollute frontend code with stage1-specific stuff) */ -int error_message_backend(void) +void stg1_error_message(char *msg, ...) { + va_list args; + va_start(args, msg); + log_message("unsetting automatic"); unset_param(MODE_AUTOMATIC); - return 0; + verror_message(msg, args); + va_end(args); } -int info_message_backend(void) +void stg1_info_message(char *msg, ...) { - return IS_AUTOMATIC ? 1 : 0; + va_list args; + va_start(args, msg); + if (IS_AUTOMATIC) { + vlog_message(msg, args); + return; + } + vinfo_message(msg, args); + va_end(args); } @@ -215,14 +225,14 @@ static void expert_third_party_modules(void) my_insmod("floppy", ANY_DRIVER_TYPE, NULL); if (my_mount("/dev/fd0", floppy_mount_location, "ext2") == -1) { - error_message("I can't find a Linux ext2 floppy in first floppy drive."); + stg1_error_message("I can't find a Linux ext2 floppy in first floppy drive."); return expert_third_party_modules(); } modules = list_directory(floppy_mount_location); if (!modules || !*modules) { - error_message("No modules found on floppy disk."); + stg1_error_message("No modules found on floppy disk."); umount(floppy_mount_location); return expert_third_party_modules(); } @@ -246,7 +256,7 @@ static void expert_third_party_modules(void) if (rc) { log_message("\tfailed"); - error_message("Insmod failed."); + stg1_error_message("Insmod failed."); } return expert_third_party_modules(); diff --git a/mdk-stage1/stage1.h b/mdk-stage1/stage1.h index 88445f962..a9ca99b32 100644 --- a/mdk-stage1/stage1.h +++ b/mdk-stage1/stage1.h @@ -47,6 +47,8 @@ extern char * interactive_fifo; void fatal_error(char *msg) __attribute__ ((noreturn)); -#define __FRONTEND_NEED_BACKEND__ + +void stg1_error_message(char *msg, ...) __attribute__ ((format (printf, 1, 2))); +void stg1_info_message(char *msg, ...) __attribute__ ((format (printf, 1, 2))); #endif diff --git a/mdk-stage1/stdio-frontend.c b/mdk-stage1/stdio-frontend.c index fd3510cf1..5b37eafcd 100644 --- a/mdk-stage1/stdio-frontend.c +++ b/mdk-stage1/stdio-frontend.c @@ -163,44 +163,27 @@ static char * get_string_response(char * initial_string) return strdup(s); } -static void blocking_msg(char *type, char *fmt, va_list args) +static void blocking_msg(char *type, char *fmt, va_list ap) { printf(type); - vprintf(fmt, args); + vprintf(fmt, ap); get_any_response(); } -void error_message(char *msg, ...) +void verror_message(char *msg, va_list ap) { - va_list args; -#ifdef __FRONTEND_NEED_BACKEND__ - if (error_message_backend()) - return; -#endif - va_start(args, msg); - blocking_msg("> Error! ", msg, args); - va_end(args); + blocking_msg("> Error! ", msg, ap); } -void info_message(char *msg, ...) +void vinfo_message(char *msg, va_list ap) { - va_list args; -#ifdef __FRONTEND_NEED_BACKEND__ - if (info_message_backend()) - return; -#endif - va_start(args, msg); - blocking_msg("> Notice: ", msg, args); - va_end(args); + blocking_msg("> Notice: ", msg, ap); } -void wait_message(char *msg, ...) +void vwait_message(char *msg, va_list ap) { - va_list args; printf("Please wait: "); - va_start(args, msg); - vprintf(msg, args); - va_end(args); + vprintf(msg, ap); fflush(stdout); } diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index 66df907b7..deafdc8fe 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -256,14 +256,14 @@ enum return_type load_ramdisk_fd(int ramdisk_fd, int size) if (!st2) { log_message("Opening compressed ramdisk: %s", BZ2_bzerror(st2, &z_errnum)); - error_message("Could not open compressed ramdisk file."); + stg1_error_message("Could not open compressed ramdisk file."); return RETURN_ERROR; } ram_fd = open(ramdisk, O_WRONLY); if (ram_fd == -1) { log_perror(ramdisk); - error_message("Could not open ramdisk device file."); + stg1_error_message("Could not open ramdisk device file."); return RETURN_ERROR; } @@ -282,7 +282,7 @@ enum return_type load_ramdisk_fd(int ramdisk_fd, int size) if (!seems_ok) { log_message("reading compressed ramdisk: %s", BZ2_bzerror(st2, &z_errnum)); remove_wait_message(); - error_message("Could not uncompress second stage ramdisk."); + stg1_error_message("Could not uncompress second stage ramdisk."); return RETURN_ERROR; } @@ -345,7 +345,7 @@ enum return_type load_ramdisk(void) if (st2_fd == -1) { log_message("open ramdisk file (%s) failed", img_name); - error_message("Could not open compressed ramdisk file (%s).", img_name); + stg1_error_message("Could not open compressed ramdisk file (%s).", img_name); return RETURN_ERROR; } |