[libvirt] [PATCH] Check if systemd is the init before creating machines

Ján Tomko jtomko at redhat.com
Mon Mar 3 09:35:36 UTC 2014


On 02/28/2014 06:36 PM, Daniel P. Berrange wrote:
> On Thu, Feb 27, 2014 at 09:29:24PM +0100, Ján Tomko wrote:
>> If systemd is installed, but not the init system,
>> systemd-machined fails with an unhelpful error message:
>> Launch helper exited with unknown return code 1
>>
>> Fall back to manual cgroup creation if systemd is installed,
>> but it's not PID 1.
>>
>> [1] https://bugs.freedesktop.org/show_bug.cgi?id=69962
>> ---
>>
>> (Yes, Gentoo.)
>>
>>  src/util/virsystemd.c | 26 ++++++++++++++++++++++++++
>>  1 file changed, 26 insertions(+)
>>
>> diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
>> index 8adf209..0404a63 100644
>> --- a/src/util/virsystemd.c
>> +++ b/src/util/virsystemd.c
>> @@ -30,6 +30,7 @@
>>  #include "virstring.h"
>>  #include "viralloc.h"
>>  #include "virutil.h"
>> +#include "virfile.h"
>>  #include "virlog.h"
>>  #include "virerror.h"
>>  
>> @@ -142,6 +143,28 @@ cleanup:
>>      return machinename;
>>  }
>>  
>> +/*
>> + * Returns 0 if systemd is the init, -2 if not
>> + * -1 on fatal error
>> + */
>> +static int
>> +virSystemdIsInit(void)
>> +{
>> +    char *buf = NULL;
>> +    int ret = -2;
>> +
>> +    if (virFileReadAll("/proc/1/comm", sizeof("systemd\n "), &buf) < 0)
>> +        return -1;
>> +
>> +    if (STREQ(buf, "systemd\n"))
>> +        ret = 0;
>> +    else
>> +        VIR_DEBUG("systemd is not the init");
>> +
>> +    VIR_FREE(buf);
>> +    return ret;
>> +}
>> +
>>  /**
>>   * virSystemdCreateMachine:
>>   * @name: driver unique name of the machine
>> @@ -173,6 +196,9 @@ int virSystemdCreateMachine(const char *name,
>>      if (ret < 0)
>>          return ret;
>>  
>> +    if ((ret = virSystemdIsInit()) < 0)
>> +        return ret;
>> +
> 
> We already do a call
> 
>     ret = virDBusIsServiceEnabled("org.freedesktop.machine1");
> 
> I'd suggest that we perhaps also call
> 
>     ret = virDBusIsServiceEnabled("org.freedesktop.systemd1");
> 
> instead of looking in /proc/1/comm
> 

systemd1 also shows up in the list of activatable names even if systemd is not
running.

Jan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140303/2eb206eb/attachment-0001.sig>


More information about the libvir-list mailing list