Latest changes from me. Over to you Paul...

This commit is contained in:
Poul-Henning Kamp 1994-10-21 02:14:54 +00:00
parent 091b0456f4
commit 4752baca4a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=3746
7 changed files with 164 additions and 154 deletions

View File

@ -5,7 +5,7 @@ NOMAN= yet
.PATH: /usr/src/sbin/disklabel .PATH: /usr/src/sbin/disklabel
SRCS = stage1.c dkcksum.c bootarea.c mbr.c \ SRCS = stage1.c dkcksum.c bootarea.c mbr.c \
utils.c termcap.c \ utils.c termcap.c exec.c \
stage0.c stage2.c stage3.c main.c stage0.c stage2.c stage3.c main.c
CFLAGS += -Wall CFLAGS += -Wall

77
sbin/sysinstall/exec.c Normal file
View File

@ -0,0 +1,77 @@
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
* $Id: utils.c,v 1.4 1994/10/20 19:30:56 ache Exp $
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <dialog.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/param.h>
#include <sys/mount.h>
#include "sysinstall.h"
int
exec(int magic, char *cmd, char *args, ...)
{
int pid, w, status;
char *argv[EXEC_MAXARG];
int arg = 0;
int no_args = 0;
va_list ap;
struct stat dummy;
int i;
if (stat(cmd, &dummy) == -1) {
sprintf(errmsg, "Executable %s does not exist\n", cmd);
return(-1);
}
va_start(ap, args);
argv[arg++] = (char *)args;
do {
if (arg >= EXEC_MAXARG)
Fatal("Too many arguments");
} while ((argv[arg++] = va_arg(ap, char *)));
va_end(ap);
if ((pid = fork()) == 0) {
switch (magic) {
case 1:
close(0);
i = open("/file.list",O_RDONLY);
if (i != 0) {
perror("/etc/file.list");
exit(2);
}
break;
default:
break;
}
execv(cmd, argv);
exit(1);
}
while ((w = wait(&status)) != pid && w != -1)
;
if (w == -1)
Fatal("Child process %s terminated abnormally\n", cmd);
return(status);
}

View File

@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: main.c,v 1.4 1994/10/20 06:48:39 phk Exp $ * $Id: main.c,v 1.5 1994/10/20 19:30:50 ache Exp $
* *
*/ */
@ -20,6 +20,7 @@
#include <dialog.h> #include <dialog.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/reboot.h>
#define EXTERN /* only in main.c */ #define EXTERN /* only in main.c */
@ -90,7 +91,7 @@ main(int argc, char **argv)
if (alloc_memory() < 0) if (alloc_memory() < 0)
Fatal("No memory\n"); Fatal("No memory\n");
setjmp(jmp_restart); setjmp(jmp_restart); /* XXX Allow people to "restart" */
if (getenv("STAGE0") || !access("/this_is_boot_flp",R_OK)) { if (getenv("STAGE0") || !access("/this_is_boot_flp",R_OK)) {
stage0(); stage0();
@ -113,10 +114,11 @@ main(int argc, char **argv)
*/ */
stage2(); stage2();
} else if (getenv("STAGE3")) { reboot(RB_AUTOBOOT);
} else if (getenv("STAGE3") || !access("/this_is_hd",R_OK)) {
stage3(); stage3();
} else { } else {
fprintf(stderr,"Must setenv STAGE0 or STAGE3\n"); Fatal("Must setenv STAGE0 or STAGE3");
} }
return 0; return 0;
} }

View File

