mirror of
https://git.FreeBSD.org/src.git
synced 2025-02-05 18:05:16 +00:00
To restart, sysinstall calls execl. Since it will create a new process, we
can't check to see if sysinstall is running as init just by checking if the PID is 0. Introduce a new option that sets the RunningAsInit flag, and update the code to check RunningAsInit intstead of getpid(). PR: bin/38854 Submitted by: Peter Sedeffow <peter at trumanbrewery.com> Approved by: rrs (mentor) MFC after: 1 month
This commit is contained in:
parent
2793b01844
commit
3affea8f99
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=211417
@ -76,13 +76,10 @@ globalsInit(void)
|
|||||||
{
|
{
|
||||||
DebugFD = -1;
|
DebugFD = -1;
|
||||||
ColorDisplay = FALSE;
|
ColorDisplay = FALSE;
|
||||||
Fake = FALSE;
|
|
||||||
Restarting = FALSE;
|
|
||||||
OnVTY = FALSE;
|
OnVTY = FALSE;
|
||||||
DialogActive = FALSE;
|
DialogActive = FALSE;
|
||||||
VarHead = NULL;
|
VarHead = NULL;
|
||||||
mediaDevice = NULL;
|
mediaDevice = NULL;
|
||||||
RunningAsInit = FALSE;
|
|
||||||
|
|
||||||
HomeChunk = NULL;
|
HomeChunk = NULL;
|
||||||
RootChunk = NULL;
|
RootChunk = NULL;
|
||||||
|
@ -1274,7 +1274,7 @@ installVarDefaults(dialogMenuItem *self)
|
|||||||
variable_set2(VAR_FIXIT_TTY, "serial", 0);
|
variable_set2(VAR_FIXIT_TTY, "serial", 0);
|
||||||
variable_set2(VAR_PKG_TMPDIR, "/var/tmp", 0);
|
variable_set2(VAR_PKG_TMPDIR, "/var/tmp", 0);
|
||||||
variable_set2(VAR_MEDIA_TIMEOUT, itoa(MEDIA_TIMEOUT), 0);
|
variable_set2(VAR_MEDIA_TIMEOUT, itoa(MEDIA_TIMEOUT), 0);
|
||||||
if (getpid() != 1)
|
if (!RunningAsInit)
|
||||||
variable_set2(SYSTEM_STATE, "update", 0);
|
variable_set2(SYSTEM_STATE, "update", 0);
|
||||||
else
|
else
|
||||||
variable_set2(SYSTEM_STATE, "init", 0);
|
variable_set2(SYSTEM_STATE, "init", 0);
|
||||||
|
@ -56,12 +56,42 @@ main(int argc, char **argv)
|
|||||||
int choice, scroll, curr, max, status;
|
int choice, scroll, curr, max, status;
|
||||||
char titlestr[80], *arch, *osrel, *ostype;
|
char titlestr[80], *arch, *osrel, *ostype;
|
||||||
struct rlimit rlim;
|
struct rlimit rlim;
|
||||||
|
char *arg;
|
||||||
|
int i;
|
||||||
|
int optionArgs = 0;
|
||||||
|
|
||||||
/* Record name to be able to restart */
|
/* Record name to be able to restart */
|
||||||
StartName = argv[0];
|
StartName = argv[0];
|
||||||
|
|
||||||
|
Restarting = FALSE;
|
||||||
|
RunningAsInit = FALSE;
|
||||||
|
Fake = FALSE;
|
||||||
|
|
||||||
|
for (i = 1; i < argc; i++) {
|
||||||
|
arg = argv[i];
|
||||||
|
|
||||||
|
if (arg[0] != '-')
|
||||||
|
break;
|
||||||
|
|
||||||
|
optionArgs++;
|
||||||
|
|
||||||
|
if (!strcmp(arg, "-fake")) {
|
||||||
|
variable_set2(VAR_DEBUG, "YES", 0);
|
||||||
|
Fake = TRUE;
|
||||||
|
} else if (!strcmp(arg, "-restart")) {
|
||||||
|
Restarting = TRUE;
|
||||||
|
} else if (!strcmp(arg, "-fakeInit")) {
|
||||||
|
RunningAsInit = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
arg = argv[optionArgs+1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getpid() == 1)
|
||||||
|
RunningAsInit = TRUE;
|
||||||
|
|
||||||
/* Catch fatal signals and complain about them if running as init */
|
/* Catch fatal signals and complain about them if running as init */
|
||||||
if (getpid() == 1) {
|
if (RunningAsInit) {
|
||||||
signal(SIGBUS, screech);
|
signal(SIGBUS, screech);
|
||||||
signal(SIGSEGV, screech);
|
signal(SIGSEGV, screech);
|
||||||
}
|
}
|
||||||
@ -105,13 +135,8 @@ main(int argc, char **argv)
|
|||||||
if (!RunningAsInit)
|
if (!RunningAsInit)
|
||||||
installEnvironment();
|
installEnvironment();
|
||||||
|
|
||||||
if (argc > 1 && !strcmp(argv[1], "-fake")) {
|
if (Fake)
|
||||||
variable_set2(VAR_DEBUG, "YES", 0);
|
|
||||||
Fake = TRUE;
|
|
||||||
msgConfirm("I'll be just faking it from here on out, OK?");
|
msgConfirm("I'll be just faking it from here on out, OK?");
|
||||||
}
|
|
||||||
if (argc > 1 && !strcmp(argv[1], "-restart"))
|
|
||||||
Restarting = TRUE;
|
|
||||||
|
|
||||||
/* Try to preserve our scroll-back buffer */
|
/* Try to preserve our scroll-back buffer */
|
||||||
if (OnVTY) {
|
if (OnVTY) {
|
||||||
@ -140,19 +165,14 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
/* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */
|
/* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */
|
||||||
if (!RunningAsInit) {
|
if (!RunningAsInit) {
|
||||||
int i, start_arg;
|
for (i = optionArgs+1; i < argc; i++) {
|
||||||
|
|
||||||
if (!strstr(argv[0], "sysinstall"))
|
|
||||||
start_arg = 0;
|
|
||||||
else if (Fake || Restarting)
|
|
||||||
start_arg = 2;
|
|
||||||
else
|
|
||||||
start_arg = 1;
|
|
||||||
for (i = start_arg; i < argc; i++) {
|
|
||||||
if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS)
|
if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS)
|
||||||
systemShutdown(1);
|
systemShutdown(1);
|
||||||
}
|
}
|
||||||
if (argc > start_arg)
|
|
||||||
|
/* If we were given commands to process on the command line, just exit
|
||||||
|
* now */
|
||||||
|
if (argc > optionArgs+1)
|
||||||
systemShutdown(0);
|
systemShutdown(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -187,7 +207,7 @@ main(int argc, char **argv)
|
|||||||
while (1) {
|
while (1) {
|
||||||
choice = scroll = curr = max = 0;
|
choice = scroll = curr = max = 0;
|
||||||
dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE);
|
dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE);
|
||||||
if (getpid() != 1
|
if (!RunningAsInit
|
||||||
#if defined(__sparc64__)
|
#if defined(__sparc64__)
|
||||||
|| !msgNoYes("Are you sure you wish to exit? The system will halt.")
|
|| !msgNoYes("Are you sure you wish to exit? The system will halt.")
|
||||||
#else
|
#else
|
||||||
|
@ -233,7 +233,7 @@ msgFatal(char *fmt, ...)
|
|||||||
mvaddstr(StatusLine, 0, errstr);
|
mvaddstr(StatusLine, 0, errstr);
|
||||||
addstr(" - ");
|
addstr(" - ");
|
||||||
addstr("PRESS ANY KEY TO ");
|
addstr("PRESS ANY KEY TO ");
|
||||||
if (getpid() == 1)
|
if (RunningAsInit)
|
||||||
addstr("REBOOT");
|
addstr("REBOOT");
|
||||||
else
|
else
|
||||||
addstr("QUIT");
|
addstr("QUIT");
|
||||||
|
@ -59,13 +59,20 @@ static int
|
|||||||
intr_restart(dialogMenuItem *self)
|
intr_restart(dialogMenuItem *self)
|
||||||
{
|
{
|
||||||
int ret, fd, fdmax;
|
int ret, fd, fdmax;
|
||||||
|
char *arg;
|
||||||
|
|
||||||
mediaClose();
|
mediaClose();
|
||||||
free_variables();
|
free_variables();
|
||||||
fdmax = getdtablesize();
|
fdmax = getdtablesize();
|
||||||
for (fd = 3; fd < fdmax; fd++)
|
for (fd = 3; fd < fdmax; fd++)
|
||||||
close(fd);
|
close(fd);
|
||||||
ret = execl(StartName, StartName, "-restart", (char *)NULL);
|
|
||||||
|
if (RunningAsInit)
|
||||||
|
arg = "-restart -fakeInit";
|
||||||
|
else
|
||||||
|
arg = "-restart";
|
||||||
|
|
||||||
|
ret = execl(StartName, StartName, arg, NULL);
|
||||||
msgDebug("execl failed (%s)\n", strerror(errno));
|
msgDebug("execl failed (%s)\n", strerror(errno));
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
return -1;
|
return -1;
|
||||||
@ -148,11 +155,10 @@ systemInitialize(int argc, char **argv)
|
|||||||
variable_set2(VAR_DEBUG, "YES", 0);
|
variable_set2(VAR_DEBUG, "YES", 0);
|
||||||
|
|
||||||
/* Are we running as init? */
|
/* Are we running as init? */
|
||||||
if (getpid() == 1) {
|
if (RunningAsInit) {
|
||||||
struct ufs_args ufs_args;
|
struct ufs_args ufs_args;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
RunningAsInit = 1;
|
|
||||||
setsid();
|
setsid();
|
||||||
close(0);
|
close(0);
|
||||||
fd = open("/dev/ttyv0", O_RDWR);
|
fd = open("/dev/ttyv0", O_RDWR);
|
||||||
|
@ -105,7 +105,7 @@ set_termcap(void)
|
|||||||
else {
|
else {
|
||||||
int i, on;
|
int i, on;
|
||||||
|
|
||||||
if (getpid() == 1) {
|
if (RunningAsInit) {
|
||||||
DebugFD = open("/dev/ttyv1", O_WRONLY);
|
DebugFD = open("/dev/ttyv1", O_WRONLY);
|
||||||
if (DebugFD != -1) {
|
if (DebugFD != -1) {
|
||||||
on = 1;
|
on = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user