Skip to contentSkip to conversation

dhcp-client: fix invoke dhclient-script failed on Read-only file system

PATCH Superseded Hongxu Jia 3 participants 7 messages Dec 3, 2013 – Dec 10, 2013

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Hongxu Jia

author
#0 lore raw

v2 cover dhcp-client: fix invoke dhclient-script failed on Read-only file system

Change in V2:
* we should *never* check IMAGE_FEATURES in individual recipes. Two reasons:
1) It may cause unnecessary rebuilds.
2) IMAGE_FEATURES may be set in <image>.bb instead of local.conf.

* The make_resolv_conf function in that script doesn't take into consideration the situation in which /etc/resolv.conf is a symlink to /var/run/resolv.conf.

The following changes since commit a17ffbdbb7d142a94ef842a32b749b18e2e7f0a1:

bitbake: hob: fix rotating progress icon animation (2013-12-02 17:51:35 +0000)

are available in the git repository at:

git://git.pokylinux.org/poky-contrib hongxu/fix-dhcpclient
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=hongxu/fix-dhcpclient

Hongxu Jia (2):
dhclient-script: let resolv.conf and resolv.conf.dhclient on the same
direcotry
dhclient-script: override make_resolv_conf for read-only fs

 meta/recipes-connectivity/dhcp/dhcp.inc            |  7 +-
 ...ript-let-resolv.conf-and-resolv.conf.dhcl.patch | 74 ++++++++++++++++++++++
 .../dhcp/files/readonly-dhclient-enter-hooks       | 31 +++++++++
 3 files changed, 111 insertions(+), 1 deletion(-)
 create mode 100644 meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch
 create mode 100644 meta/recipes-connectivity/dhcp/files/readonly-dhclient-enter-hooks
Signature · 1 line
1.8.1.2
author
#1 lore raw

PATCH v2 1/2 dhclient-script: let resolv.conf and resolv.conf.dhclient on the same direcotry

Even though '/etc' is on the readonly partition, it's possible that /etc/resolv.conf is on a separate writable partition.

In this situation, we should make sure the temp file resolv.conf.dhclient on the same direcotry.

