Comment 3 for bug 857524

Revision history for this message
Scott Moser (smoser) wrote :

The following are comments on the changes in the patch

fix updating of /etc/resolv.conf for read-only

This patch makes the following changes:
 * instead of writing to a temp file in /etc/, write directly to
   /etc/resolv.conf
 * replace the multiple '>>' with a single '>' and braces. This means
   the file will be opened for write once rather than append many times.
 * opening for write (truncate) keeps the ownership of the file if it exists,
   and correctly follows a symlink.
   This makes the chmod and chown --reference un-necessary
 * use 'grep -i' rather than 'sed' to get the old nameserver entries from
   existing resolv.conf. This is how the linux.udeb does it, and I find it more clean.
 * changes 'wait_for_rw' to take a file argument rather than hard coding /etc

Note, there is an issue with this patch if /etc/resolv.conf is a symlink and
is the symlink (*not the target*) is not owned by root. To demonstrate:
  $ rm -f /tmp/foo /tmp/bar
  $ ln -s /tmp/foo /tmp/bar
  $ sudo sh -c 'echo hi > /tmp/foo'
  $ sudo sh -c 'echo himom > /tmp/bar'
  sh: /tmp/bar: Permission denied

The only solution I see for this is to attempt to resolve the target of the
symlink (readlink -f) and writing directly there instead of through the
symlink.