Le vendredi 22 mars 2013 à 23:53 +0100, Lennart Poettering a écrit :
> On Thu, 21.03.13 17:04, Frederic Crozat ([email protected]) wrote:
> 
> > Hi all,
> > 
> > in https://bugzilla.novell.com/show_bug.cgi?id=809646 we noticed LSB
> > Provides can sometime be incorrectly handled (resulting in "Failed to
> > add LSB Provides name XXXX.service, ignoring: File exists" errors),
> > depending on initscript parsing order (if a provides is required by
> > another initscript and this initscript is parsed before the one with the
> > provides).
> 
> Can you explain the problem in more detail? Not following here.

Yes, sorry, I didn't give our test example :

Let's say you have two initscripts, A and B:

A contains in its LSB header:
Required-Start: C

and B contains in its LSB header:
Provides: C

When systemd is parsing /etc/rc.d/, depending on the file order, you can
end up with:
- B is parsed first. An unit "C.service" will be "created" and will be
added as additional name to B.service, with unit_add_name. No bug.
- A is parsed first. An unit "C.service" is created for the
"Required-Start" dependency (it will have no file attached, since
nothing provides this dependency yet). Then B is parsed and when trying
to handle "Provides: C", unit_add_name is called but will fail, because
"C.service" already exists in manager->units. Therefore, a merge should
occur for that case.

> 
> Also, whitespace/coding style issues. 

Will fix.

> Hmm, and also, unit_merge_by_name() looks like the easier way here, as
> it does pretty much what you do here anyway....

Indeed. I overlooked it..

New patch attached.


-- 
Frederic Crozat <[email protected]>
SUSE
>From d43a9dc530261506b62c257021c8433d5bf25388 Mon Sep 17 00:00:00 2001
From: Frederic Crozat <[email protected]>
Date: Thu, 21 Mar 2013 15:40:45 +0100
Subject: [PATCH] core: ensure LSB Provides are handled correctly

Depending on initscript reading order, one initscript might
reference as a Required-Start/Should-Start dependency another
initscript provides, before initscript containing provides has been
parsed and the corresponding in-memory unit has been created. This
change ensure the unit created for the dependency is merged with the
one containing the provides.
---
 src/core/service.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/core/service.c b/src/core/service.c
index 080d583..5c7d919 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -765,7 +765,7 @@ static int service_load_sysv_path(Service *s, const char *path) {
                                                 continue;
 
                                         if (unit_name_to_type(m) == UNIT_SERVICE)
-                                                r = unit_add_name(u, m);
+                                                r = unit_merge_by_name (u, m);
                                         else
                                                 /* NB: SysV targets
                                                  * which are provided
-- 
1.8.1.4

_______________________________________________
systemd-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to