summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Cottenceau <gc@mandriva.com>2000-11-21 17:14:00 +0000
committerGuillaume Cottenceau <gc@mandriva.com>2000-11-21 17:14:00 +0000
commit3ef4b2ee26bc41cdd392b1e3feb82ab6cf587669 (patch)
treec875d209f8546af5888a4b27bed33d3ee15f2a5b
parentc870373766599b2810326720d891128bfcb6fa64 (diff)
downloaddrakx-3ef4b2ee26bc41cdd392b1e3feb82ab6cf587669.tar
drakx-3ef4b2ee26bc41cdd392b1e3feb82ab6cf587669.tar.gz
drakx-3ef4b2ee26bc41cdd392b1e3feb82ab6cf587669.tar.bz2
drakx-3ef4b2ee26bc41cdd392b1e3feb82ab6cf587669.tar.xz
drakx-3ef4b2ee26bc41cdd392b1e3feb82ab6cf587669.zip
first draft
-rw-r--r--mdk-stage1/Makefile48
-rw-r--r--mdk-stage1/init-data/emptyboot.img.bz2bin0 -> 6342 bytes
-rw-r--r--mdk-stage1/init-data/msgboot-graphicallogo-2880.img.bz2bin0 -> 30301 bytes
-rw-r--r--mdk-stage1/init-data/msgboot-graphicallogo.img.bz2bin0 -> 29067 bytes
-rw-r--r--mdk-stage1/init-data/msgboot.img.bz2bin0 -> 30378 bytes
-rw-r--r--mdk-stage1/init.c32
-rw-r--r--mdk-stage1/log.c74
-rw-r--r--mdk-stage1/log.h35
-rw-r--r--mdk-stage1/stage1-data/stage1-with-sash.tar.bz2bin0 -> 345061 bytes
-rw-r--r--mdk-stage1/stage1-data/stage1.tar.bz2bin0 -> 1998 bytes
-rw-r--r--mdk-stage1/stage1.c129
11 files changed, 277 insertions, 41 deletions
diff --git a/mdk-stage1/Makefile b/mdk-stage1/Makefile
index ca707070a..a1b2fc68f 100644
--- a/mdk-stage1/Makefile
+++ b/mdk-stage1/Makefile
@@ -29,7 +29,7 @@ ARCH := $(patsubst sparc%,sparc,$(ARCH))
#- We can leave "-g" forever since stripping will remove everything
CFLAGS = -Os -g -Wall -Werror -fomit-frame-pointer
INCLUDES = -I.
-DEFS = -D_GNU_SOURCE=1 -DVERSION=\"$(VERSION)\" -DUSE_LOGDEV
+DEFS = -D_GNU_SOURCE=1 -DVERSION=\"$(VERSION)\" -DUSE_LOGDEV -DSPAWN_SHELL
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CFLAGS)
@@ -37,31 +37,32 @@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CFLAGS)
#- stage1 "loader"
INITSRC = minilibc.c init.c
- #- stage1 itself
-STAGE1SRC = #stage1.c cdrom.c devices.c
+INITOBJS = $(subst .c,.o,$(INITSRC))
-ALLSRC = $(INITSRC) $(STAGE1SRC)
+ #- stage1 itself (minus stage1.c)
+STAGE1SRC = log.c #cdrom.c devices.c
+
+STAGE1OBJS = $(subst .c,.o,$(STAGE1SRC))
+
+ALLSRC = $(INITSRC) $(STAGE1SRC)
-STATIC = -static
ifeq (i386, $(ARCH))
-MINILIBC=minilibc.o
-LDFLAGS = -nostdlib /usr/lib/crt1.o
+MINILIC=minilibc.o
+LDFLAGS_INIT = -static -nostdlib /usr/lib/crt1.o
+LDFLAGS_STAGE1 = -static
STATIC=-static
-else
+endif
ifeq (sparc, $(ARCH))
MINILIBC=minilibc.o /usr/lib/libc.a
-LDFLAGS = -nostdlib /usr/lib/crt1.o
-STATIC=-static
-else
-STATIC=-static
-endif
+LDFLAGS_INIT = -static -nostdlib /usr/lib/crt1.o
+LDFLAGS_STAGE1 = -static
endif
-BINS = init
+BINS = init stage1-network
#ifeq (i386, $(ARCH))
@@ -91,24 +92,27 @@ dirs:
[ "$$n" = "." ] || make -C $$n ;\
done
+
+init: $(INITOBJS)
+ $(CC) $(LDFLAGS_INIT) -o $@ $(INITOBJS)
+
+stage1-network: $(STAGE1OBJS) stage1-network.o $(NETOBJS)
+ $(CC) $(LDFLAGS_STAGE1) -o $@ $(STAGE1OBJS) stage1-network.o $(NETOBJS)
+
+
.c.o:
$(COMPILE) -c $<
-init: init.o $(MINILIBC)
- $(CC) $(STATIC) $(LDFLAGS) -o $@ init.o $(MINILIBC)
+stage1-network.o: stage1.c
+ $(COMPILE) -DNETWORK_INSTALL -o $@ -c $<
-stage1-network: stage1-network.o $(OBJS) $(NETOBJS)
- $(CC) -g $(STATIC) -o $@ $^ -lpopt \
- -lkudzu_loader ../isys/libisys.a ../balkan/libbalkan.a \
- $(MODULELINKAGE) \
- -lpump -lbz2 -lz -lresolv -lnewt -lslang -lpci
clean:
@echo -e "*** CLEANING in all directories\n"
@for n in $(DIRS); do \
(cd $$n; make clean) \
done
- rm -f *.o .depend $(BINS)
+ rm -f *.o .depend *.rdz *.img $(BINS)
deps:
$(CPP) $(CFLAGS) -DHAVE_CONFIG_H -M $(ALLSRC) > .depend
diff --git a/mdk-stage1/init-data/emptyboot.img.bz2 b/mdk-stage1/init-data/emptyboot.img.bz2
new file mode 100644
index 000000000..6ae939c1b
--- /dev/null
+++ b/mdk-stage1/init-data/emptyboot.img.bz2
Binary files differ
diff --git a/mdk-stage1/init-data/msgboot-graphicallogo-2880.img.bz2 b/mdk-stage1/init-data/msgboot-graphicallogo-2880.img.bz2
new file mode 100644
index 000000000..9d5d276fb
--- /dev/null
+++ b/mdk-stage1/init-data/msgboot-graphicallogo-2880.img.bz2
Binary files differ
diff --git a/mdk-stage1/init-data/msgboot-graphicallogo.img.bz2 b/mdk-stage1/init-data/msgboot-graphicallogo.img.bz2
new file mode 100644
index 000000000..c650dce8b
--- /dev/null
+++ b/mdk-stage1/init-data/msgboot-graphicallogo.img.bz2
Binary files differ
diff --git a/mdk-stage1/init-data/msgboot.img.bz2 b/mdk-stage1/init-data/msgboot.img.bz2
new file mode 100644
index 000000000..c5f3a7ed7
--- /dev/null
+++ b/mdk-stage1/init-data/msgboot.img.bz2
Binary files differ
diff --git a/mdk-stage1/init.c b/mdk-stage1/init.c
index 6fbaac8be..7a0363c3f 100644
--- a/mdk-stage1/init.c
+++ b/mdk-stage1/init.c
@@ -58,7 +58,7 @@ int testing;
void fatal_error(char *msg)
{
- printf("FATAL ERROR: %s\n\nI can't recover from this, please reboot manually and send bugreport.\n", msg);
+ printf("FATAL ERROR IN INIT: %s\n\nI can't recover from this, please reboot manually and send bugreport.\n", msg);
while (1);
}
@@ -102,7 +102,6 @@ void doklog(char * fn)
{
print_error("error opening /tmp/syslog");
sleep(5);
- close(in);
return;
}
@@ -113,9 +112,12 @@ void doklog(char * fn)
close(in);
close(out);
close(log);
+ sleep(1);
return;
}
+ printf("logging process forked.\n");
+
close(0);
close(1);
close(2);
@@ -205,8 +207,9 @@ void doklog(char * fn)
readfd = accept(sock, (struct sockaddr *) &sockaddr, &s);
if (readfd < 0)
{
- if (out >= 0) write(out, "error in accept\n", 16);
- write(log, "error in accept\n", 16);
+ char * msg_error = "error in accept\n";
+ if (out >= 0) write(out, msg_error, strlen(msg_error));
+ write(log, msg_error, strlen(msg_error));
close(sock);
sock = -1;
}
@@ -387,21 +390,21 @@ int main(int argc, char **argv)
int fd;
int abnormal_termination = 0;
int end_stage2 = 0;
- char * child_argv[20];
/* getpid() != 1 should work, by linuxrc tends to get a larger pid */
testing = (getpid() > 50);
- printf("*** TESTING MODE ***\n");
-
if (!testing)
{
/* turn off screen blanking */
printf("\033[9;0]");
printf("\033[8]");
}
+ else
+ printf("*** TESTING MODE ***\n");
+
- printf("--- Hi. Linux-Mandrake install initializer starting. ---\n");
+ printf("\n--- Hi. Linux-Mandrake install initializer starting. ---\n");
printf("VERSION: %s\n", VERSION);
@@ -453,7 +456,6 @@ int main(int argc, char **argv)
if (!testing)
doklog("/dev/tty4");
-
/* Go into normal init mode - keep going, and then do a orderly shutdown
when:
@@ -466,17 +468,9 @@ int main(int argc, char **argv)
if (!(installpid = fork()))
{
/* child */
- int index;
+ char * child_argv[2];
child_argv[0] = "/sbin/stage1";
-
- index = 1;
- while (argv[index])
- {
- /* should be strdup but I don't have malloc */
- child_argv[index] = argv[index];
- index++;
- }
- child_argv[index] = NULL;
+ child_argv[1] = NULL;
printf("execing: %s\n", child_argv[0]);
execve(child_argv[0], child_argv, env);
diff --git a/mdk-stage1/log.c b/mdk-stage1/log.c
new file mode 100644
index 000000000..27e77bf02
--- /dev/null
+++ b/mdk-stage1/log.c
@@ -0,0 +1,74 @@
+/*
+ * 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 <fcntl.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "log.h"
+
+static FILE * logfile = NULL;
+
+
+void do_log_message(const char * s, va_list args)
+{
+ if (!logfile) return;
+
+ fprintf(logfile, "* ");
+ vfprintf(logfile, s, args);
+ fprintf(logfile, "\n");
+
+ fflush(logfile);
+}
+
+
+void log_message(const char * s, ...)
+{
+ va_list args;
+
+ va_start(args, s);
+ do_log_message(s, args);
+ va_end(args);
+
+ return;
+}
+
+
+void open_log(int testing)
+{
+ if (!testing)
+ {
+ logfile = fopen("/dev/tty3", "w");
+ if (!logfile)
+ logfile = fopen("/tmp/install.log", "a");
+ }
+ else
+ logfile = fopen("debug.log", "w");
+}
+
+void close_log(void)
+{
+ if (logfile)
+ fclose(logfile);
+}
diff --git a/mdk-stage1/log.h b/mdk-stage1/log.h
new file mode 100644
index 000000000..61daa41be
--- /dev/null
+++ b/mdk-stage1/log.h
@@ -0,0 +1,35 @@
+/*
+ * 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
+ *
+ */
+
+
+#ifndef _LOG_H_
+#define _LOG_H_
+
+#include <stdio.h>
+
+extern FILE * log;
+extern int logfd;
+
+void log_message(const char * s, ...);
+void open_log(int useLocal);
+void close_log(void);
+
+#endif
diff --git a/mdk-stage1/stage1-data/stage1-with-sash.tar.bz2 b/mdk-stage1/stage1-data/stage1-with-sash.tar.bz2
new file mode 100644
index 000000000..1398f0146
--- /dev/null
+++ b/mdk-stage1/stage1-data/stage1-with-sash.tar.bz2
Binary files differ
diff --git a/mdk-stage1/stage1-data/stage1.tar.bz2 b/mdk-stage1/stage1-data/stage1.tar.bz2
new file mode 100644
index 000000000..29dd9cad1
--- /dev/null
+++ b/mdk-stage1/stage1-data/stage1.tar.bz2
Binary files differ
diff --git a/mdk-stage1/stage1.c b/mdk-stage1/stage1.c
new file mode 100644
index 000000000..16b848a9c
--- /dev/null
+++ b/mdk-stage1/stage1.c
@@ -0,0 +1,129 @@
+/*
+ * 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 <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include "log.h"
+
+
+int testing;
+
+
+void fatal_error(char *msg)
+{
+ printf("FATAL ERROR IN STAGE1: %s\n\nI can't recover from this, please reboot manually and send bugreport.\n", msg);
+ while (1);
+}
+
+void process_cmdline(void)
+{
+ char buf[512];
+ int fd;
+ int size;
+
+
+ log_message("opening /proc/cmdline... ");
+
+ if ((fd = open("/proc/cmdline", O_RDONLY, 0)) < 0) fatal_error("could not open /proc/cmdline");
+
+ size = read(fd, buf, sizeof(buf) - 1);
+ buf[size] = '\0';
+ close(fd);
+
+ log_message("\t%s", buf);
+}
+
+
+#ifdef SPAWN_SHELL
+/* spawns a shell on console #2 */
+void spawn_shell(void)
+{
+ pid_t pid;
+ int fd;
+ char * shell_name = "/sbin/sash";
+
+ if (!testing)
+ {
+ fd = open("/dev/tty2", O_RDWR);
+ if (fd < 0)
+ {
+ log_message("cannot open /dev/tty2 -- no shell will be provided");
+ return;
+ }
+ else
+ if (access(shell_name, X_OK))
+ {
+ log_message("cannot open shell - /usr/bin/sh doesn't exist");
+ return;
+ }
+
+ if (!(pid = fork()))
+ {
+ dup2(fd, 0);
+ dup2(fd, 1);
+ dup2(fd, 2);
+
+ close(fd);
+ setsid();
+ if (ioctl(0, TIOCSCTTY, NULL))
+ perror("could not set new controlling tty");
+
+ execl(shell_name, shell_name, NULL);
+ log_message("execl of %s failed: %s", shell_name, strerror(errno));
+ }
+
+ close(fd);
+ }
+ else
+ log_message("I should be spawning a shell");
+}
+#endif
+
+
+int
+main(int argc, char **argv)
+{
+ /* getpid() != 1 should work, by linuxrc tends to get a larger pid */
+ testing = (getpid() > 50);
+
+ open_log(testing);
+
+ log_message("welcome to the Linux-Mandrake install (stage1, version " VERSION " built " __DATE__ " " __TIME__")");
+
+ process_cmdline();
+ spawn_shell();
+
+
+ printf("Temporary end of stage1 binary -- entering an infinite loop\n");
+ log_message("Temporary end of stage1 binary -- entering an infinite loop");
+ while(1);
+
+ return 0;
+}