Patchwork [1/2] dhcp: move dhcp leases files handling to postinst/postrm

login
register
mail settings
Submitter Otavio Salvador
Date Feb. 6, 2012, 11:03 a.m.
Message ID <5ffae3864d6ec5dafadff13381d3177c44392b7e.1328526202.git.otavio@ossystems.com.br>
Download mbox | patch
Permalink /patch/20775/
State New
Headers show

Comments

Otavio Salvador - Feb. 6, 2012, 11:03 a.m.
Both server and client needs access to leases files so its creation
and removal are now handled by postinst/postrm scripts.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
 meta/recipes-connectivity/dhcp/dhcp.inc      |   19 ++++++++++++++++++-
 meta/recipes-connectivity/dhcp/dhcp_4.2.0.bb |    2 +-
 2 files changed, 19 insertions(+), 2 deletions(-)
Phil Blundell - Feb. 6, 2012, 11:13 a.m.
On Mon, 2012-02-06 at 11:03 +0000, Otavio Salvador wrote:
> +pkg_postrm_dhcp-server() {
> +    rm -f $D/${localstatedir}/lib/dhcp/dhcpd.leases
> +    rm -f $D/${localstatedir}/lib/dhcp/dhcpd6.leases
> +    rmdir $D/${localstatedir}/lib/dhcp
> +}
> +
> +pkg_postrm_dhcp-client() {
> +    rm -f $D/${localstatedir}/lib/dhcp/dhclient.leases
> +    rm -f $D/${localstatedir}/lib/dhcp/dhclient6.leases
> +    rmdir $D/${localstatedir}/lib/dhcp

Are those rmdirs not going to fail if you try to remove one package with
the other one still installed?

p.
Otavio Salvador - Feb. 6, 2012, 11:21 a.m.
On Mon, Feb 6, 2012 at 09:13, Phil Blundell <philb@gnu.org> wrote:

> On Mon, 2012-02-06 at 11:03 +0000, Otavio Salvador wrote:
> > +pkg_postrm_dhcp-server() {
> > +    rm -f $D/${localstatedir}/lib/dhcp/dhcpd.leases
> > +    rm -f $D/${localstatedir}/lib/dhcp/dhcpd6.leases
> > +    rmdir $D/${localstatedir}/lib/dhcp
> > +}
> > +
> > +pkg_postrm_dhcp-client() {
> > +    rm -f $D/${localstatedir}/lib/dhcp/dhclient.leases
> > +    rm -f $D/${localstatedir}/lib/dhcp/dhclient6.leases
> > +    rmdir $D/${localstatedir}/lib/dhcp
>
> Are those rmdirs not going to fail if you try to remove one package with
> the other one still installed?
>

I think they will. I'll add an || true on it.
Phil Blundell - Feb. 6, 2012, 11:27 a.m.
On Mon, 2012-02-06 at 09:21 -0200, Otavio Salvador wrote:
> On Mon, Feb 6, 2012 at 09:13, Phil Blundell <philb@gnu.org> wrote:
>         On Mon, 2012-02-06 at 11:03 +0000, Otavio Salvador wrote:
>         > +pkg_postrm_dhcp-server() {
>         > +    rm -f $D/${localstatedir}/lib/dhcp/dhcpd.leases
>         > +    rm -f $D/${localstatedir}/lib/dhcp/dhcpd6.leases
>         > +    rmdir $D/${localstatedir}/lib/dhcp
>         > +}
>         > +
>         > +pkg_postrm_dhcp-client() {
>         > +    rm -f $D/${localstatedir}/lib/dhcp/dhclient.leases
>         > +    rm -f $D/${localstatedir}/lib/dhcp/dhclient6.leases
>         > +    rmdir $D/${localstatedir}/lib/dhcp
>         
>         
>         Are those rmdirs not going to fail if you try to remove one
>         package with
>         the other one still installed?
> 
> 
> I think they will. I'll add an || true on it.

If you do that then you'd also need to redirect stderr to avoid getting
error messages on the console.  Might be better to wrap the rmdir calls
in a check to see if the directory is empty.

p.

Patch

diff --git a/meta/recipes-connectivity/dhcp/dhcp.inc b/meta/recipes-connectivity/dhcp/dhcp.inc
index be256ce..92e4d36 100644
--- a/meta/recipes-connectivity/dhcp/dhcp.inc
+++ b/meta/recipes-connectivity/dhcp/dhcp.inc
@@ -66,12 +66,29 @@  FILES_dhcp-server-config = "${sysconfdir}/default/dhcp-server ${sysconfdir}/dhcp
 
 FILES_dhcp-relay = "${sbindir}/dhcrelay ${sysconfdir}/init.d/dhcp-relay ${sysconfdir}/default/dhcp-relay"
 
-FILES_dhcp-client = "${base_sbindir}/dhclient ${base_sbindir}/dhclient-script ${sysconfdir}/dhcp/dhclient.conf ${localstatedir}/lib/dhcp/"
+FILES_dhcp-client = "${base_sbindir}/dhclient ${base_sbindir}/dhclient-script ${sysconfdir}/dhcp/dhclient.conf"
 RDEPENDS_dhcp-client = "bash"
 
 FILES_dhcp-omshell = "${bindir}/omshell"
 
 pkg_postinst_dhcp-server() {
+    mkdir -p $D/${localstatedir}/lib/dhcp
     touch $D/${localstatedir}/lib/dhcp/dhcpd.leases
     touch $D/${localstatedir}/lib/dhcp/dhcpd6.leases
 }
+
+pkg_postinst_dhcp-client() {
+    mkdir -p $D/${localstatedir}/lib/dhcp
+}
+
+pkg_postrm_dhcp-server() {
+    rm -f $D/${localstatedir}/lib/dhcp/dhcpd.leases
+    rm -f $D/${localstatedir}/lib/dhcp/dhcpd6.leases
+    rmdir $D/${localstatedir}/lib/dhcp
+}
+
+pkg_postrm_dhcp-client() {
+    rm -f $D/${localstatedir}/lib/dhcp/dhclient.leases
+    rm -f $D/${localstatedir}/lib/dhcp/dhclient6.leases
+    rmdir $D/${localstatedir}/lib/dhcp
+}
diff --git a/meta/recipes-connectivity/dhcp/dhcp_4.2.0.bb b/meta/recipes-connectivity/dhcp/dhcp_4.2.0.bb
index a3a560b..3b1c0e2 100644
--- a/meta/recipes-connectivity/dhcp/dhcp_4.2.0.bb
+++ b/meta/recipes-connectivity/dhcp/dhcp_4.2.0.bb
@@ -1,6 +1,6 @@ 
 require dhcp.inc
 
-PR = "r5"
+PR = "r7"
 
 SRC_URI += "file://fixincludes.patch \
             file://dhcp-3.0.3-dhclient-dbus.patch;striplevel=0 \