Remove from init.c/loader.c things that systemd does for us.
* We don't need to populate /dev.
* We don't need to mount filesystems.
* We don't need to start dbus or udevd.
* We don't need to start a shell in multiple places.
---
data/systemd/Makefile.am | 2 +-
data/systemd/loader.service | 8 +-
data/systemd/tmp.mount | 9 ++
loader/devices.h | 103 -----------------
loader/init.c | 268 +------------------------------------------
loader/loader.c | 76 +------------
6 files changed, 19 insertions(+), 447 deletions(-)
create mode 100644 data/systemd/tmp.mount
delete mode 100644 loader/devices.h
diff --git a/data/systemd/Makefile.am b/data/systemd/Makefile.am
index 4185ddb..cebbd2c 100644
--- a/data/systemd/Makefile.am
+++ b/data/systemd/Makefile.am
@@ -18,7 +18,7 @@
# Author: Chris Lumens <clumens@redhat.com>
systemddir = /lib/systemd/system
-dist_systemd_DATA = anaconda-shell.service anaconda.target loader.service
+dist_systemd_DATA = anaconda-shell.service anaconda.target loader.service tmp.mount
MAINTAINERCLEANFILES = Makefile.in
diff --git a/data/systemd/loader.service b/data/systemd/loader.service
index 3b6b726..d808067 100644
--- a/data/systemd/loader.service
+++ b/data/systemd/loader.service
@@ -1,12 +1,12 @@
[Unit]
Description=The anaconda loader
-Requires=dbus.service udev.service rsyslog.service
-After=dbus.service udev.service rsyslog.service
+Requires=dbus.service udev.service rsyslog.service tmp.mount
+After=dbus.service udev.service rsyslog.service tmp.mount
[Service]
-Environment=HOME=/
+Environment=HOME=/root MALLOC_CHECK_=2 MALLOC_PERTURB_=204 PATH=/usr/bin:/bin:/sbin:/usr/sbin:/mnt/sysimage/bin:/mnt/sysimage/usr/bin:/mnt/sysimage/usr/sbin:/mnt/sysimage/sbin PYTHONPATH=/tmp/updates TERM=linux
Type=oneshot
-WorkingDirectory=/
+WorkingDirectory=/root
ExecStart=/sbin/loader
StandardInput=tty-force
KillMode=process-group
diff --git a/data/systemd/tmp.mount b/data/systemd/tmp.mount
new file mode 100644
index 0000000..5a42685
--- /dev/null
+++ b/data/systemd/tmp.mount
@@ -0,0 +1,9 @@
+[Unit]
+Description=Runtime Directory
+Before=loader.service
+
+[Mount]
+What=tmpfs
+Where=/tmp
+Type=tmpfs
+Options=size=250m
diff --git a/loader/devices.h b/loader/devices.h
deleted file mode 100644
index 974e792..0000000
--- a/loader/devices.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * devices.h: handle declaration of devices to be created under /dev
- *
- * Copyright (C) 2004 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/>.
- */
-
-#ifndef LOADER_INIT_DEVICES_H
-#define LOADER_INIT_DEVICES_H
-
-struct devnode {
- char * devname;
- int type;
- int major;
- int minor;
- int perms;
- char * owner;
- char * group;
-};
-
-#define CHARDEV 0
-#define BLOCKDEV 1
-#define DIRTYPE 2
-
-struct devnode devnodes[] = {
- /* consoles */
- {"console", CHARDEV, 5, 1, 0600, "root", "root"},
- {"ttyS0", CHARDEV, 4, 64, 0600, "root", "root"},
- {"ttyS1", CHARDEV, 4, 65, 0600, "root", "root"},
- {"ttyS2", CHARDEV, 4, 66, 0600, "root", "root"},
- {"ttyS3", CHARDEV, 4, 67, 0600, "root", "root"},
-#ifdef __ia64__
- {"ttySG0", CHARDEV, 204, 40, 0600, "root", "root"},
-#endif
-#ifdef __powerpc__
- {"hvsi0", CHARDEV, 229, 128, 0600, "root", "root"},
- {"hvsi1", CHARDEV, 229, 129, 0600, "root", "root"},
- {"hvsi2", CHARDEV, 229, 130, 0600, "root", "root"},
-#endif
- {"hvc0", CHARDEV, 229, 0, 0600, "root", "root"},
-#if defined(__i386__) || defined(__x86_64__) || defined(__ia64__)
- {"xvc0", CHARDEV, 204, 191, 0600, "root", "root"},
-#endif
- /* base unix */
- {"null", CHARDEV, 1, 3, 0666, "root", "root"},
- {"zero", CHARDEV, 1, 5, 0666, "root", "root"},
- {"mem", CHARDEV, 1, 1, 0600, "root", "root"},
- /* ttys */
- {"pts", DIRTYPE, 0, 0, 0755, "root", "root"},
- {"ptmx", CHARDEV, 5, 2, 0666, "root", "root"},
- {"tty", CHARDEV, 5, 0, 0666, "root", "root"},
- {"tty0", CHARDEV, 4, 0, 0600, "root", "tty"},
- {"tty1", CHARDEV, 4, 1, 0600, "root", "tty"},
- {"tty2", CHARDEV, 4, 2, 0600, "root", "tty"},
- {"tty3", CHARDEV, 4, 3, 0600, "root", "tty"},
- {"tty4", CHARDEV, 4, 4, 0600, "root", "tty"},
- {"tty5", CHARDEV, 4, 5, 0600, "root", "tty"},
- {"tty6", CHARDEV, 4, 6, 0600, "root", "tty"},
- {"tty7", CHARDEV, 4, 7, 0600, "root", "tty"},
- {"tty8", CHARDEV, 4, 8, 0600, "root", "tty"},
- {"tty9", CHARDEV, 4, 9, 0600, "root", "tty"},
- /* fb */
- {"fb0", CHARDEV, 29, 0, 0600, "root", "tty"},
- /* sparc specific */
-#ifdef __sparc__
- {"openprom", CHARDEV, 10, 139, 0644, "root", "root"},
- {"sunmouse", CHARDEV, 10, 6, 0644, "root", "root"},
- {"kbd", CHARDEV, 11, 0, 0644, "root", "root"},
-#endif
- /* X */
- {"agpgart", CHARDEV, 10, 175, 0664, "root", "root"},
- {"psaux", CHARDEV, 10, 1, 0644, "root", "root"},
- {"input", DIRTYPE, 0, 0, 0755, "root", "root"},
- {"input/mice", CHARDEV, 13, 63, 0664, "root", "root"},
- /* floppies */
- {"fd0", BLOCKDEV, 2, 0, 0644, "root", "root"},
- {"fd1", BLOCKDEV, 2, 1, 0644, "root", "root"},
- /* random */
- {"random", CHARDEV, 1, 8, 0644, "root", "root"},
- {"urandom", CHARDEV, 1, 9, 0644, "root", "root"},
- /* mac stuff */
-#ifdef __powerpc__
- {"nvram", CHARDEV, 10, 144, 0644, "root", "root"},
- {"adb", CHARDEV, 56, 0, 0644, "root", "root"},
- {"iseries", DIRTYPE, 0, 0, 0755, "root", "root" },
-#endif
- {"rtc", CHARDEV, 10, 135, 0644, "root", "root"},
- { NULL, 0, 0, 0, 0, NULL, NULL },
-};
-
-#endif
diff --git a/loader/init.c b/loader/init.c
index 65df89c..bdcf614 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -52,49 +52,12 @@
#include "init.h"
#include "copy.h"
-#include "devices.h"
#include "modules.h"
#include "readvars.h"
#include <asm/types.h>
#include <linux/serial.h>
-#ifndef MS_REMOUNT
-#define MS_REMOUNT 32
-#endif
-
-#define ENV_PATH 0
-#define ENV_LD_LIBRARY_PATH 1
-#define ENV_HOME 2
-#define ENV_TERM 3
-#define ENV_DEBUG 4
-#define ENV_TERMINFO 5
-#define ENV_PYTHONPATH 6
-#define ENV_MALLOC_CHECK 7
-#define ENV_MALLOC_PERTURB 8
-
-char * env[] = {
- "PATH=/usr/bin:/bin:/sbin:/usr/sbin:/mnt/sysimage/bin:"
- "/mnt/sysimage/usr/bin:/mnt/sysimage/usr/sbin:/mnt/sysimage/sbin:"
- "/mnt/sysimage/usr/X11R6/bin",
-
- /* we set a nicer ld library path specifically for bash -- a full
- one makes anaconda unhappy */
-#if defined(__x86_64__) || defined(__s390x__) || defined(__powerpc64__) || (defined(__sparc__) && defined(__arch64__))
- "LD_LIBRARY_PATH=/lib64:/usr/lib64:/lib:/usr/lib",
-#else
- "LD_LIBRARY_PATH=/lib:/usr/lib",
-#endif
- "HOME=/root",
- "TERM=linux",
- "DEBUG=",
- "TERMINFO=/etc/linux-terminfo",
- "PYTHONPATH=/tmp/updates",
- "MALLOC_CHECK_=2",
- "MALLOC_PERTURB_=204",
- NULL
-};
-
static char *VIRTIO_PORT = "/dev/virtio-ports/org.fedoraproject.anaconda.log.0";
/*
@@ -116,13 +79,6 @@ struct termios ts;
static int expected_exit = 0;
static GHashTable *cmdline = NULL;
-static void doExit(int) __attribute__ ((noreturn));
-static void doExit(int result)
-{
- expected_exit = 1;
- exit(result);
-}
-
static void printstr(char * string) {
write(1, string, strlen(string));
}
@@ -232,49 +188,6 @@ static int termcmp(struct termios *a, struct termios *b) {
}
#endif
-static void createDevices(void) {
- int i;
-
- /* unset the umask so devices are created with correct perms
- and not complemented by the previous umask call */
-
- mode_t previous_umask = umask(0);
-
- for (i = 0; devnodes[i].devname != NULL; i++) {
- char devname[64];
- int type = -1;
-
- snprintf(devname, 63, "/dev/%s", devnodes[i].devname);
- switch (devnodes[i].type) {
- case DIRTYPE:
- if (mkdir(devname, devnodes[i].perms) < 0) {
- fprintf(stderr, "Unable to create directory %s: %m
",
- devname);
- }
- break;
- case CHARDEV:
- type = S_IFCHR;
- break;
- case BLOCKDEV:
- type = S_IFBLK;
- break;
- }
- if (type == -1) continue;
-
- if (mknod(devname, type | devnodes[i].perms,
- makedev(devnodes[i].major, devnodes[i].minor)) < 0)
- fprintf(stderr, "Unable to create device %s: %m
", devname);
- }
-
- /* Hurray for hacks, this stops /lib/udev/rules.d/65-md-incremental.rules
- from medling with mdraid sets. */
- i = creat("/dev/.in_sysinit", 0644);
- close(i);
-
- /* Restore umask for minimal side affects */
- umask(previous_umask);
-}
-
static void termReset(void) {
/* change to tty1 */
ioctl(0, VT_ACTIVATE, 1);
@@ -383,21 +296,6 @@ static int onQEMU(void)
return ret;
}
-static int getInitPid(void) {
- int fd = 0, pid = -1;
- char * buf = calloc(1, 10);
-
- fd = open("/var/run/init.pid", O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "Unable to find pid of init!!!
");
- return -1;
- }
- read(fd, buf, 9);
- close(fd);
- sscanf(buf, "%d", &pid);
- return pid;
-}
-
static void copyErrorFn (char *msg) {
printf(msg);
}
@@ -514,7 +412,7 @@ static void setupEnv(void)
}
int main(int argc, char **argv) {
- pid_t installpid, childpid;
+ pid_t installpid;
int waitStatus;
int fd = -1;
int doShutdown =0;
@@ -531,26 +429,6 @@ int main(int argc, char **argv) {
int ret;
gpointer value = NULL;
- if (!strncmp(basename(argv[0]), "poweroff", 8)) {
- printf("Running poweroff...
");
- fd = getInitPid();
- if (fd > 0)
- kill(fd, SIGUSR2);
- doExit(0);
- } else if (!strncmp(basename(argv[0]), "halt", 4)) {
- printf("Running halt...
");
- fd = getInitPid();
- if (fd > 0)
- kill(fd, SIGUSR1);
- doExit(0);
- } else if (!strncmp(basename(argv[0]), "reboot", 6)) {
- printf("Running reboot...
");
- fd = getInitPid();
- if (fd > 0)
- kill(fd, SIGINT);
- doExit(0);
- }
-
/* turn off screen blanking */
printstr("