summaryrefslogtreecommitdiffstats
path: root/loader2/shutdown.c
diff options
context:
space:
mode:
authorJeremy Katz <katzj@redhat.com>2003-04-24 15:46:31 +0000
committerJeremy Katz <katzj@redhat.com>2003-04-24 15:46:31 +0000
commit0a562126d84c59a113231ae7ab38984f92d62153 (patch)
tree5e87b9094f4ebdc328979e3a0640dee5f1fc40cb /loader2/shutdown.c
parentdd200d781bd9012f562399c2ee69c23fe60d86b9 (diff)
downloadanaconda-0a562126d84c59a113231ae7ab38984f92d62153.tar.gz
anaconda-0a562126d84c59a113231ae7ab38984f92d62153.tar.xz
anaconda-0a562126d84c59a113231ae7ab38984f92d62153.zip
another taroon merge. tagged before as before-taroon-merge, after as
after-taroon-merge this one adds s390 fixes, basic i/p series platform support, support for multiple kernels and one second stage, cmdline kickstart mode (nice for s390), some warning cleanups.
Diffstat (limited to 'loader2/shutdown.c')
-rw-r--r--loader2/shutdown.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/loader2/shutdown.c b/loader2/shutdown.c
new file mode 100644
index 000000000..33dab7bad
--- /dev/null
+++ b/loader2/shutdown.c
@@ -0,0 +1,108 @@
+/*
+ * shutdown.c
+ *
+ * Shutdown a running system. If built with -DAS_SHUTDOWN=1, then
+ * it builds a standalone shutdown binary.
+ *
+ * Copyright 1996 - 2003 Red Hat, Inc.
+ *
+ * This software may be freely redistributed under the terms of the GNU
+ * public license.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/reboot.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifdef AS_SHUTDOWN
+int testing = 0;
+#else
+extern int testing;
+#endif
+
+void disableSwap(void);
+void unmountFilesystems(void);
+
+
+void shutDown(int noKill, int doReboot) {
+ sync(); sync();
+
+ if (!testing && !noKill) {
+ printf("sending termination signals...");
+ kill(-1, 15);
+ sleep(2);
+ printf("done\n");
+
+ printf("sending kill signals...");
+ kill(-1, 9);
+ sleep(2);
+ printf("done\n");
+ }
+
+ printf("disabling swap...\n");
+ disableSwap();
+
+ printf("unmounting filesystems...\n");
+ unmountFilesystems();
+
+ if (doReboot) {
+ printf("rebooting system\n");
+ sleep(2);
+
+#if USE_MINILIBC
+ reboot(0xfee1dead, 672274793, 0x1234567);
+#else
+ reboot(RB_AUTOBOOT);
+#endif
+ } else {
+ printf("you may safely reboot your system\n");
+#if !defined(__s390__) && !defined(__s390x__)
+ while (1);
+#else
+ reboot(RB_HALT_SYSTEM);
+#endif
+ }
+
+ exit(0);
+
+ return;
+}
+
+#ifdef AS_SHUTDOWN
+int main(int argc, char ** argv) {
+ int fd;
+ int doReboot = 0;
+ int i = 1;
+
+ while (i < argc) {
+ if (!strncmp("-r", argv[i], 2))
+ doReboot = 1;
+ i++;
+ }
+
+ /* ignore some signals so we don't kill ourself */
+ signal(SIGINT, SIG_IGN);
+ signal(SIGTSTP, SIG_IGN);
+
+ /* now change to / */
+ chdir("/");
+
+ /* redirect output to the real console */
+ fd = open("/dev/console", O_RDWR);
+ dup2(fd, 0);
+ dup2(fd, 1);
+ dup2(fd, 2);
+ close(fd);
+
+ shutDown(0, doReboot);
+}
+#endif