diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-04-10 17:53:17 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-04-10 18:00:34 +0200 |
commit | e537352b9bfffe6f6286483bff2c7601c78407e3 (patch) | |
tree | be1a46883f8a1bc6b666bd680adda2d309979c15 /manager.c | |
parent | 108736d0d34d7b74a61a6ac7b99d4d4fec81ce09 (diff) |
mount: implement mounting properly
This also includes code that writes utmp/wtmp records when applicable,
making use the mount infrastructure to detct when those files are
accessible.
Finally, this also introduces a --dump-configuration-items switch.
Diffstat (limited to 'manager.c')
-rw-r--r-- | manager.c | 74 |
1 files changed, 74 insertions, 0 deletions
@@ -27,6 +27,7 @@ #include <sys/signalfd.h> #include <sys/wait.h> #include <unistd.h> +#include <utmpx.h> #include <sys/poll.h> #include <sys/reboot.h> #include <sys/ioctl.h> @@ -42,6 +43,7 @@ #include "ratelimit.h" #include "cgroup.h" #include "mount-setup.h" +#include "utmp-wtmp.h" static int manager_setup_signals(Manager *m) { sigset_t mask; @@ -291,6 +293,8 @@ int manager_new(ManagerRunningAs running_as, Manager **_m) { if (!(m = new0(Manager, 1))) return -ENOMEM; + m->boot_timestamp = now(CLOCK_REALTIME); + m->running_as = running_as; m->signal_watch.fd = m->mount_watch.fd = m->udev_watch.fd = m->epoll_fd = -1; m->current_job_id = 1; /* start as id #1, so that we can leave #0 around as "null-like" value */ @@ -428,6 +432,10 @@ int manager_coldplug(Manager *m) { return r; } + /* Now that the initial devices are available, let's see if we + * can write the utmp file */ + manager_write_utmp_reboot(m); + return 0; } @@ -1704,6 +1712,72 @@ int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j) { return 0; } +static bool manager_utmp_good(Manager *m) { + int r; + + assert(m); + + if ((r = mount_path_is_mounted(m, _PATH_UTMPX)) <= 0) { + + if (r < 0) + log_warning("Failed to determine whether " _PATH_UTMPX " is mounted: %s", strerror(-r)); + + return false; + } + + return true; +} + +void manager_write_utmp_reboot(Manager *m) { + int r; + + assert(m); + + if (m->utmp_reboot_written) + return; + + if (m->running_as != MANAGER_INIT) + return; + + if (!manager_utmp_good(m)) + return; + + if ((r = utmp_put_reboot(m->boot_timestamp)) < 0) { + + if (r != -ENOENT && r != -EROFS) + log_warning("Failed to write utmp/wtmp: %s", strerror(-r)); + + return; + } + + m->utmp_reboot_written = true; +} + +void manager_write_utmp_runlevel(Manager *m, Unit *u) { + int runlevel, r; + + assert(m); + assert(u); + + if (u->meta.type != UNIT_TARGET) + return; + + if (m->running_as != MANAGER_INIT) + return; + + if (!manager_utmp_good(m)) + return; + + if ((runlevel = target_get_runlevel(TARGET(u))) <= 0) + return; + + if ((r = utmp_put_runlevel(0, runlevel, 0)) < 0) { + + if (r != -ENOENT && r != -EROFS) + log_warning("Failed to write utmp/wtmp: %s", strerror(-r)); + } +} + static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = { [MANAGER_INIT] = "init", [MANAGER_SYSTEM] = "system", |