summaryrefslogtreecommitdiffstats
path: root/loader2
diff options
context:
space:
mode:
authorJeremy Katz <katzj@redhat.com>2004-06-21 22:40:03 +0000
committerJeremy Katz <katzj@redhat.com>2004-06-21 22:40:03 +0000
commit3c60d32a1b5bc689e60a4d4aa325dc2bd1d8ceeb (patch)
treed298f63e3517030143c86ea4a449f1e2b9db290e /loader2
parent33bf9726e7baa89b15f400cc44802e6deb69128e (diff)
downloadanaconda-3c60d32a1b5bc689e60a4d4aa325dc2bd1d8ceeb.tar.gz
anaconda-3c60d32a1b5bc689e60a4d4aa325dc2bd1d8ceeb.tar.xz
anaconda-3c60d32a1b5bc689e60a4d4aa325dc2bd1d8ceeb.zip
kickstart commands to control doing reboot/poweroff/halt at the end of an
install (#116414)
Diffstat (limited to 'loader2')
-rw-r--r--loader2/kickstart.c54
-rw-r--r--loader2/kickstart.h3
-rw-r--r--loader2/loader.c14
-rw-r--r--loader2/loader.h8
4 files changed, 73 insertions, 6 deletions
diff --git a/loader2/kickstart.c b/loader2/kickstart.c
index 8763a1ce9..20dc733d6 100644
--- a/loader2/kickstart.c
+++ b/loader2/kickstart.c
@@ -68,6 +68,12 @@ static void setCmdlineMode(struct loaderData_s * loaderData, int argc,
char ** argv, int * flagsPtr);
static void setSELinux(struct loaderData_s * loaderData, int argc,
char ** argv, int * flagsPtr);
+static void setPowerOff(struct loaderData_s * loaderData, int argc,
+ char ** argv, int * flagsPtr);
+static void setHalt(struct loaderData_s * loaderData, int argc,
+ char ** argv, int * flagsPtr);
+static void setShutdown(struct loaderData_s * loaderData, int argc,
+ char ** argv, int * flagsPtr);
void loadKickstartModule(struct loaderData_s * loaderData, int argc,
char ** argv, int * flagsPtr);
@@ -85,6 +91,9 @@ struct ksCommandNames ksTable[] = {
{ KS_CMD_DEVICE, "device", loadKickstartModule },
{ KS_CMD_CMDLINE, "cmdline", setCmdlineMode },
{ KS_CMD_SELINUX, "selinux", setSELinux },
+ { KS_CMD_POWEROFF, "poweroff", setPowerOff },
+ { KS_CMD_HALT, "halt", setHalt },
+ { KS_CMD_SHUTDOWN, "shutdown", setShutdown },
{ KS_CMD_NONE, NULL, NULL }
};
@@ -361,6 +370,51 @@ static void setSELinux(struct loaderData_s * loaderData, int argc,
return;
}
+static void setPowerOff(struct loaderData_s * loaderData, int argc,
+ char ** argv, int * flagsPtr) {
+ (*flagsPtr) = (*flagsPtr) | LOADER_FLAGS_POWEROFF;
+ return;
+}
+
+static void setHalt(struct loaderData_s * loaderData, int argc,
+ char ** argv, int * flagsPtr) {
+ (*flagsPtr) = (*flagsPtr) | LOADER_FLAGS_HALT;
+ return;
+}
+
+static void setShutdown(struct loaderData_s * loaderData, int argc,
+ char ** argv, int * flagsPtr) {
+ poptContext optCon;
+ int reboot = 0, halt = 0, poweroff = 0;
+ int rc;
+
+ struct poptOption ksOptions[] = {
+ { "reboot", 'r', POPT_ARG_NONE, &reboot, 0 },
+ { "halt", 'h', POPT_ARG_NONE, &halt, 0 },
+ { "poweroff", 'p', POPT_ARG_NONE, &poweroff, 0 },
+ { 0, 0, 0, 0, 0 }
+ };
+
+ optCon = poptGetContext(NULL, argc, (const char **) argv, ksOptions, 0);
+ if ((rc = poptGetNextOpt(optCon)) < -1) {
+ startNewt(*flagsPtr);
+ newtWinMessage(_("Kickstart Error"), _("OK"),
+ _("Bad argument to shutdown kickstart method "
+ "command %s: %s"),
+ poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
+ poptStrerror(rc));
+ return;
+ }
+
+
+ if (poweroff)
+ (*flagsPtr) = (*flagsPtr) | LOADER_FLAGS_POWEROFF;
+ if ((!poweroff && !reboot) || (halt))
+ (*flagsPtr) = (*flagsPtr) | LOADER_FLAGS_HALT;
+
+ return;
+}
+
void runKickstart(struct loaderData_s * loaderData,
int * flagsPtr) {
struct ksCommandNames * cmd;
diff --git a/loader2/kickstart.h b/loader2/kickstart.h
index ae4465648..fde6a5286 100644
--- a/loader2/kickstart.h
+++ b/loader2/kickstart.h
@@ -16,6 +16,9 @@
#define KS_CMD_CMDLINE 11
#define KS_CMD_GRAPHICAL 12
#define KS_CMD_SELINUX 13
+#define KS_CMD_POWEROFF 14
+#define KS_CMD_HALT 15
+#define KS_CMD_SHUTDOWN 16
int ksReadCommands(char * cmdFile, int flags);
int ksGetCommand(int cmd, char ** last, int * argc, char *** argv);
diff --git a/loader2/loader.c b/loader2/loader.c
index a29fcf86b..33d1657ed 100644
--- a/loader2/loader.c
+++ b/loader2/loader.c
@@ -574,8 +574,6 @@ static int parseCmdLineFlags(int flags, struct loaderData_s * loaderData,
loaderData->wepkey = strdup(argv[i] + 7);
else if (!strncasecmp(argv[i], "linksleep=", 10))
num_link_checks = atoi(argv[i] + 10);
- else if (!strncasecmp(argv[i], "allowcddma", 10))
- flags |= LOADER_FLAGS_ENABLECDDMA;
else if (!strncasecmp(argv[i], "selinux=0", 9))
flags &= ~LOADER_FLAGS_SELINUX;
else if (!strncasecmp(argv[i], "selinux", 7))
@@ -1501,6 +1499,18 @@ int main(int argc, char ** argv) {
else
rc = 0;
+ if ((rc == 0) && (FL_POWEROFF(flags) || FL_HALT(flags))) {
+ if (!(pid = fork())) {
+ char * cmd = (FL_POWEROFF(flags) ? strdup("/sbin/poweroff") :
+ strdup("/sbin/halt"));
+ execl(cmd, cmd, NULL);
+ fprintf(stderr, "exec of poweroff failed: %s",
+ strerror(errno));
+ exit(1);
+ }
+ waitpid(pid, &status, 0);
+ }
+
#if defined(__s390__) || defined(__s390x__)
/* FIXME: we have to send a signal to linuxrc on s390 so that shutdown
* can happen. this is ugly */
diff --git a/loader2/loader.h b/loader2/loader.h
index 112eb4d81..ddf66033f 100644
--- a/loader2/loader.h
+++ b/loader2/loader.h
@@ -13,6 +13,7 @@
#define LOADER_FLAGS_RESCUE (1 << 3)
#define LOADER_FLAGS_KICKSTART (1 << 4)
#define LOADER_FLAGS_KICKSTART_SEND_MAC (1 << 5)
+#define LOADER_FLAGS_POWEROFF (1 << 6)
#define LOADER_FLAGS_NOPROBE (1 << 7)
#define LOADER_FLAGS_MODDISK (1 << 8)
#define LOADER_FLAGS_ISA (1 << 9)
@@ -32,8 +33,7 @@
#define LOADER_FLAGS_NOFB (1 << 27)
#define LOADER_FLAGS_CMDLINE (1 << 28)
#define LOADER_FLAGS_GRAPHICAL (1 << 29)
-/* FIXME: this should go away */
-#define LOADER_FLAGS_ENABLECDDMA (1 << 13)
+#define LOADER_FLAGS_HALT (1 << 13)
#define LOADER_FLAGS_SELINUX (1 << 14)
#define FL_TESTING(a) ((a) & LOADER_FLAGS_TESTING)
@@ -42,6 +42,7 @@
#define FL_RESCUE(a) ((a) & LOADER_FLAGS_RESCUE)
#define FL_KICKSTART(a) ((a) & LOADER_FLAGS_KICKSTART)
#define FL_KICKSTART_SEND_MAC(a) ((a) & LOADER_FLAGS_KICKSTART_SEND_MAC)
+#define FL_POWEROFF(a) ((a) & LOADER_FLAGS_POWEROFF)
#define FL_NOPROBE(a) ((a) & LOADER_FLAGS_NOPROBE)
#define FL_MODDISK(a) ((a) & LOADER_FLAGS_MODDISK)
#define FL_ISA(a) ((a) & LOADER_FLAGS_ISA)
@@ -63,8 +64,7 @@
#define FL_NOFB(a) ((a) & LOADER_FLAGS_NOFB)
#define FL_GRAPHICAL(a) ((a) & LOADER_FLAGS_GRAPHICAL)
#define FL_CMDLINE(a) ((a) & LOADER_FLAGS_CMDLINE)
-/* FIXME: this should go away */
-#define FL_ENABLECDDMA(a) ((a) & LOADER_FLAGS_ENABLECDDMA)
+#define FL_HALT(a) ((a) & LOADER_FLAGS_HALT)
#define FL_SELINUX(a) ((a) & LOADER_FLAGS_SELINUX)