[systemd-commits] 5 commits - TODO man/systemctl.xml src/core src/systemctl src/systemd
Lennart Poettering
lennart at kemper.freedesktop.org
Mon May 14 13:41:38 PDT 2012
TODO | 8 +----
man/systemctl.xml | 27 +++++++++++++++++++
src/core/dbus-manager.c | 17 ++++++++++++
src/core/namespace.c | 23 +++++++++++-----
src/systemctl/systemctl.c | 63 +++++++++++++++++++++++++++++++++++++++++++++-
src/systemd/sd-login.h | 4 ++
6 files changed, 127 insertions(+), 15 deletions(-)
New commits:
commit ee1f44bd9a63e776810a31bd8394e8d481b6c34d
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon May 14 22:41:17 2012 +0200
sd-login: update header docs a bit
diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h
index f8c3c69..0a6d6ff 100644
--- a/src/systemd/sd-login.h
+++ b/src/systemd/sd-login.h
@@ -34,7 +34,9 @@ extern "C" {
* Instead of returning an empty string array or empty uid array, we
* may return NULL.
*
- * Free the data we return with libc free().
+ * Free the data the library returns with libc free(). String arrays
+ * are NULL terminated and you need to free the array itself in
+ * addition to the strings contained.
*
* We return error codes as negative errno, kernel-style. 0 or
* positive on success.
commit c1d70f7ca5eeeb3850161444028ba227f79df83e
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri May 11 17:56:09 2012 +0200
namespace: make PrivateTmp= apply to both /tmp and /var/tmp
diff --git a/TODO b/TODO
index 89a35ad..a3b4165 100644
--- a/TODO
+++ b/TODO
@@ -97,8 +97,6 @@ Features:
* allow configuration of console width/height in vconsole.conf
-* PrivateTmp should apply to both /tmp and /var/tmp
-
* fstab should take priority over units in /usr
* cleanup syslog 'priority' vs. 'level' wording
diff --git a/src/core/namespace.c b/src/core/namespace.c
index ba1edbe..4bef15f 100644
--- a/src/core/namespace.c
+++ b/src/core/namespace.c
@@ -131,7 +131,8 @@ static int apply_mount(Path *p, const char *root_dir, const char *inaccessible_d
assert(inaccessible_dir);
assert(private_dir);
- if (!(where = strappend(root_dir, p->path)))
+ where = strappend(root_dir, p->path);
+ if (!where)
return -ENOMEM;
switch (p->mode) {
@@ -157,7 +158,8 @@ static int apply_mount(Path *p, const char *root_dir, const char *inaccessible_d
assert_not_reached("Unknown mode");
}
- if ((r = mount(what, where, NULL, MS_BIND|MS_REC, NULL)) >= 0) {
+ r = mount(what, where, NULL, MS_BIND|MS_REC, NULL);
+ if (r >= 0) {
log_debug("Successfully mounted %s to %s", what, where);
/* The bind mount will always inherit the original
@@ -205,9 +207,10 @@ int setup_namespace(
strv_length(writable) +
strv_length(readable) +
strv_length(inaccessible) +
- (private_tmp ? 2 : 1);
+ (private_tmp ? 3 : 1);
- if (!(paths = new(Path, n)))
+ paths = new(Path, n);
+ if (!paths)
return -ENOMEM;
p = paths;
@@ -220,6 +223,10 @@ int setup_namespace(
p->path = "/tmp";
p->mode = PRIVATE;
p++;
+
+ p->path = "/var/tmp";
+ p->mode = PRIVATE;
+ p++;
}
p->path = "/";
@@ -282,9 +289,11 @@ int setup_namespace(
goto fail;
}
- for (p = paths; p < paths + n; p++)
- if ((r = apply_mount(p, root_dir, inaccessible_dir, private_dir, flags)) < 0)
+ for (p = paths; p < paths + n; p++) {
+ r = apply_mount(p, root_dir, inaccessible_dir, private_dir, flags);
+ if (r < 0)
goto undo_mounts;
+ }
memcpy(old_root_dir, tmp_dir, sizeof(tmp_dir)-1);
if (!mkdtemp(old_root_dir)) {
@@ -341,7 +350,7 @@ fail:
if (remove_tmp)
rmdir(tmp_dir);
- free(paths);
+ free(paths);
return r;
}
commit 1c334d993a8bb32241284479012a27a7509aaa3c
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri May 11 17:46:58 2012 +0200
update TODO
diff --git a/TODO b/TODO
index d2bb326..89a35ad 100644
--- a/TODO
+++ b/TODO
@@ -23,7 +23,7 @@ Bugfixes:
Features:
-* expose switch-root in systemctl
+* actually queue the new default unit after switch-root
* remove old root in switch-root logic
@@ -52,8 +52,6 @@ Features:
* don't delete /run/users/lennart if lennart is still logged in even if aging is used
-* automount: implement expire
-
* vconsole: implement setterm -store -foreground xxx --background zzz
* ExecOnFailure=/usr/bin/foo
@@ -72,7 +70,7 @@ Features:
* Auke: merge Auke's bootchart
-* journald: allow forwarding of log data to specific TTY instea dof console
+* journald: allow forwarding of log data to specific TTY instead of console
* add RequiredBy to [Install]
commit 957eb8cab28dc83aa4b800d033031e53cd0a9e00
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri May 11 17:35:46 2012 +0200
systemctl: add switch-root verb
diff --git a/man/systemctl.xml b/man/systemctl.xml
index 9e113eb..29481e7 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -1159,6 +1159,33 @@
<listitem><para>Hibernate the system.</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><command>switch-root [ROOT] [INIT]</command></term>
+
+ <listitem><para>Switches to a
+ different root directory and executes
+ a new system manager process below
+ it. This is intended for usage in
+ initial RAM disks ("initrd"), and will
+ transition from the initrd's system
+ manager process (a.k.a "init" process)
+ to the main system manager
+ process. Takes two arguments: the
+ directory to make the new root
+ directory, and the path to the new
+ system manager binary below it to
+ execute as PID 1. If the latter is
+ ommitted or the empty string, a
+ systemd binary will automatically be
+ searched for and used as init. If the
+ system manager path is ommitted or
+ equal the empty string the state of
+ the initrd's system manager process is
+ passed to the main system manager,
+ which allows later introspection of the
+ state of the services involved in the
+ initrd boot.</para></listitem>
+ </varlistentry>
</variablelist>
</refsect1>
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 4708a35..0034c55 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -3580,6 +3580,65 @@ finish:
return r;
}
+static int switch_root(DBusConnection *bus, char **args) {
+ DBusMessage *m = NULL, *reply = NULL;
+ unsigned l;
+ const char *root, *init;
+ DBusError error;
+ int r;
+
+ dbus_error_init(&error);
+
+ l = strv_length(args);
+ if (l < 2 || l > 3) {
+ log_error("Wrong number of arguments.");
+ return -EINVAL;
+ }
+
+ root = args[1];
+ init = l >= 3 ? args[2] : "";
+
+ m = dbus_message_new_method_call(
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager",
+ "SwitchRoot");
+ if (!m) {
+ log_error("Could not allocate message.");
+ return -ENOMEM;
+ }
+
+ if (!dbus_message_append_args(
+ m,
+ DBUS_TYPE_STRING, &root,
+ DBUS_TYPE_STRING, &init,
+ DBUS_TYPE_INVALID)) {
+ log_error("Could not append arguments to message.");
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
+ if (!reply) {
+ log_error("Failed to issue method call: %s", bus_error_message(&error));
+ r = -EIO;
+ goto finish;
+ }
+
+ r = 0;
+
+finish:
+ if (m)
+ dbus_message_unref(m);
+
+ if (reply)
+ dbus_message_unref(reply);
+
+ dbus_error_free(&error);
+
+ return r;
+}
+
static int set_environment(DBusConnection *bus, char **args) {
DBusMessage *m = NULL, *reply = NULL;
DBusError error;
@@ -4220,6 +4279,7 @@ static int systemctl_help(void) {
" reboot Shut down and reboot the system\n"
" kexec Shut down and reboot the system with kexec\n"
" exit Request user instance exit\n"
+ " switch-root [ROOT] [INIT] Change to a different root file system\n"
" suspend Suspend the system\n"
" hibernate Hibernate the system\n",
program_invocation_short_name);
@@ -5169,7 +5229,8 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
{ "preset", MORE, 2, enable_unit },
{ "mask", MORE, 2, enable_unit },
{ "unmask", MORE, 2, enable_unit },
- { "link", MORE, 2, enable_unit }
+ { "link", MORE, 2, enable_unit },
+ { "switch-root", MORE, 2, switch_root },
};
int left;
commit 50913bc0c8ced894ceabc7e893c0fdf73af9a261
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri May 11 17:17:57 2012 +0200
core: add extra safety check before switching root
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 6ad1984..33dcb56 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -1186,6 +1186,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SwitchRoot")) {
const char *switch_root, *switch_root_init;
char *u, *v;
+ int k;
if (!dbus_message_get_args(
message,
@@ -1206,6 +1207,22 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
+ /* Safety check */
+ if (isempty(switch_root_init))
+ k = access(switch_root, F_OK);
+ else {
+ char *p;
+
+ p = join(switch_root, "/", switch_root_init, NULL);
+ if (!p)
+ goto oom;
+
+ k = access(p, X_OK);
+ free(p);
+ }
+ if (k < 0)
+ return bus_send_error_reply(connection, message, NULL, -errno);
+
u = strdup(switch_root);
if (!u)
goto oom;
More information about the systemd-commits
mailing list