[systemd-devel] [PATCH 2/2] systemctl: for switch-root check, if we switch to a systemd init

Harald Hoyer harald at redhat.com
Wed Mar 5 06:25:33 PST 2014


On 03/05/2014 02:55 PM, Zbigniew Jędrzejewski-Szmek wrote:
> On Wed, Mar 05, 2014 at 02:37:47PM +0100, harald at redhat.com wrote:
>> From: Harald Hoyer <harald at redhat.com>
>>
>> If "systemctl switch-root" is called with a specific "INIT" or
>> /proc/cmdline contains "init=", then systemd would not serialize
>> itsself.
>>
>> Let systemctl check, if the new init is in the standard systemd
>> installation path and if so, clear the INIT parameter,
>> to let systemd serialize itsself.
>> ---
>>  src/systemctl/systemctl.c | 11 +++++++++++
>>  1 file changed, 11 insertions(+)
>>
>> diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
>> index f395265..18dbcc0 100644
>> --- a/src/systemctl/systemctl.c
>> +++ b/src/systemctl/systemctl.c
>> @@ -4283,6 +4283,7 @@ static int show_environment(sd_bus *bus, char **args) {
>>  static int switch_root(sd_bus *bus, char **args) {
>>          _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
>>          _cleanup_free_ char *init = NULL;
>> +        _cleanup_free_ char *root_systemd_path = NULL;
>>          const char *root;
>>          unsigned l;
>>          int r;
>> @@ -4309,6 +4310,16 @@ static int switch_root(sd_bus *bus, char **args) {
>>          if (!init)
>>                  return log_oom();
>>  
>> +        root_systemd_path = strjoin(root, "/", SYSTEMD_BINARY_PATH, NULL);
>> +        if (!root_systemd_path)
>> +                return log_oom();
>> +
>> +        if (files_same(init, root_systemd_path) > 0) {
>> +                char *t = init;
>> +                init = strdup("");
>> +                free(t);
> Maybe the old value should be kept on oom error?
> 
> Zbyszek
> 

Well, on oom, we most likely are screwed on sending the dbus message later on
anyway.


More information about the systemd-devel mailing list