@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: stage2.c,v 1.2 1994/10/20 06:48:40 phk Exp $ * $Id: stage2.c,v 1.3 1994/10/20 19:30:53 ache Exp $
* *
*/ */
@ -33,7 +33,8 @@ stage2()
char **p,**q; char **p,**q;
char pbuf[90]; char pbuf[90];
char dbuf[90]; char dbuf[90];
int i,j; FILE *f1, *f2;
int i;
for(q=mountpoint,p = devicename; *p; p++,q++) { for(q=mountpoint,p = devicename; *p; p++,q++) {
if(!strcmp(*q,"swap")) if(!strcmp(*q,"swap"))
@ -41,60 +42,62 @@ stage2()
TellEm("newfs /dev/r%s",*p); TellEm("newfs /dev/r%s",*p);
strcpy(pbuf, "/dev/r"); strcpy(pbuf, "/dev/r");
strcat(pbuf, *p); strcat(pbuf, *p);
if (exec("/bin/newfs","/bin/newfs", pbuf, 0) == -1) i = exec(0, "/bin/newfs", "/bin/newfs", pbuf, 0);
Fatal(errmsg); if (i)
Fatal("Exec(/bin/newfs) failed, code=%d.",i);
} }
for(q=mountpoint,p = devicename; *p; p++,q++) { for(q=mountpoint,p = devicename; *p; p++,q++) {
if(!strcmp(*q,"swap"))
continue;
MountUfs(*p, "/mnt", *q, 1); MountUfs(*p, "/mnt", *q, 1);
} }
TellEm("cpio -dumpv /mnt < file.list"); TellEm("cpio -dumpv /mnt < file.list");
if (exec("/bin/cpio","/bin/cpio", "-dumpv", "/mnt", 0) == -1) i = exec(1, "/bin/cpio", "/bin/cpio", "-dumpv", "/mnt", 0);
Fatal(errmsg); if (i)
Fatal("Exec(/bin/cpio) failed, code=%d.",i);
TellEm("write /mnt/etc/fstab"); TellEm("Making /mnt/etc/fstab");
i = open("/mnt/etc/fstab",O_CREAT|O_TRUNC|O_APPEND|O_WRONLY,0644); f1 = fopen("/mnt/etc/fstab","w");
if(i < 0) { if(!f1)
Fatal("Couldn't open /mnt/etc/fstab for writing"); Fatal("Couldn't open /mnt/etc/fstab for writing.");
}
/* This file is our own. It serves several jobs */ /* This file is our own. It serves several jobs */
j = open("/mnt/this_is_hd",O_CREAT|O_TRUNC|O_APPEND|O_WRONLY,0644); f2 = fopen("/mnt/this_is_hd","w");
if(j < 0) { if(!f2)
Fatal("Couldn't open /mnt/this_is_hd for writing"); Fatal("Couldn't open /mnt/this_is_hd for writing.");
}
TellEm("Writing filesystems");
for(q=mountpoint,p = devicename; *p; p++,q++) { for(q=mountpoint,p = devicename; *p; p++,q++) {
sprintf(pbuf,"%s\n%s\n",*p,*q);
write(j,pbuf,strlen(pbuf));
if(!strcmp(*q,"swap")) if(!strcmp(*q,"swap"))
continue; continue;
sprintf(pbuf,"/dev/%s\t\t%s\tufs rw 1 1\n",*p,*q); fprintf(f2,"%s\n%s\n",*p,*q);
write(i,pbuf,strlen(pbuf)); fprintf(f1,"/dev/%s\t\t%s\tufs rw 1 1\n",*p,*q);
} }
TellEm("Writing swap-devs");
for(q=mountpoint,p = devicename; *p; p++,q++) { for(q=mountpoint,p = devicename; *p; p++,q++) {
if(strcmp(*q,"swap")) if(strcmp(*q,"swap"))
continue; continue;
sprintf(pbuf,"/dev/%s\t\tnone\tswap sw 0 0\n",*p); fprintf(f1,"/dev/%s\t\tnone\tswap sw 0 0\n",*p);
write(i,pbuf,strlen(pbuf));
} }
close(i); TellEm("Writing procfs");
write(j,"\n",1); fprintf(f1,"proc\t\t/proc\tprocfs rw 0 0\n");
close(j); fclose(f1);
sprintf(pbuf,"proc\t\t/proc\tprocfs rw 0 0\n"); fclose(f2);
write(i,pbuf,strlen(pbuf));
/* we have to unmount in reverse order */ /* we have to unmount in reverse order */
for(p = mountpoint; *p; p++) for(p = mountpoint; *p; p++)
continue; continue;
TellEm("Unmount disks");
for(p--;p >= mountpoint;p--) { for(p--;p >= mountpoint;p--) {
if(!strcmp(*q,"swap")) if(!strcmp(*p,"swap"))
continue; continue;
strcpy(dbuf,"/mnt"); strcpy(dbuf,"/mnt");
strcat(dbuf,*p); strcat(dbuf,*p);
TellEm("unmount %s",dbuf); TellEm("unmount %s",dbuf);
if (unmount("/mnt", 0) == -1) if (unmount(dbuf, 0) == -1)
Fatal("Error unmounting /mnt: %s", strerror(errno)); Fatal("Error unmounting %s.",dbuf);
} }
} }

