FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian Laptop

 
 
LinkBack Thread Tools
 
Old 04-06-2011, 08:10 PM
Chris Lumens
 
Default Remove all the custom shutdown/reboot/halt code in loader and init.

These decisions will now be made in anaconda proper. There's no need to
involve three separate processes in the discussion.
---
loader/init.c | 43 ---------
loader/kickstart.c | 25 ------
loader/loader.c | 48 ++---------
loader/loader.h | 6 +-
loader/shutdown.c | 217 -----------------------------------------------
loader/undomounts.c | 235 ---------------------------------------------------
6 files changed, 10 insertions(+), 564 deletions(-)
delete mode 100644 loader/shutdown.c
delete mode 100644 loader/undomounts.c

diff --git a/loader/init.c b/loader/init.c
index 02f3cd4..429eada 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -68,8 +68,6 @@
*
*/

-void shutDown(int doKill, reboot_action rebootAction);
-static int getKillPolicy(void);
struct termios ts;

static void printstr(char * string) {
@@ -146,34 +144,6 @@ static void termReset(void) {
printf("1733[0m33[100E
");
}

-/* reboot handler */
-static void sigintHandler(int signum) {
- termReset();
- shutDown(getKillPolicy(), REBOOT);
-}
-
-/* halt handler */
-static void sigUsr1Handler(int signum) {
- termReset();
- shutDown(getKillPolicy(), HALT);
-}
-
-/* poweroff handler */
-static void sigUsr2Handler(int signum) {
- termReset();
- shutDown(getKillPolicy(), POWEROFF);
-}
-
-static int getKillPolicy(void) {
- gpointer value = NULL;
-
- if (g_hash_table_lookup_extended(cmdline, "nokill", NULL, &value)) {
- return 0;
- }
-
- return 1;
-}
-
static void copyErrorFn (char *msg) {
printf(msg);
}
@@ -284,8 +254,6 @@ int main(int argc, char **argv) {
perror("setrlimit failed - no coredumps will be available");
}

- doKill = getKillPolicy();
-
#if !defined(__s390__) && !defined(__s390x__)
static struct termios orig_cmode;
static int orig_flags;
@@ -424,17 +392,8 @@ int main(int argc, char **argv) {

printf("running %s
", argvc[0]);
execve(argvc[0], argvc, env);
-
- shutDown(1, HALT);
}

- /* signal handlers for halt/poweroff */
- signal(SIGUSR1, sigUsr1Handler);
- signal(SIGUSR2, sigUsr2Handler);
-
- /* set up the ctrl+alt+delete handler to kill our pid, not pid 1 */
- signal(SIGINT, sigintHandler);
-
while (!doShutdown) {
pid_t childpid;
childpid = wait(&waitStatus);
@@ -466,8 +425,6 @@ int main(int argc, char **argv) {
shutdown_method = REBOOT;
}

- shutDown(doKill, shutdown_method);
-
return 0;
}

diff --git a/loader/kickstart.c b/loader/kickstart.c
index 3575ee4..c1187fb 100644
--- a/loader/kickstart.c
+++ b/loader/kickstart.c
@@ -67,7 +67,6 @@ extern uint64_t flags;

static void setDisplayMode(struct loaderData_s * loaderData, PyObject *handler);
static void setSELinux(struct loaderData_s * loaderData, PyObject *handler);
-static void setShutdown(struct loaderData_s * loaderData, PyObject *handler);
static void setMediaCheck(struct loaderData_s * loaderData, PyObject *handler);
static void setUpdates(struct loaderData_s * loaderData, PyObject *handler);
static void setVnc(struct loaderData_s * loaderData, PyObject *handler);
@@ -96,7 +95,6 @@ commandFunc_t ksTable[] = {
&setKickstartNetwork,
&setMediaCheck,
&setSELinux,
- &setShutdown,
&setUpdates,
&useKickstartDD,
NULL
@@ -538,29 +536,6 @@ static void setSELinux(struct loaderData_s * loaderData, PyObject *handler) {
Py_XDECREF(settingObj);
}

-static void setShutdown(struct loaderData_s * loaderData, PyObject *handler) {
- PyObject *rebootObj = getObject(constantsMod, "KS_REBOOT", 0);
- PyObject *shutdownObj = getObject(constantsMod, "KS_SHUTDOWN", 0);
- PyObject *settingObj = getattr(handler, "reboot", "action");
-
- if (!settingObj)
- goto cleanup;
-
- if (FL_NOKILL(flags))
- flags |= LOADER_FLAGS_HALT;
- else {
- if (settingObj == shutdownObj)
- flags |= LOADER_FLAGS_POWEROFF;
- else if (settingObj != rebootObj)
- flags |= LOADER_FLAGS_HALT;
- }
-
-cleanup:
- Py_XDECREF(rebootObj);
- Py_XDECREF(shutdownObj);
- Py_XDECREF(settingObj);
-}
-
static void setMediaCheck(struct loaderData_s * loaderData, PyObject *handler) {
PyObject *mediaCheckEnabled = getattr(handler, "mediacheck", "mediacheck");

diff --git a/loader/loader.c b/loader/loader.c
index 194975e..5043994 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -1878,7 +1878,7 @@ static void loadScsiDhModules(void)
}

int main(int argc, char ** argv) {
- int i, rc, pid, status;
+ int i, rc;
int isDevelMode = 0;

char * arg;
@@ -2364,9 +2364,9 @@ int main(int argc, char ** argv) {
}
}
}
-
+
*argptr = NULL;
-
+
stopNewt();
closeLog();

@@ -2377,45 +2377,13 @@ int main(int argc, char ** argv) {
}
printf(fmt, VERSION, getProductName());

- do {
- if (!(pid = fork())) {
- /* Create a new process group that we can easily kill off later. */
- setpgid(0, 0);
- /* This is where the Anaconda python process is started. */
- if (execv(anacondaArgs[0], anacondaArgs) == -1) {
- fprintf(stderr,"exec of anaconda failed: %m
");
- doExit(1);
- }
- }
- waitpid(pid, &status, 0);
- } while (restart_anaconda(&loaderData));
-
- if (!WIFEXITED(status) || (WIFEXITED(status) && WEXITSTATUS(status))) {
- rc = 1;
- } 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"));
- if (execl(cmd, cmd, NULL) == -1) {
- fprintf(stderr, "exec of poweroff failed: %m
");
- doExit(1);
- }
- }
- waitpid(pid, &status, 0);
+ /* Just replace the current process with anaconda. */
+ if (execv(anacondaArgs[0], anacondaArgs) == -1){
+ fprintf(stderr, "exec of anaconda failed: %m
");
+ doExit(1);
}

- stop_fw_loader(&loaderData);
-#if defined(__s390__) || defined(__s390x__)
- /* at the latest possibility signal init=linuxrc.s390 to reboot/halt */
- logMessage(INFO, "Sending signal %d to process %d
",
- init_sig, init_pid);
- kill(init_pid, init_sig);
-#endif
- doExit(rc);
+ doExit(0);
}

/* vim:set sw=4 sts=4 et: */
diff --git a/loader/loader.h b/loader/loader.h
index 6d3aac1..d761a4a 100644
--- a/loader/loader.h
+++ b/loader/loader.h
@@ -33,14 +33,14 @@
#define LOADER_FLAGS_RESCUE (((uint64_t) 1) << 3)
#define LOADER_FLAGS_KICKSTART (((uint64_t) 1) << 4)
#define LOADER_FLAGS_KICKSTART_SEND_MAC (((uint64_t) 1) << 5)
-#define LOADER_FLAGS_POWEROFF (((uint64_t) 1) << 6)
+/* #6 unused */
#define LOADER_FLAGS_NOPROBE (((uint64_t) 1) << 7)
#define LOADER_FLAGS_MODDISK (((uint64_t) 1) << 8)
#define LOADER_FLAGS_EARLY_NETWORKING (((uint64_t) 1) << 9)
#define LOADER_FLAGS_SERIAL (((uint64_t) 1) << 10)
#define LOADER_FLAGS_UPDATES (((uint64_t) 1) << 11)
#define LOADER_FLAGS_KSFILE (((uint64_t) 1) << 12)
-#define LOADER_FLAGS_HALT (((uint64_t) 1) << 13)
+/* #13 unused */
#define LOADER_FLAGS_SELINUX (((uint64_t) 1) << 14)
#define LOADER_FLAGS_VIRTPCONSOLE (((uint64_t) 1) << 15)
/* #16 unused */
@@ -77,7 +77,6 @@
#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_EARLY_NETWORKING(a) ((a) & LOADER_FLAGS_EARLY_NETWORKING)
@@ -90,7 +89,6 @@
#define FL_ASKMETHOD(a) ((a) & LOADER_FLAGS_ASKMETHOD)
#define FL_GRAPHICAL(a) ((a) & LOADER_FLAGS_GRAPHICAL)
#define FL_CMDLINE(a) ((a) & LOADER_FLAGS_CMDLINE)
-#define FL_HALT(a) ((a) & LOADER_FLAGS_HALT)
#define FL_SELINUX(a) ((a) & LOADER_FLAGS_SELINUX)
#define FL_VIRTPCONSOLE(a) ((a) & LOADER_FLAGS_VIRTPCONSOLE)
#define FL_ASKNETWORK(a) ((a) & LOADER_FLAGS_ASKNETWORK)
diff --git a/loader/shutdown.c b/loader/shutdown.c
deleted file mode 100644
index 8535a1b..0000000
--- a/loader/shutdown.c
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * shutdown.c
- *
- * Shutdown a running system. If built with -DAS_SHUTDOWN=1, then
- * it builds a standalone shutdown binary.
- *
- * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <fcntl.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/reboot.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#include "init.h"
-
-void disableSwap(void);
-void unmountFilesystems(void);
-
-static void performTerminations(void) {
- /* First of all kill everything in the anaconda process group. This won't
- hit any daemons spawned from anaconda, those usually call setsid(). */
- char buf[256];
- int fd, anaconda_pid = 0;
- if ((fd = open("/var/run/anaconda.pid", O_RDONLY)) >= 0 ) {
- if (read(fd, buf, 256) > 0) {
- anaconda_pid = atol(buf);
- }
- }
- if (anaconda_pid > 0) {
- printf("terminating anaconda...");
- kill(-anaconda_pid, SIGTERM);
- printf("done
");
- }
-
- /* Next, kill everything except what is inside the init's session or
- excluded in donotkill. */
- FILE *f;
- char *donotkill[] = {"mdmon", "NetworkManager", "dhclient", NULL};
- char omit[256], oarg[64];
- char **procname, *pid;
- /* find some pids so we can omit them from killall5 */
- *omit = '';
- for (procname=donotkill; *procname; procname++) {
- sprintf(buf, "/sbin/pidof %s", *procname);
- if ((f = popen(buf, "r")) != NULL) {
- if (fgets(buf, sizeof(buf), f) != NULL) {
- buf[strcspn(buf,"
")] = '';
- pid = strtok(buf, " ");
- while (pid) {
- sprintf(oarg, " -o %s", pid);
- strcat(omit, oarg);
- pid = strtok(NULL, " ");
- }
- }
-
- fclose(f);
- }
- }
-
- sync();
- printf("sending termination signals...");
- fflush(stdout);
- sprintf(buf, "/sbin/killall5 -15%s", omit);
- system(buf);
- sleep(2);
- printf("done
");
-
- printf("sending kill signals...");
- fflush(stdout);
- sprintf(buf, "/sbin/killall5 -9%s", omit);
- system(buf);
- sleep(2);
- printf("done
");
-}
-
-static void performUnmounts(void) {
- int status;
- struct stat st_buf;
-
- printf("disabling swap...
");
- disableSwap();
-
- printf("unmounting filesystems...
");
- unmountFilesystems();
-
- /* We've lost /mnt/runtime where /lib is a link to put the old
- /lib back so that our mdadm invocation below works. */
- if (lstat("/lib64", &st_buf) == 0) {
- unlink("/lib64");
- rename("/lib64_old", "/lib64");
- } else {
- unlink("/lib");
- rename("/lib_old", "/lib");
- }
- unlink("/usr");
- rename("/usr_old", "/usr");
-
- printf("waiting for mdraid sets to become clean...
");
- status = system("/sbin/mdadm --wait-clean --scan");
- if (!WIFEXITED(status))
- printf("Error: mdadm did not terminate normally
");
- else if (WEXITSTATUS(status))
- printf("Error: mdadm exited with status: %d
",
- WEXITSTATUS(status));
-}
-
-static void performReboot(reboot_action rebootAction) {
- switch (rebootAction) {
- case POWEROFF:
- printf("powering off system
");
- sleep(2);
- reboot(RB_POWER_OFF);
- break;
- case REBOOT:
- printf("rebooting system
");
- sleep(2);
-#if USE_MINILIBC
- reboot(0xfee1dead, 672274793, 0x1234567);
-#else
- reboot(RB_AUTOBOOT);
-#endif
- break;
- case HALT:
- printf("halting system
");
- reboot(RB_HALT_SYSTEM);
- break;
- default:
- break;
- }
-}
-
-static void performDelayedReboot()
-{
- printf("The system will be rebooted when you press Ctrl-C or Ctrl-Alt-Delete.
");
- while (1) {
- sleep(1);
- }
-}
-
-void shutDown(int doKill, reboot_action rebootAction)
-{
- static int reentered = 0;
-
- if (reentered) {
- performTerminations();
- performUnmounts();
- performReboot(rebootAction);
- }
- reentered = 1;
- if (rebootAction != DELAYED_REBOOT && doKill) {
- performTerminations();
- performUnmounts();
- performReboot(rebootAction);
- } else {
- performDelayedReboot();
- }
- exit(0);
-}
-
-#ifdef AS_SHUTDOWN
-int main(int argc, char ** argv) {
- int fd;
- reboot_action rebootAction = HALT;
- int doKill = 1;
- int i = 1;
-
- while (i < argc) {
- if (!strncmp("-r", argv[i], 2))
- rebootAction = REBOOT;
- else if (!strncmp("--nokill", argv[i], 8))
- doKill = 0;
- else if (!strncmp("-P", argv[i], 2))
- rebootAction = POWEROFF;
- i++;
- }
-
- /* ignore some signals so we don't kill ourself */
- signal(SIGINT, SIG_IGN);
- signal(SIGTSTP, SIG_IGN);
-
- /* now change to / */
- i = 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(doKill, rebootAction);
- return 0;
-}
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 ts=4: */
diff --git a/loader/undomounts.c b/loader/undomounts.c
deleted file mode 100644
index 270255a..0000000
--- a/loader/undomounts.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * undomounts.c: Handles some basic unmounting stuff for init
- * Broken out so that it can be used on s390 in a shutdown binary
- *
- * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author(s): Erik Troan <ewt@redhat.com>
- * Jeremy Katz <katzj@redhat.com>
- */
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/mount.h>
-#include <sys/stat.h>
-#include <sys/swap.h>
-#include <unistd.h>
-
-#include <linux/loop.h>
-
-/* Defined in linux/fs.h, but inside __KERNEL__. */
-#ifdef MNT_DETACH
-#undef MNT_DETACH
-#endif
-
-#define MNT_DETACH 0x00000002
-
-struct unmountInfo {
- char * name;
- int mounted;
- int loopDevice;
- enum { FS, LOOP } what;
-} ;
-
-void undoLoop(struct unmountInfo * fs, int numFs, int this);
-
-static void printstr(char * string) {
- write(1, string, strlen(string));
-}
-
-void undoMount(struct unmountInfo * fs, int numFs, int this) {
- size_t len = strlen(fs[this].name);
- int i;
-
- if (!fs[this].mounted) return;
- fs[this].mounted = 0;
-
- /* unmount everything underneath this */
- for (i = 0; i < numFs; i++) {
- if (fs[i].name && (strlen(fs[i].name) >= len) &&
- (fs[i].name[len] == '/') &&
- !strncmp(fs[this].name, fs[i].name, len)) {
- if (fs[i].what == LOOP)
- undoLoop(fs, numFs, i);
- else
- undoMount(fs, numFs, i);
- }
- }
-
- printf(" %s", fs[this].name);
- /* don't need to unmount /tmp. it is busy anyway. */
- if (umount(fs[this].name) < 0) {
- printf(" umount failed (%d)", errno);
- } else {
- printf(" done");
- }
- printf("
");
-}
-
-void undoLoop(struct unmountInfo * fs, int numFs, int this) {
- int i;
- int fd;
-
- if (!fs[this].mounted) return;
- fs[this].mounted = 0;
-
- /* find the device mount */
- for (i = 0; i < numFs; i++) {
- if (fs[i].what == FS && (fs[i].loopDevice == fs[this].loopDevice))
- break;
- }
-
- if (i < numFs) {
- /* the device is mounted, unmount it (and recursively, anything
- * underneath) */
- undoMount(fs, numFs, i);
- }
-
- unlink("/tmp/loop");
- mknod("/tmp/loop", 0600 | S_IFBLK, (7 << 8) | fs[this].loopDevice);
- printf(" disabling /dev/loop%d", fs[this].loopDevice);
- if ((fd = open("/tmp/loop", O_RDONLY, 0)) < 0) {
- printf(" failed to open device: %d", errno);
- } else {
- ioctl(fd, LOOP_CLR_FD, 0);
- close(fd);
- }
-
- printf("
");
-}
-
-void unmountFilesystems(void) {
- int fd, size;
- char buf[65535]; /* this should be big enough */
- char * chptr, * start;
- struct unmountInfo filesystems[500];
- int numFilesystems = 0;
- int i;
- struct loop_info li;
- struct stat sb;
-
- fd = open("/proc/mounts", O_RDONLY, 0);
- if (fd < 1) {
- /* FIXME: was perror */
- printstr("failed to open /proc/mounts");
- sleep(2);
- return;
- }
-
- size = read(fd, buf, sizeof(buf) - 1);
- buf[size] = '';
-
- close(fd);
-
- chptr = buf;
- while (*chptr) {
- while (*chptr != ' ') chptr++;
- *chptr++ = '';
- start = chptr;
- while (*chptr != ' ') chptr++;
- *chptr++ = '';
-
- if (strcmp(start, "/") && strcmp(start, "/tmp") &&
- strcmp(start, "/proc") && strcmp(start, "/sys") &&
- strcmp(start, "/dev")) {
- filesystems[numFilesystems].name = strdup(start);
- filesystems[numFilesystems].what = FS;
- filesystems[numFilesystems].mounted = 1;
-
- stat(start, &sb);
- if ((sb.st_dev >> 8) == 7) {
- filesystems[numFilesystems].loopDevice = sb.st_dev & 0xf;
- } else {
- filesystems[numFilesystems].loopDevice = -1;
- }
-
- numFilesystems++;
- }
-
- while (*chptr != '
') chptr++;
- chptr++;
- }
-
- for (i = 0; i < 7; i++) {
- unlink("/tmp/loop");
- mknod("/tmp/loop", 0600 | S_IFBLK, (7 << 8) | i);
- if ((fd = open("/tmp/loop", O_RDONLY, 0)) >= 0) {
- if (!ioctl(fd, LOOP_GET_STATUS, &li) && li.lo_name[0]) {
- filesystems[numFilesystems].name = strdup(li.lo_name);
- filesystems[numFilesystems].what = LOOP;
- filesystems[numFilesystems].mounted = 1;
- filesystems[numFilesystems].loopDevice = i;
- numFilesystems++;
- }
-
- close(fd);
- }
- }
-
- for (i = 0; i < numFilesystems; i++) {
- if (filesystems[i].what == LOOP) {
- undoLoop(filesystems, numFilesystems, i);
- }
- }
-
- for (i = 0; i < numFilesystems; i++) {
- if ((filesystems[i].mounted) && (filesystems[i].name)) {
- undoMount(filesystems, numFilesystems, i);
- }
- }
-
- for (i = 0; i < numFilesystems; i++)
- free(filesystems[i].name);
-}
-
-void disableSwap(void) {
- int fd;
- char buf[4096];
- int i;
- char * start;
- char * chptr;
-
- if ((fd = open("/proc/swaps", O_RDONLY, 0)) < 0) return;
-
- i = read(fd, buf, sizeof(buf) - 1);
- close(fd);
- if (i < 0) return;
- buf[i] = '';
-
- start = buf;
- while (*start) {
- while (*start != '
' && *start) start++;
- if (!*start) return;
-
- start++;
- if (*start != '/') return;
- chptr = start;
- while (*chptr && *chptr != ' ') chptr++;
- if (!(*chptr)) return;
- *chptr = '';
- printf(" %s", start);
- if (swapoff(start))
- printf(" failed (%d)", errno);
- printf("
");
-
- start = chptr + 1;
- }
-}
--
1.7.4.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 07:07 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org