diff options
author | brucec <brucec@FreeBSD.org> | 2010-08-17 09:39:06 +0000 |
---|---|---|
committer | brucec <brucec@FreeBSD.org> | 2010-08-17 09:39:06 +0000 |
commit | 8d54dbc4591e4b62384caa7d630faa4299ee25b5 (patch) | |
tree | dddcbea3eb4b045482f04c13e365e39ed7d2049f /usr.sbin/sysinstall/main.c | |
parent | 5a79777b4407edd39781e06216e4dc6ca68bb6a7 (diff) | |
download | FreeBSD-src-8d54dbc4591e4b62384caa7d630faa4299ee25b5.zip FreeBSD-src-8d54dbc4591e4b62384caa7d630faa4299ee25b5.tar.gz |
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
Diffstat (limited to 'usr.sbin/sysinstall/main.c')
-rw-r--r-- | usr.sbin/sysinstall/main.c | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/usr.sbin/sysinstall/main.c b/usr.sbin/sysinstall/main.c index 47cbbcd..3f9164a 100644 --- a/usr.sbin/sysinstall/main.c +++ b/usr.sbin/sysinstall/main.c @@ -56,12 +56,42 @@ main(int argc, char **argv) int choice, scroll, curr, max, status; char titlestr[80], *arch, *osrel, *ostype; struct rlimit rlim; - + char *arg; + int i; + int optionArgs = 0; + /* Record name to be able to restart */ 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 */ - if (getpid() == 1) { + if (RunningAsInit) { signal(SIGBUS, screech); signal(SIGSEGV, screech); } @@ -105,13 +135,8 @@ main(int argc, char **argv) if (!RunningAsInit) installEnvironment(); - if (argc > 1 && !strcmp(argv[1], "-fake")) { - variable_set2(VAR_DEBUG, "YES", 0); - Fake = TRUE; + if (Fake) 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 */ 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") */ if (!RunningAsInit) { - int i, start_arg; - - 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++) { + for (i = optionArgs+1; i < argc; i++) { if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS) 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); } else @@ -187,7 +207,7 @@ main(int argc, char **argv) while (1) { choice = scroll = curr = max = 0; dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE); - if (getpid() != 1 + if (!RunningAsInit #if defined(__sparc64__) || !msgNoYes("Are you sure you wish to exit? The system will halt.") #else |