View File

@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: stage3.c,v 1.2 1994/10/20 04:59:58 phk Exp $ * $Id: stage3.c,v 1.3 1994/10/20 19:30:53 ache Exp $
* *
*/ */
@ -37,10 +37,9 @@
void void
stage3() stage3()
{ {
char *diskname; char pbuf[90];
struct ufs_args ufsargs; char dbuf[90];
char *s; FILE *f;
int i;
/* /*
* Extract the disk-name from /etc/fstab, we wrote it ourselves, * Extract the disk-name from /etc/fstab, we wrote it ourselves,
@ -48,76 +47,38 @@ stage3()
* XXX: Multidisk installs. We need to mount all partitions. * XXX: Multidisk installs. We need to mount all partitions.
*/ */
i = open("/etc/fstab", O_RDONLY); f = fopen("/this_is_hd","r");
if (i < 0) { if (!f) {
Fatal("Couldn't open /etc/fstab"); Fatal("Couldn't open /this_is_hd");
} }
read(i, scratch, 100); while(fgets(dbuf,sizeof pbuf, f)) {
for (s = scratch; *s != ' ' && *s != '\t'; s++); dbuf[strlen(dbuf)-1] = 0;
s--; fgets(pbuf,sizeof pbuf, f);
*s = '\0'; pbuf[strlen(pbuf)-1] = 0;
s = scratch + 5; MountUfs(dbuf,0,pbuf,0);
diskname = malloc(strlen(s) + 1);
if (!diskname) {
Fatal("malloc failed");
} }
strcpy(diskname, s); fclose(f);
close(i);
Mkdir("/proc");
Mkdir("/root");
Mkdir("/var");
Mkdir("/var/run");
sprintf(scratch, "mount -u /dev/%sa /", diskname);
TellEm(scratch);
sprintf(scratch, "/dev/%sa", diskname);
ufsargs.fspec = scratch;
if (mount(MOUNT_UFS, "/", MNT_UPDATE, (caddr_t) & ufsargs) == -1) {
sprintf(errmsg, "Failed to mount root read/write: %s\n%s", strerror(errno), ufsargs.fspec);
Fatal(errmsg);
}
sprintf(scratch, "mount /dev/%se /usr", diskname);
TellEm(scratch);
sprintf(scratch, "/dev/%se", diskname);
ufsargs.fspec = scratch;
if (mount(MOUNT_UFS, "/usr", 0, (caddr_t) & ufsargs) == -1) {
sprintf(errmsg, "Failed to mount /usr: %s\n%s", strerror(errno), ufsargs.fspec);
Fatal(errmsg);
}
TellEm("mkdir /proc");
if (mkdir("/proc", S_IRWXU) == -1) {
sprintf(errmsg, "Couldn't create directory /proc: %s\n",
strerror(errno));
Fatal(errmsg);
}
TellEm("mkdir /root");
if (mkdir("/root", S_IRWXU) == -1) {
sprintf(errmsg, "Couldn't create directory /root: %s\n",
strerror(errno));
Fatal(errmsg);
}
TellEm("mkdir /var");
if (mkdir("/var", S_IRWXU) == -1) {
sprintf(errmsg, "Couldn't create directory /var: %s\n",
strerror(errno));
Fatal(errmsg);
}
TellEm("mkdir /var/run");
if (mkdir("/var/run", S_IRWXU) == -1) {
sprintf(errmsg, "Couldn't create directory /var/run: %s\n",
strerror(errno));
Fatal(errmsg);
}
sprintf(scratch, "Insert CPIO floppy in floppy drive 0\n"); sprintf(scratch, "Insert CPIO floppy in floppy drive 0\n");
dialog_msgbox("Stage 2 installation", scratch, 6, 75, 1); dialog_msgbox("Stage 2 installation", scratch, 6, 75, 1);
ufsargs.fspec = "/dev/fd0a";
if (mount(MOUNT_UFS, "/mnt", MNT_RDONLY, (caddr_t) & ufsargs) == -1) { MountUfs("/dev/fd0a",0,"/mnt",0);
sprintf(errmsg, "Failed to mount /mnt: %s\n%s", strerror(errno), ufsargs.fspec);
Fatal(errmsg);
}
TellEm("sh -c 'cd / ; gunzip < /mnt/inst2.cpio.gz | cpio -idum'"); TellEm("sh -c 'cd / ; gunzip < /mnt/inst2.cpio.gz | cpio -idum'");
if (exec("/bin/sh", "/bin/sh", "-e", "-c",
if (exec(0, "/bin/sh",
"/bin/sh", "-e", "-c",
"cd / ; gunzip < /mnt/inst2.cpio.gz | cpio -idum", 0) == -1) "cd / ; gunzip < /mnt/inst2.cpio.gz | cpio -idum", 0) == -1)
Fatal(errmsg); Fatal(errmsg);
TellEm("sh -c 'cd /mnt ; ls install magic | cpio -dump /'"); TellEm("sh -c 'cd /mnt ; ls install magic | cpio -dump /'");
if (exec("/bin/sh", "/bin/sh", "-e", "-c",
if (exec(0, "/bin/sh",
"/bin/sh", "-e", "-c",
"cd /mnt ; ls magic | cpio -dump /", 0) == -1) "cd /mnt ; ls magic | cpio -dump /", 0) == -1)
Fatal(errmsg); Fatal(errmsg);
@ -127,7 +88,8 @@ stage3()
Fatal(errmsg); Fatal(errmsg);
} }
TellEm("sh -c 'cd /dev ; sh MAKEDEV all'"); TellEm("sh -c 'cd /dev ; sh MAKEDEV all'");
if (exec("/bin/sh", "/bin/sh", "-e", "-c", if (exec(0, "/bin/sh",
"/bin/sh", "-e", "-c",
"PATH=/bin:/sbin:/usr/bin:/usr/sbin; export PATH ; cd /dev ; sh MAKEDEV all", 0) == -1) "PATH=/bin:/sbin:/usr/bin:/usr/sbin; export PATH ; cd /dev ; sh MAKEDEV all", 0) == -1)
Fatal(errmsg); Fatal(errmsg);
@ -141,5 +103,5 @@ stage3()
close(0); close(0);
close(1); close(1);
close(2); close(2);
execl("/sbin/init", "init", 0); execl(0,"/sbin/init", "init", 0);
} }

