summaryrefslogtreecommitdiffstats
path: root/sbin/sysinstall/main.c
blob: d1db0e1c5eaba4afcfc8eb6f87021634bec90503 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * ----------------------------------------------------------------------------
 * "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: main.c,v 1.20 1995/01/30 03:19:52 phk Exp $
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>

#include <dialog.h>

#include <sys/ioctl.h>
#include <sys/reboot.h>

#define EXTERN /* only in main.c */

#include "sysinstall.h"

void
handle_intr(int sig)
{
	dialog_clear_norefresh();
	dialog_msgbox("User Interrupt",
		      "User interrupted.  Aborting the installation",
		      -1, -1, 1);
	ExitSysinstall();
}

int
main(int argc, char **argv)
{
	signal(SIGINT, SIG_IGN);

	/* Are we running as init? */
	cpio_fd = -1;
	if (getpid() == 1) {
		setsid();
		if (argc > 1 && strchr(argv[1],'C')) {
			/* Kernel told us that we are on a CDROM root */
			close(0); open("/bootcd/dev/console",O_RDWR);
			close(1); dup(0);
			close(2); dup(0);
			cpio_fd = open("/floppies/cpio.flp",O_RDONLY);
			on_cdrom++;
			chroot("/bootcd");
		} else {
			close(0); open("/dev/console",O_RDWR);
			close(1); dup(0);
			close(2); dup(0);
		}
		printf("sysinstall running as init\n\r");
		ioctl(0,TIOCSCTTY,(char *)NULL);
		setlogin("root");
		setbuf(stdin,0);
		setbuf(stdout,0);
		setbuf(stderr,0);
	}
	if (set_termcap() == -1) {
		Fatal("Can't find terminal entry\n");
	}
	/* XXX too early to use fatal ! */

	/* XXX - libdialog has particularly bad return value checking */
	init_dialog();
	/* If we haven't crashed I guess dialog is running ! */
	dialog_active = 1;

	signal(SIGINT, handle_intr);

	if (getpid() != 1) {
		stage0();
		stage1();
		end_dialog();
		dialog_active=0;
	} else if (!access("/this_is_boot_flp",R_OK)) {
		while(1) {
			stage0();
			if(!stage1())
				break;
		}
		stage2();
		end_dialog();
		dialog_active=0;
		reboot(RB_AUTOBOOT);
	} else {
		stage3();
		stage5();
	}
	return 0;
}
OpenPOWER on IntegriCloud