diff options
author | Guillaume Cottenceau <gc@mandriva.com> | 2001-02-21 23:01:11 +0000 |
---|---|---|
committer | Guillaume Cottenceau <gc@mandriva.com> | 2001-02-21 23:01:11 +0000 |
commit | 841067b45e61bb8d5a1394d8bba25db1d2a23ea0 (patch) | |
tree | 76a8779a4825eef4fa8655ece532a1e34b601615 /mdk-stage1 | |
parent | 4fc11a304d40052e9515f660e144d925eff8575c (diff) | |
download | drakx-backup-do-not-use-841067b45e61bb8d5a1394d8bba25db1d2a23ea0.tar drakx-backup-do-not-use-841067b45e61bb8d5a1394d8bba25db1d2a23ea0.tar.gz drakx-backup-do-not-use-841067b45e61bb8d5a1394d8bba25db1d2a23ea0.tar.bz2 drakx-backup-do-not-use-841067b45e61bb8d5a1394d8bba25db1d2a23ea0.tar.xz drakx-backup-do-not-use-841067b45e61bb8d5a1394d8bba25db1d2a23ea0.zip |
- fix "init" on ppc (do not use minilibc on non-i386 arch's)
- fix segfault of dietlibc-linked apps (broken va_stuff in dietlibc)
- cleanup of "init"
Diffstat (limited to 'mdk-stage1')
-rw-r--r-- | mdk-stage1/Makefile | 17 | ||||
-rw-r--r-- | mdk-stage1/dietlibc/lib/vfprintf.c | 10 | ||||
-rw-r--r-- | mdk-stage1/dietlibc/lib/vprintf.c | 12 | ||||
-rw-r--r-- | mdk-stage1/init-libc-headers.h | 40 | ||||
-rw-r--r-- | mdk-stage1/init.c | 48 | ||||
-rw-r--r-- | mdk-stage1/minilibc.c | 27 | ||||
-rw-r--r-- | mdk-stage1/minilibc.h | 3 | ||||
-rw-r--r-- | mdk-stage1/tools.c | 4 |
8 files changed, 99 insertions, 62 deletions
diff --git a/mdk-stage1/Makefile b/mdk-stage1/Makefile index ce75a7c5f..5c3a0e98a 100644 --- a/mdk-stage1/Makefile +++ b/mdk-stage1/Makefile @@ -37,7 +37,13 @@ COMPILE = $(CC) $(DEFS) $(CFLAGS) #- stage1 "loader" +ifeq (i386, $(ARCH)) INITSRC = minilibc.c init.c +INIT_DEFS = -DINIT_HEADERS=\"minilibc.h\" +else +INITSRC = init.c +INIT_DEFS = -DINIT_HEADERS=\"init-libc-headers.h\" +endif INITOBJS = $(subst .c,.o,$(INITSRC)) @@ -103,13 +109,9 @@ NETWORK_DEFS = -DDISABLE_CDROM -DDISABLE_DISK ifeq (i386, $(ARCH)) -MINILIC=minilibc.o LDFLAGS_INIT = -static -nostdlib /usr/lib/crt1.o -endif -ifeq (sparc, $(ARCH)) -MINILIBC=minilibc.o /usr/lib/libc.a -LDFLAGS_INIT = -static -nostdlib /usr/lib/crt1.o -LDFLAGS_STAGE1 = -static +else +LDFLAGS_INIT = $(GLIBC_LDFLAGS_STAGE1) endif @@ -165,6 +167,9 @@ $(STAGE1OBJS-DISK): %-DISK.o: %.c .depend $(STAGE1OBJS-NETWORK): %-NETWORK.o: %.c .depend $(COMPILE) $(GLIBC_INCLUDES) $(NETWORK_DEFS) -c $< -o $@ +$(INITOBJS): %.o: %.c + $(COMPILE) $(INIT_DEFS) $(GLIBC_INCLUDES) -c $< + .c.o: .depend $(COMPILE) $(GLIBC_INCLUDES) $(PCMCIA_DEFS) -c $< diff --git a/mdk-stage1/dietlibc/lib/vfprintf.c b/mdk-stage1/dietlibc/lib/vfprintf.c index 0ebfd1561..03dfe87a9 100644 --- a/mdk-stage1/dietlibc/lib/vfprintf.c +++ b/mdk-stage1/dietlibc/lib/vfprintf.c @@ -4,12 +4,8 @@ int vfprintf(FILE *fstream, const char *format, va_list ap) { - char *tmp; - size_t n=vsnprintf(0, 1000000, format, ap); - tmp=alloca(n+2); - if (tmp) { - vsnprintf(tmp, n+1, format, ap); - fwrite(tmp, n,1, fstream); - } + char tmp[1000000]; + size_t n = vsnprintf(tmp, sizeof(tmp), format, ap); + fwrite(tmp, n, 1, fstream); return n; } diff --git a/mdk-stage1/dietlibc/lib/vprintf.c b/mdk-stage1/dietlibc/lib/vprintf.c index bba98419f..46ecc47a4 100644 --- a/mdk-stage1/dietlibc/lib/vprintf.c +++ b/mdk-stage1/dietlibc/lib/vprintf.c @@ -7,14 +7,8 @@ int vsnprintf (char *str,size_t size,const char *format, va_list arg_ptr); int vprintf(const char *format, va_list ap) { - int n; - char *printf_buf; -/* char printf_buf[1024]; */ - va_list temp = ap; - n=vsnprintf(0,1000000,format,temp); -/* write(1,printf_buf,strlen(printf_buf)); */ - printf_buf=alloca(n+2); - n=vsnprintf(printf_buf,n+1,format,ap); - write(1,printf_buf,n); + char tmp[1000000]; + size_t n = vsnprintf(tmp, sizeof(tmp), format, ap); + write(1, tmp, n); return n; } diff --git a/mdk-stage1/init-libc-headers.h b/mdk-stage1/init-libc-headers.h new file mode 100644 index 000000000..d9394d851 --- /dev/null +++ b/mdk-stage1/init-libc-headers.h @@ -0,0 +1,40 @@ +/* + * Guillaume Cottenceau (gc@mandrakesoft.com) + * + * Copyright 2000 MandrakeSoft + * + * This software may be freely redistributed under the terms of the GNU + * public license. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/* + * Portions from Erik Troan (ewt@redhat.com) + * + * Copyright 1996 Red Hat Software + * + */ + +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/mount.h> +#include <linux/un.h> +#include <errno.h> +#include <signal.h> +#include <sys/resource.h> +#include <sys/wait.h> +#include <linux/reboot.h> +#include <sys/reboot.h> +#include <linux/unistd.h> +_syscall3(int, syslog, int, type, char *, bufp, int, len); + diff --git a/mdk-stage1/init.c b/mdk-stage1/init.c index 502bb3b21..edcce8508 100644 --- a/mdk-stage1/init.c +++ b/mdk-stage1/init.c @@ -19,19 +19,14 @@ * */ -#include "minilibc.h" -#include "config-stage1.h" - -#define KICK_FLOPPY 1 -#define KICK_BOOTP 2 +#ifndef INIT_HEADERS +#include "init-libc-headers.h" +#else +#include INIT_HEADERS +#endif -#define MS_REMOUNT 32 +#include "config-stage1.h" -#define ENV_PATH 0 -#define ENV_LD_LIBRARY_PATH 1 -#define ENV_HOME 2 -#define ENV_TERM 3 -#define ENV_DEBUG 4 char * env[] = { "PATH=/usr/bin:/bin:/sbin:/usr/sbin:/mnt/sbin:/mnt/usr/sbin:/mnt/bin:/mnt/usr/bin", @@ -73,6 +68,33 @@ void print_warning(char *msg) printf("W: %s\n", msg); } +void print_int(int fd, int i) +{ + char buf[10]; + char * chptr = buf + 9; + int j = 0; + + if (i < 0) + { + write(1, "-", 1); + i = -1 * i; + } + + while (i) + { + *chptr-- = '0' + (i % 10); + j++; + i = i / 10; + } + + write(fd, chptr + 1, j); +} + +void print_str(int fd, char * string) +{ + write(fd, string, strlen(string)); +} + /* fork to: * (1) watch /proc/kmsg and copy the stuff to /dev/tty4 @@ -203,6 +225,8 @@ void doklog() } +#define LOOP_CLR_FD 0x4C01 + void del_loop(char *device) { int fd; @@ -426,7 +450,7 @@ int main(int argc, char **argv) if (!abnormal_termination) { printf("rebooting system\n"); sleep(2); - reboot(0xfee1dead, 672274793, 0x1234567); + reboot(LINUX_REBOOT_CMD_RESTART); } else { printf("you may safely reboot your system\n"); while (1); diff --git a/mdk-stage1/minilibc.c b/mdk-stage1/minilibc.c index ac0ffe334..d8ff88852 100644 --- a/mdk-stage1/minilibc.c +++ b/mdk-stage1/minilibc.c @@ -203,32 +203,6 @@ char * strstr(char *haystack, char *needle) return NULL; } -void print_int(int fd, int i) -{ - char buf[10]; - char * chptr = buf + 9; - int j = 0; - - if (i < 0) - { - write(1, "-", 1); - i = -1 * i; - } - - while (i) - { - *chptr-- = '0' + (i % 10); - j++; - i = i / 10; - } - - write(fd, chptr + 1, j); -} - -void print_str(int fd, char * string) -{ - write(fd, string, strlen(string)); -} /* Minimum printf which handles only characters, %d's and %s's */ void printf(char * fmt, ...) @@ -274,3 +248,4 @@ void printf(char * fmt, ...) } } } + diff --git a/mdk-stage1/minilibc.h b/mdk-stage1/minilibc.h index 8682ae3d2..f3ff9c758 100644 --- a/mdk-stage1/minilibc.h +++ b/mdk-stage1/minilibc.h @@ -109,6 +109,8 @@ static inline _syscall0(int,fork) #endif static inline _syscall0(pid_t,setsid) static inline _syscall3(int,syslog,int, type, char *, buf, int, len); +#define LINUX_REBOOT_CMD_RESTART 0x01234567 +#define reboot(x) reboot(0xfee1dead, 672274793, x) #else static inline _syscall5(int,_newselect,int,n,fd_set *,rd,fd_set *,wr,fd_set *,ex,struct timeval *,timeval); static inline _syscall3(int,write,int,fd,const char *,buf,unsigned long,count) @@ -141,3 +143,4 @@ void print_str(int fd, char * string); void print_int(int fd, int i); /* Minimum printf which handles only characters, %d's and %s's */ void printf(char * fmt, ...); + diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index c67748ff5..9d0f083f6 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -50,11 +50,11 @@ void process_cmdline(void) log_message("opening /proc/cmdline... "); - if ((fd = open("/proc/cmdline", O_RDONLY, 0)) == -1) + if ((fd = open("/proc/cmdline", O_RDONLY)) == -1) fatal_error("could not open /proc/cmdline"); size = read(fd, buf, sizeof(buf)); - buf[size-1] = 0; + buf[size-1] = '\0'; // -1 to eat the \n close(fd); log_message("\t%s", buf); |