View File

@ -68,8 +68,12 @@ void *Malloc __P((size_t size));
char *StrAlloc __P((char *str)); char *StrAlloc __P((char *str));
void Fatal __P((char *fmt, ...)); void Fatal __P((char *fmt, ...));
int AskAbort __P((char *fmt, ...)); int AskAbort __P((char *fmt, ...));
int exec __P((char *cmd, char *args, ...));
void MountUfs __P((char *device, char *prefix, char *mountpoint, int do_mkdir)); void MountUfs __P((char *device, char *prefix, char *mountpoint, int do_mkdir));
void Mkdir __P((char *path));
/* exec.c */
int exec __P((int magic, char *cmd, char *args, ...));
#define EXEC_MAXARG 100
/* stage0.c */ /* stage0.c */
void stage0 __P((void)); void stage0 __P((void));

View File

@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: utils.c,v 1.3 1994/10/20 06:48:40 phk Exp $ * $Id: utils.c,v 1.4 1994/10/20 19:30:56 ache Exp $
* *
*/ */
@ -43,11 +43,13 @@ void
Fatal(char *fmt, ...) Fatal(char *fmt, ...)
{ {
char *p; char *p;
int i = errno;
va_list ap; va_list ap;
p = Malloc(2048); p = Malloc(2048);
va_start(ap,fmt); va_start(ap,fmt);
vsnprintf(p, 2048, fmt, ap); vsnprintf(p, 2048, fmt, ap);
va_end(ap); va_end(ap);
sprintf(p+strlen(p),"\nErrno= %d, %s.",i,strerror(i));
dialog_msgbox("Fatal", p, 12, 75, 1); dialog_msgbox("Fatal", p, 12, 75, 1);
free(p); free(p);
end_dialog(); end_dialog();
@ -90,52 +92,6 @@ StrAlloc(char *str)
return p; return p;
} }
int
exec(char *cmd, char *args, ...)
{
int pid, w, status;
char **argv = NULL;
int arg = 0;
int no_args = 0;
va_list ap;
struct stat dummy;
if (stat(cmd, &dummy) == -1) {
sprintf(errmsg, "Executable %s does not exist\n", cmd);
return(-1);
}
va_start(ap, args);
do {
if (arg == no_args) {
no_args += 10;
if (!(argv = realloc(argv, no_args * sizeof(char *)))) {
sprintf(errmsg, "Failed to allocate memory during exec of %s\n", cmd);
return(-1);
}
if (arg == 0)
argv[arg++] = (char *)args;
}
} while ((argv[arg++] = va_arg(ap, char *)));
va_end(ap);
if ((pid = fork()) == 0) {
execv(cmd, argv);
exit(1);
}
while ((w = wait(&status)) != pid && w != -1)
;
free(argv);
if (w == -1) {
sprintf(errmsg, "Child process %s terminated abnormally\n", cmd);
return(-1);
}
return(0);
}
void void
MountUfs(char *device, char *prefix, char *mountpoint, int do_mkdir) MountUfs(char *device, char *prefix, char *mountpoint, int do_mkdir)
{ {
@ -153,11 +109,7 @@ MountUfs(char *device, char *prefix, char *mountpoint, int do_mkdir)
strcat(pbuf,mountpoint); strcat(pbuf,mountpoint);
if(do_mkdir && access(pbuf,R_OK)) { if(do_mkdir && access(pbuf,R_OK)) {
TellEm("mkdir %s",pbuf); Mkdir(pbuf);
if (mkdir(pbuf,S_IRWXU) == -1) {
Fatal("Couldn't create directory %s: %s\n",
pbuf,strerror(errno));
}
} }
strcpy(dbuf,"/dev/"); strcpy(dbuf,"/dev/");
@ -170,3 +122,13 @@ MountUfs(char *device, char *prefix, char *mountpoint, int do_mkdir)
dbuf, pbuf, strerror(errno)); dbuf, pbuf, strerror(errno));
} }
} }
void
Mkdir(char *path)
{
TellEm("mkdir %s",path);
if (mkdir(path, S_IRWXU) == -1) {
Fatal("Couldn't create directory %s: %s\n",
path,strerror(errno));
}
}