Patchwork [1/2,V2] systemd: Remove init.d dir if systemd unit file is present and sysvinit not a distro feature

login
register
mail settings
Submitter Shakeel, Muhammad
Date July 29, 2013, 8:09 a.m.
Message ID <1375085392-12339-1-git-send-email-muhammad_shakeel@mentor.com>
Download mbox | patch
Permalink /patch/54671/
State Accepted
Commit 3b9b8d571da6bb3652427e8ccc7948cbcec0e517
Headers show

Comments

Shakeel, Muhammad - July 29, 2013, 8:09 a.m.
From: Muhammad Shakeel <muhammad_shakeel@mentor.com>

If systemd is supported DISTRO_FEATURE and sysvinit is not and also if
systemd_unitdir contains anything then no need to keep init.d scripts
for sysvinit compatibility.

Signed-off-by: Muhammad Shakeel <muhammad_shakeel@mentor.com>
---
 meta/classes/systemd.bbclass |   15 +++++++++++++++
 1 file changed, 15 insertions(+)
Ross Burton - July 29, 2013, 2:34 p.m.
On 29 July 2013 09:09, Shakeel, Muhammad <muhammad_shakeel@mentor.com> wrote:
> +        # If systemd_unitdir contains anything, delete sysv_initddir
> +        if (os.path.exists(systemd_unitdir) and os.listdir(systemd_unitdir)):
> +            shutil.rmtree(sysv_initddir)

Not sure we need the listdir(), why should the function only delete
the directory if it has contents?  If it doesn't have contents you'll
be packaging an empty directory.

Ross
Phil Blundell - July 29, 2013, 2:36 p.m.
On Mon, 2013-07-29 at 15:34 +0100, Burton, Ross wrote:
> On 29 July 2013 09:09, Shakeel, Muhammad <muhammad_shakeel@mentor.com> wrote:
> > +        # If systemd_unitdir contains anything, delete sysv_initddir
> > +        if (os.path.exists(systemd_unitdir) and os.listdir(systemd_unitdir)):
> > +            shutil.rmtree(sysv_initddir)
> 
> Not sure we need the listdir(), why should the function only delete
> the directory if it has contents?  If it doesn't have contents you'll
> be packaging an empty directory.

The directory he's deleting is different to the one that he's listing.

p.
Ross Burton - July 29, 2013, 2:44 p.m.
On 29 July 2013 15:36, Phil Blundell <pb@pbcl.net> wrote:
>> Not sure we need the listdir(), why should the function only delete
>> the directory if it has contents?  If it doesn't have contents you'll
>> be packaging an empty directory.
>
> The directory he's deleting is different to the one that he's listing.

Well spotted.  I'll go get another coffee before "reviewing" anything
else today!

Ross

Patch

diff --git a/meta/classes/systemd.bbclass b/meta/classes/systemd.bbclass
index 9763faa..76f0e7d 100644
--- a/meta/classes/systemd.bbclass
+++ b/meta/classes/systemd.bbclass
@@ -170,3 +170,18 @@  python rm_systemd_unitdir (){
             shutil.rmtree(systemd_unitdir)
 }
 do_install[postfuncs] += "rm_systemd_unitdir "
+
+python rm_sysvinit_initddir (){
+    import shutil
+    sysv_initddir = oe.path.join(d.getVar("D", True), (d.getVar('INIT_D_DIR', True) or "/etc/init.d"))
+
+    if ("systemd" in d.getVar("DISTRO_FEATURES", True).split() and
+        "sysvinit" not in d.getVar("DISTRO_FEATURES", True).split() and
+        os.path.exists(sysv_initddir)):
+        systemd_unitdir = oe.path.join(d.getVar("D", True), d.getVar('systemd_unitdir', True), "system")
+
+        # If systemd_unitdir contains anything, delete sysv_initddir
+        if (os.path.exists(systemd_unitdir) and os.listdir(systemd_unitdir)):
+            shutil.rmtree(sysv_initddir)
+}
+do_install[postfuncs] += "rm_sysvinit_initddir "