[YOCTO #5624]

---
 meta/recipes-connectivity/dhcp/dhcp.inc            |  1 +
 ...ript-let-resolv.conf-and-resolv.conf.dhcl.patch | 74 ++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch
meta/recipes-connectivity/dhcp/dhcp.inc +1 -0
index ad82b57..d8376aa 100644
@@ -16,6 +16,7 @@ SRC_URI = "ftp://ftp.isc.org/isc/dhcp/${PV}/dhcp-${PV}.tar.gz \
            file://site.h \
 	   file://init-relay file://default-relay \
 	   file://init-server file://default-server \
+	   file://dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch \
 	   file://dhclient.conf file://dhcpd.conf"
 
 inherit autotools
meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
1.8.1.2
#2 lore raw

Re: [PATCH 1/2] dhclient-script: let resolv.conf and resolv.conf.dhclient on the same direcotry

Quoted 2 lines · Hongxu Jia
+-      echo search $new_domain_search >> /etc/resolv.conf.dhclient
++      echo search $new_domain_search >> $sysconfdir/esolv.conf.dhclient

Should that be "$sysconfdir/resolv.conf.dhclient"?

p.

author
#3 lore raw

Re: [PATCH 1/2] dhclient-script: let resolv.conf and resolv.conf.dhclient on the same direcotry

Quoted 4 lines · Phil Blundell
Quoted 2 lines · Hongxu Jia
+-      echo search $new_domain_search >> /etc/resolv.conf.dhclient
++      echo search $new_domain_search >> $sysconfdir/esolv.conf.dhclient

Should that be "$sysconfdir/resolv.conf.dhclient"?

Yes, sorry for the missing, I have updated the git tree to fix this.

//Hongxu

Quoted 3 lines

p.

#4 lore raw

Re: [PATCH 1/2] dhclient-script: let resolv.conf and resolv.conf.dhclient on the same direcotry

In reply to Hongxu Jia
Quoted 6 lines · Hongxu Jia

Even though '/etc' is on the readonly partition, it's possible that /etc/resolv.conf is on a separate writable partition.

In this situation, we should make sure the temp file resolv.conf.dhclient on the same direcotry.

Quoted 6 lines

[YOCTO #5624]

---
  meta/recipes-connectivity/dhcp/dhcp.inc            |  1 +
  ...ript-let-resolv.conf-and-resolv.conf.dhcl.patch | 74 ++++++++++++++++++++++

These new scripts are doing alot of out calling from the shell script, and can cause additional fork/execs during the critical path of system startup, is there any way to reduce this?

Sau!

Quoted 96 lines
  2 files changed, 75 insertions(+)

create mode 100644 meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch

meta/recipes-connectivity/dhcp/dhcp.inc +1 -0
index ad82b57..d8376aa 100644
@@ -16,6 +16,7 @@ SRC_URI = "ftp://ftp.isc.org/isc/dhcp/${PV}/dhcp-${PV}.tar.gz \
             file://site.h \
  	   file://init-relay file://default-relay \
  	   file://init-server file://default-server \
+	   file://dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch \
  	   file://dhclient.conf file://dhcpd.conf"
 
  inherit autotools
meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch new file +74 -0
new file mode 100644
index 0000000..db56f70
@@ -0,0 +1,74 @@
+dhclient-script: let resolv.conf and resolv.conf.dhclient on the same direcotry
+
+Even though '/etc' is on the readonly partition, it's possible that
+/etc/resolv.conf is on a separate writable partition.
+
+In this situation, we should make sure the temp file resolv.conf.dhclient
+on the same direcotry.
+
+Upstream-Status: Pending
+Signed-off-by: Hongxu Jia <[email protected]>
+---
+ client/scripts/linux |   24 +++++++++++++-----------
+ 1 file changed, 13 insertions(+), 11 deletions(-)
+
+diff --git a/client/scripts/linux b/client/scripts/linux
+index 6f8ea4b..fbc6324 100755
+--- a/client/scripts/linux
++++ b/client/scripts/linux
+@@ -27,27 +27,29 @@ ip=/sbin/ip
+
+ make_resolv_conf() {
+   if [ x"$new_domain_name_servers" != x ]; then
+-    cat /dev/null > /etc/resolv.conf.dhclient
+-    chmod 644 /etc/resolv.conf.dhclient
++    sysconfdir=`dirname $(readlink -f '/etc/resolv.conf')`
++    cat /dev/null > $sysconfdir/resolv.conf.dhclient
++    chmod 644 $sysconfdir/resolv.conf.dhclient
+     if [ x"$new_domain_search" != x ]; then
+-      echo search $new_domain_search >> /etc/resolv.conf.dhclient
++      echo search $new_domain_search >> $sysconfdir/esolv.conf.dhclient
+     elif [ x"$new_domain_name" != x ]; then
+       # Note that the DHCP 'Domain Name Option' is really just a domain
+       # name, and that this practice of using the domain name option as
+       # a search path is both nonstandard and deprecated.
+-      echo search $new_domain_name >> /etc/resolv.conf.dhclient
++      echo search $new_domain_name >> $sysconfdir/resolv.conf.dhclient
+     fi
+     for nameserver in $new_domain_name_servers; do
+-      echo nameserver $nameserver >>/etc/resolv.conf.dhclient
++      echo nameserver $nameserver >>$sysconfdir/resolv.conf.dhclient
+     done
+
+-    mv /etc/resolv.conf.dhclient /etc/resolv.conf
++    mv $sysconfdir/resolv.conf.dhclient $sysconfdir/resolv.conf
+   elif [ "x${new_dhcp6_name_servers}" != x ] ; then
+-    cat /dev/null > /etc/resolv.conf.dhclient6
+-    chmod 644 /etc/resolv.conf.dhclient6
++    sysconfdir=`dirname $(readlink -f '/etc/resolv.conf')`
++    cat /dev/null > $sysconfdir/resolv.conf.dhclient6
++    chmod 644 $sysconfdir/resolv.conf.dhclient6
+
+     if [ "x${new_dhcp6_domain_search}" != x ] ; then
+-      echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6
++      echo search ${new_dhcp6_domain_search} >> $sysconfdir/resolv.conf.dhclient6
+     fi
+     shopt -s nocasematch
+     for nameserver in ${new_dhcp6_name_servers} ; do
+@@ -59,11 +61,11 @@ make_resolv_conf() {
+       else
+ 	zone_id=
+       fi
+-      echo nameserver ${nameserver}$zone_id >> /etc/resolv.conf.dhclient6
++      echo nameserver ${nameserver}$zone_id >> $sysconfdir/resolv.conf.dhclient6
+     done
+     shopt -u nocasematch
+
+-    mv /etc/resolv.conf.dhclient6 /etc/resolv.conf
++    mv $sysconfdir/resolv.conf.dhclient6 $sysconfdir/resolv.conf
+   fi
+ }
+
+--
+1.7.9.5
+
author
#5 lore raw

Re: [PATCH 1/2] dhclient-script: let resolv.conf and resolv.conf.dhclient on the same direcotry

Quoted 9 lines · Saul Wold
Quoted 8 lines · Hongxu Jia

Even though '/etc' is on the readonly partition, it's possible that /etc/resolv.conf is on a separate writable partition.

In this situation, we should make sure the temp file resolv.conf.dhclient on the same direcotry.

[YOCTO #5624]

Quoted 8 lines
Quoted 5 lines
---
  meta/recipes-connectivity/dhcp/dhcp.inc            |  1 +
  ...ript-let-resolv.conf-and-resolv.conf.dhcl.patch | 74 

++++++++++++++++++++++

These new scripts are doing alot of out calling from the shell script, and can cause additional fork/execs during the critical path of system startup, is there any way to reduce this?

Do you mean the new script :readonly-dhclient-enter-hooks ? If yes, we could just drop the [PATCH 2/2] patch and it could work while read-only is enabled;

Because /etc/resolv.conf is a symlink to /var/run/ resolv.conf in oe-core, and it's always writable:

#ls /etc/resolv.conf -al
lrwxrwxrwx 1 root root 29 Oct 22 2012 /etc/resolv.conf -> /var/run/resolv.conf

//Hongxu

Quoted 112 lines

Sau!

Quoted 109 lines
  2 files changed, 75 insertions(+)

create mode 100644
meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch

meta/recipes-connectivity/dhcp/dhcp.inc +1 -0
index ad82b57..d8376aa 100644
@@ -16,6 +16,7 @@ SRC_URI = 
 "ftp://ftp.isc.org/isc/dhcp/${PV}/dhcp-${PV}.tar.gz \
             file://site.h \
         file://init-relay file://default-relay \
         file://init-server file://default-server \
+ file://dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch \
         file://dhclient.conf file://dhcpd.conf"
 

inherit autotools

meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch +0 -0

new file mode 100644
index 0000000..db56f70
--- /dev/null
+++
b/meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch

meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch +1 -0
@@ -0,0 +1,74 @@
+dhclient-script: let resolv.conf and resolv.conf.dhclient on the 

same direcotry

meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch +5 -0
+
+Even though '/etc' is on the readonly partition, it's possible that
+/etc/resolv.conf is on a separate writable partition.
+
+In this situation, we should make sure the temp file 

resolv.conf.dhclient

meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch +24 -0
+on the same direcotry.
+
+Upstream-Status: Pending
+Signed-off-by: Hongxu Jia <[email protected]>
+---
+ client/scripts/linux |   24 +++++++++++++-----------
+ 1 file changed, 13 insertions(+), 11 deletions(-)
+
+diff --git a/client/scripts/linux b/client/scripts/linux
+index 6f8ea4b..fbc6324 100755
+--- a/client/scripts/linux
++++ b/client/scripts/linux
+@@ -27,27 +27,29 @@ ip=/sbin/ip
+
+ make_resolv_conf() {
+   if [ x"$new_domain_name_servers" != x ]; then
+-    cat /dev/null > /etc/resolv.conf.dhclient
+-    chmod 644 /etc/resolv.conf.dhclient
++    sysconfdir=`dirname $(readlink -f '/etc/resolv.conf')`
++    cat /dev/null > $sysconfdir/resolv.conf.dhclient
++    chmod 644 $sysconfdir/resolv.conf.dhclient
+     if [ x"$new_domain_search" != x ]; then
+-      echo search $new_domain_search >> /etc/resolv.conf.dhclient
++      echo search $new_domain_search >> 

$sysconfdir/esolv.conf.dhclient

meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch +2 -0
+     elif [ x"$new_domain_name" != x ]; then
+       # Note that the DHCP 'Domain Name Option' is really just a 

domain
+ # name, and that this practice of using the domain name
option as

meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch +20 -0
+       # a search path is both nonstandard and deprecated.
+-      echo search $new_domain_name >> /etc/resolv.conf.dhclient
++      echo search $new_domain_name >> $sysconfdir/resolv.conf.dhclient
+     fi
+     for nameserver in $new_domain_name_servers; do
+-      echo nameserver $nameserver >>/etc/resolv.conf.dhclient
++      echo nameserver $nameserver >>$sysconfdir/resolv.conf.dhclient
+     done
+
+-    mv /etc/resolv.conf.dhclient /etc/resolv.conf
++    mv $sysconfdir/resolv.conf.dhclient $sysconfdir/resolv.conf
+   elif [ "x${new_dhcp6_name_servers}" != x ] ; then
+-    cat /dev/null > /etc/resolv.conf.dhclient6
+-    chmod 644 /etc/resolv.conf.dhclient6
++    sysconfdir=`dirname $(readlink -f '/etc/resolv.conf')`
++    cat /dev/null > $sysconfdir/resolv.conf.dhclient6
++    chmod 644 $sysconfdir/resolv.conf.dhclient6
+
+     if [ "x${new_dhcp6_domain_search}" != x ] ; then
+-      echo search ${new_dhcp6_domain_search} >> 

/etc/resolv.conf.dhclient6
++ echo search ${new_dhcp6_domain_search} >>
$sysconfdir/resolv.conf.dhclient6

meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch +8 -0
+     fi
+     shopt -s nocasematch
+     for nameserver in ${new_dhcp6_name_servers} ; do
+@@ -59,11 +61,11 @@ make_resolv_conf() {
+       else
+     zone_id=
+       fi
+-      echo nameserver ${nameserver}$zone_id >> 

/etc/resolv.conf.dhclient6
++ echo nameserver ${nameserver}$zone_id >>
$sysconfdir/resolv.conf.dhclient6

meta/recipes-connectivity/dhcp/dhcp/dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch +11 -0
+     done
+     shopt -u nocasematch
+
+-    mv /etc/resolv.conf.dhclient6 /etc/resolv.conf
++    mv $sysconfdir/resolv.conf.dhclient6 $sysconfdir/resolv.conf
+   fi
+ }
+
+--
+1.7.9.5
+
author
#6 lore raw

PATCH v2 2/2 dhclient-script: override make_resolv_conf for read-only fs

In reply to Hongxu Jia

When dhclient-script starts, the client script first defines a shell function, make_resolv_conf , which is later used to create the /etc/resolv.conf file.

But the read-only filesystem didn't permit the modification, so override the default behaviour and redefine this function in the enter hook script.

http://linux.about.com/library/cmd/blcmdl8_dhclient-script.htm

[YOCTO #5624]
---
 meta/recipes-connectivity/dhcp/dhcp.inc            |  6 ++++-
 .../dhcp/files/readonly-dhclient-enter-hooks       | 31 ++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 meta/recipes-connectivity/dhcp/files/readonly-dhclient-enter-hooks
meta/recipes-connectivity/dhcp/dhcp.inc +5 -1
index d8376aa..58715be 100644
@@ -16,6 +16,7 @@ SRC_URI = "ftp://ftp.isc.org/isc/dhcp/${PV}/dhcp-${PV}.tar.gz \
            file://site.h \
 	   file://init-relay file://default-relay \
 	   file://init-server file://default-server \
+	   file://readonly-dhclient-enter-hooks \
 	   file://dhclient-script-let-resolv.conf-and-resolv.conf.dhcl.patch \
 	   file://dhclient.conf file://dhcpd.conf"
 
@@ -52,6 +53,7 @@ do_install_append () {
 		mv ${D}${sbindir}/dhclient ${D}${base_sbindir}/
 	fi
 	install -m 0755 ${S}/client/scripts/linux ${D}${base_sbindir}/dhclient-script
+	install -m 0755 ${WORKDIR}/readonly-dhclient-enter-hooks ${D}${sysconfdir}/dhclient-enter-hooks
 }
 
 PACKAGES += "dhcp-server dhcp-server-config dhcp-client dhcp-relay dhcp-omshell"
@@ -67,7 +69,9 @@ 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"
+FILES_dhcp-client = "${base_sbindir}/dhclient ${base_sbindir}/dhclient-script ${sysconfdir}/dhcp/dhclient.conf \
+                     ${sysconfdir}/dhclient-enter-hooks \
+"
 RDEPENDS_dhcp-client = "bash"
 
 FILES_dhcp-omshell = "${bindir}/omshell"
meta/recipes-connectivity/dhcp/files/readonly-dhclient-enter-hooks new file +31 -0
new file mode 100644
index 0000000..c43e81f
@@ -0,0 +1,31 @@
+is_on_read_only_partition () {
+    FILE=$1
+    dir=`dirname $(readlink -f "$FILE")`
+    while true; do
+        if [ ! -d "$dir" ]; then
+            echo "ERROR: $dir is not a directory"
+            exit 1
+        else
+            for flag in `awk -v dir=$dir '{ if ($2 == dir) { print "FOUND"; split($4,FLAGS,",") } }; \
+                END { for (f in FLAGS) print FLAGS[f] }' < /proc/mounts`; do
+                [ "$flag" = "FOUND" ] && partition="read-write"
+                [ "$flag" = "ro" ] && { partition="read-only"; break; }
+            done
+            if [ "$dir" = "/" -o -n "$partition" ]; then
+                break
+            else
+                dir=`dirname $dir`
+            fi
+        fi
+    done
+    [ "$partition" = "read-only" ] && echo "yes" || echo "no"
+}
+
+# If resolv.conf on the readonly partition, we should override make_resolv_conf
+if [ `is_on_read_only_partition /etc/resolv.conf` = "no" ]; then
+    return
+fi
+
+make_resolv_conf(){
+    :
+}
Signature · 1 line
1.8.1.2