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 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("33[9;0]");
printstr("33[8]");
@@ -567,12 +445,6 @@ int main(int argc, char **argv) {

printf("anaconda installer init version %s starting
", VERSION);

- printf("mounting /proc filesystem... ");
- mount("/proc", "proc", "proc", 0, NULL);
- if (access("/proc/cmdline", R_OK) == -1)
- fatal_error(1);
- printf("done
");
-
cmdline = readvars_parse_file("/proc/cmdline");

/* check for development mode early */
@@ -589,57 +461,6 @@ int main(int argc, char **argv) {
}
}

- printf("creating /dev filesystem... ");
- mount("/dev", "/dev", "tmpfs", 0, NULL);
- if (access("/dev", W_OK) == -1)
- fatal_error(1);
- createDevices();
- printf("done
");
- printf("starting udev...");
- if ((childpid = fork()) == 0) {
- execl("/sbin/udevd", "/sbin/udevd", "--daemon", NULL);
- exit(1);
- }
-
- /* wait at least until the udevd process that we forked exits */
- do {
- pid_t retpid;
- int waitstatus;
-
- retpid = wait(&waitstatus);
- if (retpid == -1) {
- if (errno == EINTR)
- continue;
- /* if the child exited before we called waitpid, we can get
- * ECHILD without anything really being wrong; we just lost
- * the race.*/
- if (errno == ECHILD)
- break;
- printf("init: error waiting on udevd: %m
");
- exit(1);
- } else if ((retpid == childpid) && WIFEXITED(waitstatus)) {
- break;
- }
- } while (1);
-
- if (fork() == 0) {
- execl("/sbin/udevadm", "udevadm", "control", "--env=ANACONDA=1", NULL);
- exit(1);
- }
- printf("done
");
-
- printf("mounting /dev/pts (unix98 pty) filesystem... ");
- mount("/dev/pts", "/dev/pts", "devpts", 0, NULL);
- if (access("/dev/pts/ptmx", F_OK) == -1)
- fatal_error(1);
- printf("done
");
-
- printf("mounting /sys filesystem... ");
- mount("/sys", "/sys", "sysfs", 0, NULL);
- if (access("/sys/class/block", R_OK) == -1)
- fatal_error(1);
- printf("done
");
-
/* if anaconda dies suddenly we are doomed, so at least make a coredump */
struct rlimit corelimit = { RLIM_INFINITY, RLIM_INFINITY};
ret = setrlimit(RLIMIT_CORE, &corelimit);
@@ -764,60 +585,10 @@ int main(int argc, char **argv) {
tcsetattr(0, TCSANOW, &ts);
}

- ret = sethostname("localhost.localdomain", 21);
- /* the default domainname (as of 2.0.35) is "(none)", which confuses
- glibc */
- ret = setdomainname("", 0);
-
- printf("trying to remount root filesystem read write... ");
- mount("/", "/", "remount", MS_REMOUNT, NULL);
- printf("done
");
-
- /* we want our /tmp to be tmpfs, but we also want to let people hack
- * their initrds to add things like a ks.cfg, so this has to be a little
- * tricky */
- rename("/tmp", "/oldtmp");
- mkdir("/tmp", 0755);
-
- printf("mounting /tmp as tmpfs... ");
- mount("none", "/tmp", "tmpfs", 0, "size=250m");
- if (access("/tmp", W_OK) == -1)
- fatal_error(1);
- printf("done
");
-
- copyDirectory("/oldtmp", "/tmp", copyErrorFn, copyErrorFn);
- unlink("/oldtmp");
-
/* Now we have some /tmp space set up, and /etc and /dev point to
it. We should be in pretty good shape. */
startSyslog();

- /* write out a pid file */
- if ((fd = open("/var/run/init.pid", O_WRONLY|O_CREAT, 0644)) > 0) {
- char * buf = malloc(10);
-
- snprintf(buf, 9, "%d", getpid());
- write(fd, buf, strlen(buf));
- close(fd);
- free(buf);
- } else {
- printf("unable to write init.pid (%d): %m
", errno);
- sleep(2);
- }
-
- /* D-Bus */
- if (fork() == 0) {
- execl("/bin/dbus-uuidgen", "/bin/dbus-uuidgen", "--ensure", NULL);
- doExit(1);
- }
-
- if (fork() == 0) {
- execl("/bin/dbus-daemon", "/bin/dbus-daemon", "--system", NULL);
- doExit(1);
- }
-
- sleep(2);
-
/* Go into normal init mode - keep going, and then do a orderly shutdown
when:

@@ -854,22 +625,7 @@ int main(int argc, char **argv) {

/* set up the ctrl+alt+delete handler to kill our pid, not pid 1 */
signal(SIGINT, sigintHandler);
- if ((fd = open("/proc/sys/kernel/cad_pid", O_WRONLY)) != -1) {
- char buf[7];
- size_t count;
- sprintf(buf, "%d", getpid());
- count = write(fd, buf, strlen(buf));
- close(fd);
- /* if we succeeded in writing our pid, turn off the hard reboot
- ctrl-alt-del handler */
- if (count == strlen(buf) &&
- (fd = open("/proc/sys/kernel/ctrl-alt-del", O_WRONLY)) != -1) {

- write(fd, "0", 1);
- close(fd);
- }
- }
-
while (!doShutdown) {
pid_t childpid;
childpid = wait(&waitStatus);
@@ -897,28 +653,6 @@ int main(int argc, char **argv) {
}
printf("
");

- /* If debug mode was requested, spawn shell */
- if(isDevelMode) {
- pid_t shellpid;
-
- printf("Development mode requested spawning shell...
");
-
- if ((shellpid = fork()) == 0) {
- if (chdir("/root") == 0) {
- execl("/bin/bash", "/bin/bash", NULL);
- } else {
- perror("Unable to chdir to /root");
- }
- }
- else if (shellpid > 0) {
- waitpid(shellpid, NULL, 0);
- }
- else {
- perror("Execution of debug shell failed.");
- }
-
- }
-
} else {
shutdown_method = REBOOT;
}
diff --git a/loader/loader.c b/loader/loader.c
index d4437c3..b32e5ce 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -358,62 +358,6 @@ static void initializeTtys(void) {
}
}

-static void spawnShell(void) {
- pid_t pid;
-
- if (FL_SERIAL(flags) || FL_NOSHELL(flags)) {
- logMessage(INFO, "not spawning a shell");
- return;
- } else if (access("/bin/sh", X_OK)) {
- logMessage(ERROR, "cannot open shell - /bin/sh doesn't exist");
- return;
- }
-
- if (!(pid = fork())) {
- int fd;
-
- fd = open("/dev/tty2", O_RDWR|O_NOCTTY);
- if (fd < 0) {
- logMessage(ERROR, "cannot open /dev/tty2 -- no shell will be provided");
- return;
- }
-
- dup2(fd, 0);
- dup2(fd, 1);
- dup2(fd, 2);
-
- close(fd);
- setsid();
-
- /* enable UTF-8 console */
- printf("33%%G");
- fflush(stdout);
- isysLoadFont();
-
- if (ioctl(0, TIOCSCTTY, NULL)) {
- logMessage(ERROR, "could not set new controlling tty");
- }
-
- signal(SIGINT, SIG_DFL);
- signal(SIGTSTP, SIG_DFL);
-
- if (!access("/tmp/updates/pyrc.py", R_OK|X_OK))
- setenv("PYTHONSTARTUP", "/tmp/updates/pyrc.py", 1);
- else if (!access("/usr/share/anaconda/pyrc.py", R_OK|X_OK))
- setenv("PYTHONSTARTUP", "/usr/share/anaconda/pyrc.py", 1);
- setenv("LD_LIBRARY_PATH", LIBPATH, 1);
- setenv("LANG", "C", 1);
-
- if (execl("/bin/sh", "-/bin/sh", NULL) == -1) {
- logMessage(CRITICAL, "exec of /bin/sh failed: %m");
- exit(1);
- }
- }
-
- return;
-}
-
-
static void copyWarnFn (char *msg) {
logMessage(WARNING, msg);
}
@@ -2048,9 +1992,6 @@ int main(int argc, char ** argv) {
/* Save list of preloaded modules so we can restore the state */
moduleState = mlSaveModuleState();

- /* Load all known devices */
- busProbe(FL_NOPROBE(flags));
-
if (FL_AUTOMODDISK(flags)) {
/* Load all autodetected DDs */
logMessage(INFO, "Trying to detect vendor driver discs");
@@ -2173,23 +2114,14 @@ int main(int argc, char ** argv) {
/* now load SELinux policy before exec'ing anaconda and the shell
* (if we're using SELinux) */
if (FL_SELINUX(flags)) {
- if (mount("/selinux", "/selinux", "selinuxfs", 0, NULL)) {
- logMessage(ERROR, "failed to mount /selinux: %m, disabling SELinux");
- flags &= ~LOADER_FLAGS_SELINUX;
+ if (loadpolicy() == 0) {
+ setexeccon(ANACONDA_CONTEXT);
} else {
- if (loadpolicy() == 0) {
- setexeccon(ANACONDA_CONTEXT);
- } else {
- logMessage(ERROR, "failed to load policy, disabling SELinux");
- flags &= ~LOADER_FLAGS_SELINUX;
- }
+ logMessage(ERROR, "failed to load policy, disabling SELinux");
+ flags &= ~LOADER_FLAGS_SELINUX;
}
}

- logMessage(INFO, "getting ready to spawn shell now");
-
- spawnShell(); /* we can attach gdb now :-) */
-
if (FL_NOPROBE(flags) && !loaderData.ksFile) {
startNewt();
manualDeviceCheck(&loaderData);
--
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 03:30 PM.

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