Debian Bug report logs - #546528
dash's preinst shouldn't rely on /bin/sh

version graph

Package: dash; Maintainer for dash is Gerrit Pape <pape@smarden.org>; Source for dash is src:dash.

Reported by: Sven Joachim <svenjoac@gmx.de>

Date: Sun, 13 Sep 2009 18:45:01 UTC

Severity: critical

Tags: patch

Found in version dash/0.5.5.1-2.2

Fixed in version dash/0.5.5.1-7.3

Done: adam@adam-barratt.org.uk (Adam D. Barratt)

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, svenjoac@gmx.de, Matthias Klose <doko@debian.org>:
Bug#546504; Package bash. (Sun, 13 Sep 2009 18:45:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sven Joachim <svenjoac@gmx.de>:
New Bug report received and forwarded. Copy sent to svenjoac@gmx.de, Matthias Klose <doko@debian.org>. (Sun, 13 Sep 2009 18:45:10 GMT) Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Sven Joachim <svenjoac@gmx.de>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: bash: needs to Pre-Depend on dash
Date: Sun, 13 Sep 2009 20:34:38 +0200
Package: bash
Version: 4.0-5
Severity: critical

The dependency of bash on dash needs to be turned into a pre-dependency,
else bash might be unpacked before dash, losing the /bin/sh symlink in
the process.  Among other things, this would make it impossible to
unpack dash, because dash's preinst is a /bin/sh script...


-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (x86_64)

Kernel: Linux 2.6.30.6-amd64 (SMP w/2 CPU cores)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages bash depends on:
ii  base-files                5.0.0          Debian base system miscellaneous f
ii  dash                      0.5.5.1-2.3    POSIX-compliant shell
ii  debianutils               3.2.1          Miscellaneous utilities specific t
ii  libc6                     2.9-26         GNU C Library: Shared libraries
ii  libncurses5               5.7+20090912-1 shared libraries for terminal hand

Versions of packages bash recommends:
ii  bash-completion               1:1.0-3    programmable completion for the ba

Versions of packages bash suggests:
ii  bash-doc                      4.0-5      Documentation and examples for the

-- no debconf information




Information forwarded to debian-bugs-dist@lists.debian.org:
Bug#546504; Package bash. (Sun, 13 Sep 2009 20:42:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Matthias Klose <doko@debian.org>:
Extra info received and forwarded to list. (Sun, 13 Sep 2009 20:42:03 GMT) Full text and rfc822 format available.

Message #10 received at 546504@bugs.debian.org (full text, mbox):

From: Matthias Klose <doko@debian.org>
To: Sven Joachim <svenjoac@gmx.de>, 546504@bugs.debian.org
Cc: Debian Bug Tracking System <control@bugs.debian.org>
Subject: Re: Bug#546504: bash: needs to Pre-Depend on dash
Date: Sun, 13 Sep 2009 22:39:40 +0200
clone 546504 -1
reassign -1 dash
thanks

On 13.09.2009 20:34, Sven Joachim wrote:
> Package: bash
> Version: 4.0-5
> Severity: critical
>
> The dependency of bash on dash needs to be turned into a pre-dependency,
> else bash might be unpacked before dash, losing the /bin/sh symlink in
> the process.  Among other things, this would make it impossible to
> unpack dash, because dash's preinst is a /bin/sh script...

changing that to a pre-dependency, but dash's preinst shouldn't rely on /bin/sh. 
bash's preinst is a C binary for that reason.




Bug 546504 cloned as bug 546528. Request was from Matthias Klose <doko@debian.org> to control@bugs.debian.org. (Sun, 13 Sep 2009 20:42:04 GMT) Full text and rfc822 format available.

Bug reassigned from package 'bash' to 'dash'. Request was from Matthias Klose <doko@debian.org> to control@bugs.debian.org. (Sun, 13 Sep 2009 20:42:06 GMT) Full text and rfc822 format available.

Bug No longer marked as found in versions bash/4.0-5. Request was from Matthias Klose <doko@debian.org> to control@bugs.debian.org. (Sun, 13 Sep 2009 20:42:07 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Thu, 22 Oct 2009 21:51:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to David Riebenbauer <davrieb@liegesta.at>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Thu, 22 Oct 2009 21:51:03 GMT) Full text and rfc822 format available.

Message #21 received at 546528@bugs.debian.org (full text, mbox):

From: David Riebenbauer <davrieb@liegesta.at>
To: 546528@bugs.debian.org
Cc: control@bugs.debian.org
Subject: [PATCH] make dash's preinst a C binary
Date: Thu, 22 Oct 2009 23:32:29 +0200
retitle 546528 dash's preinst shouldn't rely on /bin/sh
tag 546528 +patch
thanks

* Matthias Klose <doko@debian.org> [2009-10-22 20:08]:
> changing that to a pre-dependency, but dash's preinst shouldn't rely
> on /bin/sh. bash's preinst is a C binary for that reason.

Here's a patch that makes dash's preinst a C binary too.

Regards
David


---
 debian/dash.preinst   |   32 ----------
 debian/dash.preinst.c |  151 +++++++++++++++++++++++++++++++++++++++++++++++++
 debian/rules          |    7 ++-
 3 files changed, 157 insertions(+), 33 deletions(-)
 delete mode 100644 debian/dash.preinst
 create mode 100644 debian/dash.preinst.c

diff --git a/debian/dash.preinst b/debian/dash.preinst
deleted file mode 100644
index 6be584d..0000000
--- a/debian/dash.preinst
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-set -e
-
-divert() {
-	div=$(dpkg-divert --list $1)
-	distrib=${3:-$1.distrib}
-	if [ -z "$div" ]; then
-		dpkg-divert --package dash --divert $distrib --add $1
-		cp -dp $1 $distrib
-		ln -sf $2 $1
-	fi
-}
-
-divert /bin/sh dash
-divert /usr/share/man/man1/sh.1.gz dash.1.gz \
-	/usr/share/man/man1/sh.distrib.1.gz
-#!/bin/sh
-set -e
-
-divert() {
-	div=$(dpkg-divert --list $1)
-	distrib=${3:-$1.distrib}
-	if [ -z "$div" ]; then
-		dpkg-divert --package dash --divert $distrib --add $1
-		cp -dp $1 $distrib
-		ln -sf $2 $1
-	fi
-}
-
-divert /bin/sh dash
-divert /usr/share/man/man1/sh.1.gz dash.1.gz \
-	/usr/share/man/man1/sh.distrib.1.gz
diff --git a/debian/dash.preinst.c b/debian/dash.preinst.c
new file mode 100644
index 0000000..cf32596
--- /dev/null
+++ b/debian/dash.preinst.c
@@ -0,0 +1,151 @@
+/* Copyright (c) 2009 David Riebenbuaer <davrieb@liegesta.at>
+ *
+ * You may freely use, distribute, and modify this program.
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <err.h>
+#include <errno.h>
+#include <error.h>
+
+#define DPKG_DIVERT "/usr/bin/dpkg-divert"
+#define LINE_LEN 1024
+
+void run_op(const char *const op[])
+{
+  pid_t child;
+
+  switch (child = fork()) {
+    case -1:
+      // fork failed
+      {
+        err(EXIT_FAILURE, "fork failed");
+      }
+
+
+    case 0:
+      // child
+      {
+        execvp(op[0], (char *const *)(op));
+
+        err(EXIT_FAILURE, "failed to exec %s", op[0]);
+      }
+
+
+    default:
+      // parent
+      {
+        int status;
+        pid_t pid;
+
+        pid = waitpid(child, &status, 0);
+
+        if (pid != -1) {
+          if (WIFEXITED(status)) {
+            if (WEXITSTATUS(status) == 0) {
+              return;
+            }
+            else {
+              exit(WEXITSTATUS(status));
+            }
+          }
+          else {
+            fprintf(stderr, "child didn't exit normally");
+            exit(EXIT_FAILURE);
+          }
+        }
+        else {
+          err(EXIT_FAILURE, "wait failed");
+        }
+
+        break;
+      }
+  }
+}
+
+void divert(const char *target, const char *source, const char *distrib)
+{
+  pid_t child;
+  int pipedes[2];
+  static char line[LINE_LEN];
+
+  memset(line, '\0', LINE_LEN);
+
+  if (pipe(pipedes)) {
+    err(EXIT_FAILURE, "pipe creation failed");
+  }
+
+  switch(child = fork()) {
+    case -1:
+      // fork failed
+      {
+        int errnum = errno;
+
+        close(pipedes[0]);
+        close(pipedes[1]);
+        error(EXIT_FAILURE, errnum, "fork failed");
+      }
+
+
+    case 0:
+      // child
+      {
+        if (dup2(pipedes[STDOUT_FILENO], STDOUT_FILENO) < 0) {
+          err(EXIT_FAILURE, "replacing stdout with pipe failed");
+        }
+
+        close(pipedes[STDIN_FILENO]);
+        close(pipedes[STDOUT_FILENO]);
+
+        execlp(DPKG_DIVERT, DPKG_DIVERT, "--list", target, NULL);
+
+        err(EXIT_FAILURE, "dpkg-divert exec failed");
+      }
+
+
+    default:
+      // parent
+      {
+        FILE *fd;
+
+        close(pipedes[STDOUT_FILENO]);
+        fcntl(pipedes[STDIN_FILENO], F_SETFD, FD_CLOEXEC);
+        fd = fdopen(pipedes[STDIN_FILENO], "r");
+
+        while (fgets(line, LINE_LEN, fd) != NULL) {
+          line[strlen(line)-1] = '\0';
+          break;
+        }
+        fclose(fd);
+
+        break;
+      }
+  }
+
+  if (strlen(line) == 0) {
+    const char *const dpkg_divert_op[] = {DPKG_DIVERT, "--package", "dash",
+      "--divert", distrib, "--add", target, NULL};
+    const char *const cp_op[] = {"cp", "-pd", target, distrib, NULL};
+    const char *const ln_op[] = {"ln", "-fs", source, target, NULL};
+
+    run_op(dpkg_divert_op);
+    run_op(cp_op);
+    run_op(ln_op);
+  }
+}
+
+int main(void)
+{
+  divert("/bin/sh", "dash", "/bin/sh.distrib");
+  divert("/usr/share/man/man1/sh.1.gz", "dash.1.gz",
+      "/usr/share/man/man1/sh.distrib.1.gz");
+
+  return EXIT_SUCCESS;
+}
+
diff --git a/debian/rules b/debian/rules
index b5f6d7f..c67b3e2 100755
--- a/debian/rules
+++ b/debian/rules
@@ -36,7 +36,7 @@ configure-stamp: patch-stamp
 	  exec ../configure --host='$(DEB_HOST_GNU_TYPE)')
 	touch configure-stamp
 
-build: deb-checkdir build-stamp
+build: preinst-build deb-checkdir build-stamp
 build-stamp: configure-stamp
 	-$(CC) -v
 	(cd build-tmp && exec $(MAKE) CFLAGS='$(CFLAGS)') || \
@@ -55,6 +55,11 @@ clean: deb-checkdir deb-checkuid
 	rm -f configure-stamp patch-stamp build-stamp po-templates-stamp
 	rm -rf '$(DIR)' '$(DIRA)'
 	rm -f debian/files debian/substvars debian/dash.templates changelog
+	rm -f debian/dash.preinst
+
+preinst-build: debian/dash.preinst
+debian/dash.preinst: debian/dash.preinst.c
+	$(CC) -O2 -s -o debian/dash.preinst debian/dash.preinst.c
 
 install: install-indep install-arch
 install-indep: deb-checkdir deb-checkuid




Changed Bug title to 'dash's preinst shouldn't rely on /bin/sh' from 'bash: needs to Pre-Depend on dash' Request was from David Riebenbauer <davrieb@liegesta.at> to control@bugs.debian.org. (Thu, 22 Oct 2009 21:51:04 GMT) Full text and rfc822 format available.

Added tag(s) patch. Request was from David Riebenbauer <davrieb@liegesta.at> to control@bugs.debian.org. (Thu, 22 Oct 2009 21:51:05 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Sat, 23 Jan 2010 12:45:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Helmut Grohne <helmut@subdivi.de>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Sat, 23 Jan 2010 12:45:06 GMT) Full text and rfc822 format available.

Message #30 received at 546528@bugs.debian.org (full text, mbox):

From: Helmut Grohne <helmut@subdivi.de>
To: Gerrit Pape <pape@smarden.org>
Cc: 546528@bugs.debian.org, David Riebenbauer <davrieb@liegesta.at>
Subject: [maintainer ping] Re: [PATCH] make dash's preinst a C binary
Date: Sat, 23 Jan 2010 13:20:35 +0100
Hi Gerrit,

as you can see David Riebenbauer provided a patch to convert
dash.preinst to something not depending on /bin/sh. As far as I can tell
applying this patch would not worsen the situation in any way, but it
would make it easier to work on the bash package. Could you somehow
answer to this bugreport?

Helmut




Bug Marked as found in versions dash/0.5.5.1-2.2. Request was from Sven Joachim <svenjoac@gmx.de> to control@bugs.debian.org. (Tue, 06 Apr 2010 07:42:12 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Sat, 17 Jul 2010 13:48:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Marek Kubica <marek@xivilization.net>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Sat, 17 Jul 2010 13:48:06 GMT) Full text and rfc822 format available.

Message #37 received at 546528@bugs.debian.org (full text, mbox):

From: Marek Kubica <marek@xivilization.net>
To: 546528@bugs.debian.org
Subject: Re: [PATCH] make dash's preinst a C binary
Date: Sat, 17 Jul 2010 15:24:52 +0200
[Message part 1 (text/plain, inline)]
tag +pending
thanks

Hi,

In the course of todays BSP in Munich, I created an NMU patch, you'll
find it attached. I applied David's patch unchanged. I hope we can
upload this at the end of the BSP.

regards,
Marek
[dash-c-preinst.diff (text/x-patch, attachment)]
[signature.asc (application/pgp-signature, attachment)]

Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Sat, 17 Jul 2010 14:09:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Sat, 17 Jul 2010 14:09:03 GMT) Full text and rfc822 format available.

Message #42 received at 546528@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: Marek Kubica <marek@xivilization.net>, 546528@bugs.debian.org
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Sat, 17 Jul 2010 09:04:43 -0500
Hi Marek,

Marek Kubica wrote:

> In the course of todays BSP in Munich, I created an NMU patch, you'll
> find it attached.

I would prefer to see this applied to experimental.  You can remove
debian/diff/0006--INPUT-exit-127-if-command_file-is-given-but-doesn-t.diff
to fix Bug#586807 while at it.

Jonathan




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Sat, 17 Jul 2010 14:15:08 GMT) Full text and rfc822 format available.

Acknowledgement sent to Julien Cristau <jcristau@debian.org>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Sat, 17 Jul 2010 14:15:08 GMT) Full text and rfc822 format available.

Message #47 received at 546528@bugs.debian.org (full text, mbox):

From: Julien Cristau <jcristau@debian.org>
To: Marek Kubica <marek@xivilization.net>, 546528@bugs.debian.org
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Sat, 17 Jul 2010 15:10:27 +0100
[Message part 1 (text/plain, inline)]
On Sat, Jul 17, 2010 at 15:24:52 +0200, Marek Kubica wrote:

> tag +pending
> thanks
> 
> Hi,
> 
> In the course of todays BSP in Munich, I created an NMU patch, you'll
> find it attached. I applied David's patch unchanged. I hope we can
> upload this at the end of the BSP.
> 
> regards,
> Marek

> reverted:
> --- dash-0.5.5.1/debian/dash.preinst
> +++ dash-0.5.5.1.orig/debian/dash.preinst
> @@ -1,27 +0,0 @@
> -#!/bin/sh
> -set -e
> -
> -divert() {
> -	dfile=$1
> -	ltarget=$2
> -	div=$(dpkg-divert --list $dfile)
> -	distrib=${3:-$dfile.distrib}
> -	if [ -z "$div" ]; then
> -		dpkg-divert --package dash --divert $distrib --add $dfile
> -		# This differs from dpkg-divert's --rename because we
> -		# first make a copy of $dfile (the file being diverted)
> -		# in $distrib. Then, a symlink to $ltarget is forcibly created
> -		# from $dfile.
> -		# dpkg-divert's --rename direct equivalent would be:
> -		# mv $dfile $distrib -- but we could end up without a symlink
> -		cp -dp $dfile $distrib
> -		ln -sf $ltarget $dfile
> -	fi
> -}
> -
> -# Divert the following files if no diversion exists already
> -# It is currently used to prevent the files collision between bash and
> -# dash: they both provide the files in the package.
> -divert /bin/sh dash
> -divert /usr/share/man/man1/sh.1.gz dash.1.gz \
> -	/usr/share/man/man1/sh.distrib.1.gz
> diff -u dash-0.5.5.1/debian/changelog dash-0.5.5.1/debian/changelog
> --- dash-0.5.5.1/debian/changelog
> +++ dash-0.5.5.1/debian/changelog
> @@ -1,3 +1,11 @@
> +dash (0.5.5.1-7.1) unstable; urgency=low
> +
> +  * Non-maintainer upload.
> +  * Fix "dash's preinst shouldn't rely on /bin/sh" by applying the patch by
> +    David Riebenbauer (Closes: #546528)
> +
> + -- Marek Kubica <marek@xivilization.net>  Sat, 17 Jul 2010 15:10:54 +0200
> +
>  dash (0.5.5.1-7) unstable; urgency=low
>  
>    [ Raphael Geissert ]
> diff -u dash-0.5.5.1/debian/rules dash-0.5.5.1/debian/rules
> --- dash-0.5.5.1/debian/rules
> +++ dash-0.5.5.1/debian/rules
> @@ -36,7 +36,7 @@
>  	  exec ../configure --host='$(DEB_HOST_GNU_TYPE)')
>  	touch configure-stamp
>  
> -build: deb-checkdir build-stamp
> +build: preinst-build deb-checkdir build-stamp

this should be a dependency of build-stamp, not build.  Also why not use
debian/dash.preinst directly instead of this indirection?

>  build-stamp: configure-stamp
>  	-$(CC) -v
>  	(cd build-tmp && exec $(MAKE) CFLAGS='$(CFLAGS)') || \
> @@ -55,6 +55,11 @@
>  	rm -f configure-stamp patch-stamp build-stamp po-templates-stamp
>  	rm -rf '$(DIR)' '$(DIRA)'
>  	rm -f debian/files debian/substvars debian/dash.templates changelog
> +	rm -f debian/dash.preinst
> +
> +preinst-build: debian/dash.preinst
> +debian/dash.preinst: debian/dash.preinst.c
> +	$(CC) -O2 -s -o debian/dash.preinst debian/dash.preinst.c
>  
-s?

>  install: install-indep install-arch
>  install-indep: deb-checkdir deb-checkuid
> only in patch2:
> unchanged:
> --- dash-0.5.5.1.orig/debian/dash.preinst.c
> +++ dash-0.5.5.1/debian/dash.preinst.c
> @@ -0,0 +1,151 @@
> +/* Copyright (c) 2009 David Riebenbuaer <davrieb@liegesta.at>
> + *
> + * You may freely use, distribute, and modify this program.
> + */
> +
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <err.h>
> +#include <errno.h>
> +#include <error.h>
> +
> +#define DPKG_DIVERT "/usr/bin/dpkg-divert"
> +#define LINE_LEN 1024
> +
> +void run_op(const char *const op[])
> +{
> +  pid_t child;
> +
> +  switch (child = fork()) {
> +    case -1:
> +      // fork failed
> +      {
> +        err(EXIT_FAILURE, "fork failed");
> +      }
> +
> +
> +    case 0:
> +      // child
> +      {
> +        execvp(op[0], (char *const *)(op));
> +
> +        err(EXIT_FAILURE, "failed to exec %s", op[0]);
> +      }
> +
> +
> +    default:
> +      // parent
> +      {
> +        int status;
> +        pid_t pid;
> +
> +        pid = waitpid(child, &status, 0);
> +
> +        if (pid != -1) {
> +          if (WIFEXITED(status)) {
> +            if (WEXITSTATUS(status) == 0) {
> +              return;
> +            }
> +            else {
> +              exit(WEXITSTATUS(status));
> +            }
> +          }
> +          else {
> +            fprintf(stderr, "child didn't exit normally");
> +            exit(EXIT_FAILURE);
> +          }
> +        }
> +        else {
> +          err(EXIT_FAILURE, "wait failed");
> +        }
> +
> +        break;
> +      }
> +  }
> +}
> +
> +void divert(const char *target, const char *source, const char *distrib)
> +{
> +  pid_t child;
> +  int pipedes[2];
> +  static char line[LINE_LEN];
> +
> +  memset(line, '\0', LINE_LEN);
> +
> +  if (pipe(pipedes)) {
> +    err(EXIT_FAILURE, "pipe creation failed");
> +  }
> +
> +  switch(child = fork()) {
> +    case -1:
> +      // fork failed
> +      {
> +        int errnum = errno;
> +
> +        close(pipedes[0]);
> +        close(pipedes[1]);
> +        error(EXIT_FAILURE, errnum, "fork failed");
> +      }
> +
> +
> +    case 0:
> +      // child
> +      {
> +        if (dup2(pipedes[STDOUT_FILENO], STDOUT_FILENO) < 0) {
> +          err(EXIT_FAILURE, "replacing stdout with pipe failed");
> +        }
> +

kind of weird to use STD{IN,OUT}_FILENO here, but 0 and 1 three lines
earlier.

> +        close(pipedes[STDIN_FILENO]);
> +        close(pipedes[STDOUT_FILENO]);
> +
> +        execlp(DPKG_DIVERT, DPKG_DIVERT, "--list", target, NULL);
> +

(void *)NULL instead of NULL.

> +        err(EXIT_FAILURE, "dpkg-divert exec failed");
> +      }
> +
> +
> +    default:
> +      // parent
> +      {
> +        FILE *fd;
> +
> +        close(pipedes[STDOUT_FILENO]);
> +        fcntl(pipedes[STDIN_FILENO], F_SETFD, FD_CLOEXEC);
> +        fd = fdopen(pipedes[STDIN_FILENO], "r");
> +
> +        while (fgets(line, LINE_LEN, fd) != NULL) {
> +          line[strlen(line)-1] = '\0';
> +          break;
> +        }
> +        fclose(fd);
> +

missing waitpid() and handling of dpkg-divert --list failure?

> +        break;
> +      }
> +  }
> +
> +  if (strlen(line) == 0) {
> +    const char *const dpkg_divert_op[] = {DPKG_DIVERT, "--package", "dash",
> +      "--divert", distrib, "--add", target, NULL};
> +    const char *const cp_op[] = {"cp", "-pd", target, distrib, NULL};
> +    const char *const ln_op[] = {"ln", "-fs", source, target, NULL};
> +
> +    run_op(dpkg_divert_op);
> +    run_op(cp_op);
> +    run_op(ln_op);
> +  }
> +}
> +
> +int main(void)
> +{
> +  divert("/bin/sh", "dash", "/bin/sh.distrib");
> +  divert("/usr/share/man/man1/sh.1.gz", "dash.1.gz",
> +      "/usr/share/man/man1/sh.distrib.1.gz");
> +
> +  return EXIT_SUCCESS;
> +}
> +

Cheers,
Julien
[signature.asc (application/pgp-signature, inline)]

Added tag(s) pending. Request was from Marek Kubica <marek@xivilization.net> to control@bugs.debian.org. (Sat, 17 Jul 2010 14:27:02 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Sat, 17 Jul 2010 17:21:05 GMT) Full text and rfc822 format available.

Message #52 received at 546528@bugs.debian.org (full text, mbox):

From: Raphael Geissert <geissert@debian.org>
To: Marek Kubica <marek@xivilization.net>, 546528@bugs.debian.org
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Sat, 17 Jul 2010 12:17:37 -0500
Hi,

On Saturday 17 July 2010 08:24:52 Marek Kubica wrote:
> In the course of todays BSP in Munich, I created an NMU patch, you'll
> find it attached. I applied David's patch unchanged. I hope we can
> upload this at the end of the BSP.

Please hold those changes (or if you insist, upload them to experimental, 
after addressing Julien's comments.) The preinst script needs more changes for 
a successful move of /bin/sh from bash and dash to only dash.
That's already on my debcamp/debconf schedule.

Cheers,
-- 
Raphael Geissert - Debian Developer
www.debian.org - get.debian.net




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Sat, 17 Jul 2010 17:51:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Sat, 17 Jul 2010 17:51:03 GMT) Full text and rfc822 format available.

Message #57 received at 546528@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: 546528@bugs.debian.org
Cc: Marek Kubica <marek@xivilization.net>, Raphael Geissert <geissert@debian.org>
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Sat, 17 Jul 2010 12:48:09 -0500
Raphael Geissert wrote:

> The preinst script needs more changes for 
> a successful move of /bin/sh from bash and dash to only dash.
> That's already on my debcamp/debconf schedule.

Thanks, Raphael.  That’s good to hear.

To clarify: I was only suggesting that any change as big as rewriting
the dash preinst in C should ideally go through experimental first,
unless it is carefully planned and tested in advance some other way.
I am just as happy to see it wait. ;-)

Will there be a vcs repository for interested people to peek at
your changes?




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Sat, 17 Jul 2010 17:57:07 GMT) Full text and rfc822 format available.

Message #60 received at 546528@bugs.debian.org (full text, mbox):

From: Raphael Geissert <geissert@debian.org>
To: 546528@bugs.debian.org
Cc: Marek Kubica <marek@xivilization.net>
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Sat, 17 Jul 2010 12:55:52 -0500
On Saturday 17 July 2010 12:48:09 Jonathan Nieder wrote:
> Will there be a vcs repository for interested people to peek at
> your changes?

Yep, it is already available at
http://git.debian.org/?p=users/geissert/dash.git;a=summary

The changes I've made so far (for the move) are not in that repository, yet.

Cheers,
-- 
Raphael Geissert - Debian Developer
www.debian.org - get.debian.net




Removed tag(s) pending. Request was from Adam D. Barratt <adam@adam-barratt.org.uk> to control@bugs.debian.org. (Fri, 20 Aug 2010 20:03:12 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Wed, 06 Oct 2010 07:15:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Wed, 06 Oct 2010 07:15:03 GMT) Full text and rfc822 format available.

Message #67 received at 546528@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: 546528@bugs.debian.org
Cc: Marek Kubica <marek@xivilization.net>
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Wed, 6 Oct 2010 02:08:03 -0500
Hi Raphael!

Some quick questions about dash.preinst:

1. The diversions for /bin/sh and /usr/share/man/sh.1.gz are handled
separately.  Is that intentional?  What is supposed to happen if
someone diverts /bin/sh but not the manpage (for example because a
maintainer script was interrupted)?

2. The preinst is not idempotent: if interrupted between the
dpkg-divert and cp steps, for example, the cp step will never run.  Is
that fixable?  dpkg-divert --rename seems to have the same (timing-
dependent) bug, fwiw.

3. If dash diverts /bin/sh, then bash's /bin/sh will be diverted
at unpack time: no file conflict.  If bash diverts /bin/sh, then
dash's /bin/sh will be diverted at unpack time: still no file
conflict.  But what if the sysadmin diverts /bin/sh with --local?
Won't this prevent dash from providing a diversion and cause file
conflicts?

Looking forward to your thoughts,
Jonathan




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Thu, 07 Oct 2010 20:03:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Thu, 07 Oct 2010 20:03:06 GMT) Full text and rfc822 format available.

Message #72 received at 546528@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: 546528@bugs.debian.org
Cc: Marek Kubica <marek@xivilization.net>, bash@packages.debian.org, mksh@packages.debian.org, posh@packages.debian.org, ksh@packages.debian.org, pdksh@packages.debian.org
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Thu, 7 Oct 2010 14:57:17 -0500
(+cc: shell people)

Jonathan Nieder wrote:

> 3. If dash diverts /bin/sh, then bash's /bin/sh will be diverted
> at unpack time: no file conflict.  If bash diverts /bin/sh, then
> dash's /bin/sh will be diverted at unpack time: still no file
> conflict.  But what if the sysadmin diverts /bin/sh with --local?
> Won't this prevent dash from providing a diversion and cause file
> conflicts?

Okay, I just tried this locally, and:

 # dpkg-divert --divert /bin/sh.dash --add /bin/sh
 dpkg-divert: `local diversion of /bin/sh to /bin/sh.dash' clashes with `diversion of /bin/sh to /bin/sh.distrib by dash'

So for new installations, it isn't a problem[1].

But for existing installations it is very much a problem.  See
<http://bugs.debian.org/538822>.

Since there is no facility in dpkg for diverting multiple versions of
the same file to different places, one of the two current packages
that ships /bin/sh has to take responsibility for the user's custom
sh.  Let's say it's dash.  Naive procedure.

	1. Copy (or hardlink) /bin/sh to /bin/sh.local
	2. Remove the local diversion!  Divert --package dash
	   /bin/sh to /bin/sh.distrib as usual.
	3. (Optionally) remove /bin/sh.local if it is just a symlink
	   to dash.
	4. Let dash be unpacked, overwriting /bin/sh.
	5. If dash is not configured as the system shell, copy (or
	   hardlink) /bin/sh.local to overwrite /bin/sh in postinst.

The big downside: every time dash is upgraded, there would be a window
of time for these users while /bin/sh points to dash[2].

The example below is meant as pseudocode, completely untested.

Thoughts?

[1] except that preventing sysadmins from making /bin/sh point where
they want is pretty unfriendly.

[2] Longer term (squeeze + 1?) would it not be worth adopting something
like the trick ajt described[3] to remove the /bin/sh link from bash
and allow diversions to work as usual?

[3] http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=85;bug=34717
---
 debian/dash.postinst |   45 ++++++++++++++++++++++++++++-----------------
 debian/dash.preinst  |   16 +++++++++++++---
 debian/dash.prerm    |   31 +++++++++++++++++++++++++++----
 3 files changed, 68 insertions(+), 24 deletions(-)

diff --git a/debian/dash.postinst b/debian/dash.postinst
index 7e8de99..ce8a009 100644
--- a/debian/dash.postinst
+++ b/debian/dash.postinst
@@ -5,6 +5,7 @@ set -e
 check_divert() {
 	dfile=$2; ltarget=$3
 	distrib=${4:-$dfile.distrib}
+	custom=${6:-$dfile.local}
 	diverter=$(dpkg-divert --listpackage $dfile)
 	truename=$(dpkg-divert --truename $dfile)
 	case "$1" in
@@ -35,22 +36,30 @@ check_divert() {
 		fi
 		;;
 	false)
-		if [ "$diverter" = dash ]; then
-			# Simple hack. We also divert sh(1), remember?
-			bash=$(echo "$ltarget"|sed 's/dash/bash/')
-			dpkg-divert --package dash --remove $dfile
-			# The diversion is added as if we were bash, leaving
-			# no diversion would lead to a file conflict later
-			# when re-checked by dpkg
-			dpkg-divert --package bash --divert $distrib --add $dfile
-			# ugh? $truename should always be set (to $distrib)
-			if [ -n "$truename" ]; then
-				rm -f "$truename"
-			fi
-			# Point everything back to bash
-			cp -dp $dfile $distrib
-			ln -sf $bash $dfile
+		if [ "$diverter" != dash ]; then
+			# Great.
+			return 0
+		fi
+		if [ -e "$custom" ]; then
+			# /bin/sh.local exists.
+			# Use that and let dash keep the diversion.
+			cp -dp $custom $dfile
+			return 0
+		fi
+		# Simple hack. We also divert sh(1), remember?
+		bash=$(echo "$ltarget"|sed 's/dash/bash/')
+		dpkg-divert --package dash --remove $dfile
+		# The diversion is added as if we were bash, leaving
+		# no diversion would lead to a file conflict later
+		# when re-checked by dpkg
+		dpkg-divert --package bash --divert $distrib --add $dfile
+		# ugh? $truename should always be set (to $distrib)
+		if [ -n "$truename" ]; then
+			rm -f "$truename"
 		fi
+		# Point everything back to bash
+		cp -dp $dfile $distrib
+		ln -sf $bash $dfile
 		;;
 	ash)
 		# Code not modified by the NMU:
@@ -107,7 +116,8 @@ fi
 if [ "$1" = configure ] && [ -z "$2" ]; then
 	check_divert ash /bin/sh dash '' ash
 	check_divert ash /usr/share/man/man1/sh.1.gz dash.1.gz \
-		/usr/share/man/man1/sh.distrib.1.gz ash.1.gz
+		/usr/share/man/man1/sh.distrib.1.gz ash.1.gz \
+		/usr/share/man/man1/sh.local.1.gz
 	add_shell
 elif [ "$1" = configure ] && dpkg --compare-versions "$2" lt 0.4.18; then
 	add_shell
@@ -117,7 +127,8 @@ if [ $debconf ]; then
 	db_get dash/sh
 	check_divert "$RET" /bin/sh dash
 	check_divert "$RET" /usr/share/man/man1/sh.1.gz dash.1.gz \
-		/usr/share/man/man1/sh.distrib.1.gz
+		/usr/share/man/man1/sh.distrib.1.gz '' \
+		/usr/share/man/man1/sh.local.1.gz
 fi
 
 test "$1" = 'configure' || exit 0
diff --git a/debian/dash.preinst b/debian/dash.preinst
index 6553e2d..6f4afff 100644
--- a/debian/dash.preinst
+++ b/debian/dash.preinst
@@ -4,9 +4,18 @@ set -e
 divert() {
 	dfile=$1
 	ltarget=$2
-	div=$(dpkg-divert --list $dfile)
+	diverter=$(dpkg-divert --listpackage $dfile)
 	distrib=${3:-$dfile.distrib}
-	if [ -z "$div" ]; then
+	custom=${4:-$dfile.local}
+	if [ "$diverter" = LOCAL ]; then
+		cp -ndp $dfile $custom
+		dpkg-divert --local --remove $dfile
+		if [ -h "$custom" ] && [ $(readlink "$custom") = $ltarget ]; then
+			rm -f $custom
+		fi
+		div=
+	fi
+	if [ -z "$diverter" ]; then
 		dpkg-divert --package dash --divert $distrib --add $dfile
 		# This differs from dpkg-divert's --rename because we
 		# first make a copy of $dfile (the file being diverted)
@@ -24,4 +33,5 @@ divert() {
 # dash: they both provide the files in the package.
 divert /bin/sh dash
 divert /usr/share/man/man1/sh.1.gz dash.1.gz \
-	/usr/share/man/man1/sh.distrib.1.gz
+	/usr/share/man/man1/sh.distrib.1.gz \
+	/usr/share/man/man1/sh.local.1.gz
diff --git a/debian/dash.prerm b/debian/dash.prerm
index 88a5dc2..6d458d8 100644
--- a/debian/dash.prerm
+++ b/debian/dash.prerm
@@ -7,10 +7,31 @@
 set -e
 
 remove_divert() {
-	diverter=$(dpkg-divert --listpackage $1)
-	if [ "$diverter" = "dash" ]; then
-		dpkg-divert --package dash --rename --remove $1
+	current=$1
+	distrib=${2:-$current.distrib}
+	custom=${3:-$current.local}
+	diverter=$(dpkg-divert --listpackage $dfile)
+
+	if [ "$diverter" != dash ]; then
+		return 0
+	fi
+	if ! [ -e "$custom" ]; then
+		cp -db $distrib $current
+		dpkg-divert --package dash --remove $1
+		rm -f $distrib
+		return 0
 	fi
+
+	# Reinstate local diversion, if any.
+
+	cp -dp $custom $current
+	# NEEDSWORK: dpkg-divert does not provide a
+	# race-free way for one package to take over
+	# a diversion from another.
+	dpkg-divert --package dash --remove $current
+	dpkg-divert --local --divert $distrib --add $current
+	rm -f $custom
+	return 0
 }
 
 remove_shell() {
@@ -23,7 +44,9 @@ remove_shell() {
 
 if [ "$1" = remove ] || [ "$1" = deconfigure ]; then
 	remove_divert /bin/sh
-	remove_divert /usr/share/man/man1/sh.1.gz
+	remove_divert /usr/share/man/man1/sh.1.gz \
+			/usr/share/man/man1/sh.distrib.1.gz \
+			/usr/share/man/man1/sh.local.1.gz
 fi
 
 if [ "$1" = remove ]; then
-- 
1.7.2.3





Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Thu, 07 Oct 2010 20:15:15 GMT) Full text and rfc822 format available.

Acknowledgement sent to Thorsten Glaser <tg@mirbsd.de>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Thu, 07 Oct 2010 20:15:15 GMT) Full text and rfc822 format available.

Message #77 received at 546528@bugs.debian.org (full text, mbox):

From: Thorsten Glaser <tg@mirbsd.de>
To: Jonathan Nieder <jrnieder@gmail.com>, 546528@bugs.debian.org
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Thu, 7 Oct 2010 20:11:21 +0000 (UTC)
Jonathan Nieder dixit:

>[1] except that preventing sysadmins from making /bin/sh point where
>they want is pretty unfriendly.

ACK.

>Thoughts?

See my signature. Anyway, I think we should have some common, shared
code across all shells that are eligible as /bin/sh in Debian, and
maybe manage /bin/sh as non-diverted non-packaged file, means symbolic
link. The shells’ maintainer scripts can then use #!/bin/foosh shebangs
to avoid being written in C.

bye,
//mirabilos
-- 
Support mksh as /bin/sh and RoQA dash NOW!
‣ src:bash (235 (253) bugs: 0 RC, 177 (192) I&N, 58 (61) M&W, 0 F&P)
‣ src:dash (72 (82) bugs: 4 (9) RC, 49 (54) I&N, 18 M&W, 1 F&P)
‣ src:mksh (2 bugs: 0 RC, 0 I&N, 2 M&W, 0 F&P)




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Fri, 08 Oct 2010 08:09:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to 546528@bugs.debian.org:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Fri, 08 Oct 2010 08:09:03 GMT) Full text and rfc822 format available.

Message #82 received at 546528@bugs.debian.org (full text, mbox):

From: Gerrit Pape <pape@smarden.org>
To: Thorsten Glaser <tg@mirbsd.de>, 546528@bugs.debian.org
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Fri, 8 Oct 2010 07:59:18 +0000
On Thu, Oct 07, 2010 at 08:11:21PM +0000, Thorsten Glaser wrote:
> See my signature. Anyway, I think we should have some common, shared
> code across all shells that are eligible as /bin/sh in Debian, and
> maybe manage /bin/sh as non-diverted non-packaged file, means symbolic
> link. The shells’ maintainer scripts can then use #!/bin/foosh shebangs
> to avoid being written in C.

You keep saying this, you keep sending email about this since ages.  You
even complain that nobody does this for you.  I say, just do it,
finally.  The dash package will benefit from this too, if you manage to
do it right.

You know, I know how to do it.  BUT, in my case, I'm afraid the Debian
people won't like it, and, while I'm willing to do the code, I'm not
willing to end up in endless discussions until the design is accepted,
if at all.  Maybe you're in the same boat?

> and RoQA dash NOW!

What do you mean by this?

Regards, Gerrit.




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Fri, 08 Oct 2010 08:18:10 GMT) Full text and rfc822 format available.

Acknowledgement sent to Julien Cristau <jcristau@debian.org>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Fri, 08 Oct 2010 08:18:10 GMT) Full text and rfc822 format available.

Message #87 received at 546528@bugs.debian.org (full text, mbox):

From: Julien Cristau <jcristau@debian.org>
To: Thorsten Glaser <tg@mirbsd.de>, 546528@bugs.debian.org
Cc: Jonathan Nieder <jrnieder@gmail.com>
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Fri, 8 Oct 2010 10:13:54 +0200
[Message part 1 (text/plain, inline)]
On Thu, Oct  7, 2010 at 20:11:21 +0000, Thorsten Glaser wrote:

> Support mksh as /bin/sh and RoQA dash NOW!
> ‣ src:bash (235 (253) bugs: 0 RC, 177 (192) I&N, 58 (61) M&W, 0 F&P)
> ‣ src:dash (72 (82) bugs: 4 (9) RC, 49 (54) I&N, 18 M&W, 1 F&P)
> ‣ src:mksh (2 bugs: 0 RC, 0 I&N, 2 M&W, 0 F&P)
> 
It turns out having no users means fewer bugs get reported.  Who knew?

Cheers,
Julien
[signature.asc (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Fri, 08 Oct 2010 08:33:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Fri, 08 Oct 2010 08:33:03 GMT) Full text and rfc822 format available.

Message #92 received at 546528@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: 546528@bugs.debian.org
Cc: Thorsten Glaser <tg@mirbsd.de>
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Fri, 8 Oct 2010 03:28:10 -0500
Gerrit Pape wrote:

>                                               I say, just do it,
> finally.  The dash package will benefit from this too, if you manage to
> do it right.

Well said, that.

> You know, I know how to do it.  BUT, in my case, I'm afraid the Debian
> people won't like it, and, while I'm willing to do the code, I'm not
> willing to end up in endless discussions until the design is accepted,
> if at all.  Maybe you're in the same boat?

I missed the earlier discussion (any pointers?) but fwiw I would be
happy with just about any spec for moving forward from the current state
to something robust.  Feel free to send a private email if afraid a
public one would be unproductive (though public is of course better
since it would help the next person in my position).

Aren't Debian developers supposed to be able to just fix things as
long as it doesn't get in the way of others' work?




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Sat, 09 Oct 2010 04:09:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Sat, 09 Oct 2010 04:09:02 GMT) Full text and rfc822 format available.

Message #97 received at 546528@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: 546528@bugs.debian.org
Cc: Thorsten Glaser <tg@mirbsd.de>
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Fri, 8 Oct 2010 23:02:22 -0500
Gerrit Pape wrote:

> You know, I know how to do it.

Okay, I did some digging in the archives.  Sorry to those who
already went over this all.

  debian-package-dash-getv.13@list.smarden.org
  debian-package-dash-getv.39@list.smarden.org
  debian-package-dash-getv.49@list.smarden.org

In April, Gerrit Pape wrote:

>                                            I was hoping there're other
> contributors appearing, so I can learn from their questions, and jump in
> when time permits.

Makes sense.

Previous proposals
~~~~~~~~~~~~~~~~~~
Thorsten's proposal [quoted in 13]:

    Concurrent upload of all shells, with Breaks: old versions of
    other shells.

    Shared debconf template and scripts to turn it into reality.

    The shared template would have permitted values: 'unchanged'
    'dash' 'bash' 'mksh' 'ksh93' 'posh'.

    Upgrade code works like this: drop all diversions.  Update
    symlink.  Add diversion if some package wants to ship /bin/sh.

Sounds good, but it does not address how bash can lose /bin/sh
without causing breakage during the upgrade.

Raphael's proposal [13]:

    bash loses /bin/sh!  Like so:

     - dash's preinst is rewritten in C, so it does not require
       /bin/sh initially.
     - bash's postinst removes any diversion from dash, if present,
       taking care to preserve /bin/sh.
     - dash's preinst still adds a diversion, to make room for its
       /bin/sh.
     - bash pre-depends on this version of dash.
     - Any shell except dash that wants to divert /bin/sh has to
       predepend on this bash version; doing so makes everything okay.
     - Any shell that wants to divert /bin/sh, including bash, does
       so with a debconf prompt after it is installed.

Presumably the idea is that before bash is updated, its /bin/sh is
always diverted, so the removal of bash's copy of /bin/sh causes
no harm.

I don't see why dash's preinst urgently has to be rewritten in C
(though I don't disagree that it's a good thing to do); if /bin/bash
is missing, aren't we in deep trouble anyway?

Where to go from here
~~~~~~~~~~~~~~~~~~~~~
Based on the above, a possible order of operations:

  I. Get rid of /bin/sh in bash.

     Preinst:
       1. Ensures some _other_ package (e.g., dash) diverts /bin/sh.
       2. Makes sure /bin/sh points to the same place at the
          beginning and end.
     Files list: removes /bin/sh

     The result is that /bin/sh is unchanged and that (if anything
     does) dash nominally provides /bin/sh.  The next time dash is
     unpacked, it would overwrite /bin/sh.

 II. Teach dash to cope with (I).

     Precondition: /bin/sh exists.

     Preinst:
       1. Reads /bin/sh to determine who should provide it.
       2. Set up the corresponding diversion.
     Files list: /bin/sh -> dash

     Rationale: Resetting the /bin/sh diversion before unpacking
     dash prevents the problem described in (I).

III. Teach bash to avoid the problem with (I).

     Pre-Depends: dash (>= the version from (II))

Thoughts?  Questions?  Advice?

Thanks,
Jonathan

A somewhat orthogonal task
~~~~~~~~~~~~~~~~~~~~~~~~~~
IV. Introduce a new package to take responsibility for the /bin/sh symlink.

    Preinst (not necessarily in this order):
      1. Removes all diversions
      2. Sets up a diversion
      3. Makes sure /bin/sh points to the same place at the
         beginning and end.
    Debconf prompt lets a person choose what shell to use.
    Postinst makes sure /bin/sh points to the configured place.

    It is be hard to get this right while avoiding file conflicts
    until only one package provides /bin/sh, but it should be possible
    to experiment on lenny.

 V. Teach shells to rely on the package from (IV) for configuration.




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Sat, 09 Oct 2010 12:39:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Thorsten Glaser <tg@mirbsd.de>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Sat, 09 Oct 2010 12:39:03 GMT) Full text and rfc822 format available.

Message #102 received at 546528@bugs.debian.org (full text, mbox):

From: Thorsten Glaser <tg@mirbsd.de>
To: 546528@bugs.debian.org
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Sat, 9 Oct 2010 12:34:06 +0000 (UTC)
Jonathan Nieder dixit:

>Thoughts?  Questions?  Advice?

Other shells would need to be changed to cope with that as well.
The situation is a bit tricky at the moment, because mksh also
contains code to manage a diversion, which only works if dash
doesn’t, though.

Worse, on upgrade from lenny to squeeze dash fails to install if
mksh is /bin/sh…

>A somewhat orthogonal task
>~~~~~~~~~~~~~~~~~~~~~~~~~~
>IV. Introduce a new package to take responsibility for the /bin/sh symlink.

I wonder whether this should be a shell or just an “empty” package…
on the other hand, mksh-static could be split into its own binary
package and do that. It’s small (unless built with eglibc, but I’m
working on getting klibc up to the task), statically linked, fast,
and can easily relinquish control of /bin/sh since it’s basically
mksh’s little brother, with respect to features etc.

No matter if it’s empty or not, I think that, still, all shells
(eligible for /bin/sh) would need to be changed at the same time
for this. On the upside, it could read the pre-existing /bin/sh
symlink at preinst time and keep it, whether it’s from a package
(dash or bash), a diversion (bash, dash, mksh), or manually set.

Actually, couldn’t some things be done in postinst using pre-depends,
to avoid needing C for the preinst “script”? (#!/bin/mysh instead
of #!/bin/sh then, as the files are unpacked.)


Anyway, for the record; while I may be able to point out some more
things to think of when designing a fix, I’m nowhere at a level of
Debian skill to do that myself (alone) as had been suggested. I’ll
gladly help though, if I can.

bye,
//mirabilos
-- 
I believe no one can invent an algorithm. One just happens to hit upon it
when God enlightens him. Or only God invents algorithms, we merely copy them.
If you don't believe in God, just consider God as Nature if you won't deny
existence.		-- Coywolf Qi Hunt




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Wed, 13 Oct 2010 09:27:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>, 546528@bugs.debian.org, Thorsten Glaser <tg@mirbsd.de>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Wed, 13 Oct 2010 09:27:06 GMT) Full text and rfc822 format available.

Message #107 received at 546528@bugs.debian.org (full text, mbox):

From: Gerrit Pape <pape@smarden.org>
To: Jonathan Nieder <jrnieder@gmail.com>, 546528@bugs.debian.org
Cc: Thorsten Glaser <tg@mirbsd.de>
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Wed, 13 Oct 2010 09:25:04 +0000
On Fri, Oct 08, 2010 at 11:02:22PM -0500, Jonathan Nieder wrote:
> A somewhat orthogonal task
> ~~~~~~~~~~~~~~~~~~~~~~~~~~
> IV. Introduce a new package to take responsibility for the /bin/sh symlink.
> 
>     Preinst (not necessarily in this order):
>       1. Removes all diversions
>       2. Sets up a diversion
>       3. Makes sure /bin/sh points to the same place at the
>          beginning and end.
>     Debconf prompt lets a person choose what shell to use.
>     Postinst makes sure /bin/sh points to the configured place.
> 
>     It is be hard to get this right while avoiding file conflicts
>     until only one package provides /bin/sh, but it should be possible
>     to experiment on lenny.
> 
>  V. Teach shells to rely on the package from (IV) for configuration.

Hi Jonathan, this roughly is the design I had in mind, but people
started a different implementation back than, adjusting the diversion
handling in the maintainer scripts.  Since then I wait for them to
either complete the task (I never signed up for it), or give up.

In my opinion adding the same diversion handling to mksh was a bad move,
diversions only work for exactly one package, so mksh actually needs to
conflict with dash.  Herbert added this diversion handling to dash in
2001.

If a new package is introduced that takes over /bin/sh, it needs to
guarantee than some working /bin/sh symlink always exists.  In the end
no more diversions should be involved, and for upgrades the new package
can record where /bin/sh points to, and remove the diversion without
changing the symlink.  A debconf question to choose where /bin/sh points
to sounds reasonable, even though I'm not a fan of debconf.

If this all is done correctly, we nearly have a new and robust
implementation of update-alternative.  The current one isn't an option
because people are not sure that it always does the right thing, here:
guarantee that a working alternative always exists.

I doubt though, that these changes can go into squeeze that late.

Thanks a lot for your contributions.

Regards, Gerrit.




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Thu, 14 Oct 2010 21:48:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Adam D. Barratt" <adam@adam-barratt.org.uk>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Thu, 14 Oct 2010 21:48:03 GMT) Full text and rfc822 format available.

Message #112 received at 546528@bugs.debian.org (full text, mbox):

From: "Adam D. Barratt" <adam@adam-barratt.org.uk>
To: Jonathan Nieder <jrnieder@gmail.com>, 546528@bugs.debian.org
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Thu, 14 Oct 2010 22:44:50 +0100
On Fri, 2010-10-08 at 23:02 -0500, Jonathan Nieder wrote:
> Presumably the idea is that before bash is updated, its /bin/sh is
> always diverted, so the removal of bash's copy of /bin/sh causes
> no harm.
> 
> I don't see why dash's preinst urgently has to be rewritten in C
> (though I don't disagree that it's a good thing to do);

The key thing is that if the move to dash-as-default - or an upgrade of
dash whilst it is the default shell - fails, that should not leave the
system without a working /bin/sh.  Having it not be a shell script seems
a reasonable why of achieving that. :-)

> if /bin/bash
> is missing, aren't we in deep trouble anyway?

Yes.  dash's preinst (in 0.5.5.1-7) currently has a /bin/sh shebang,
however.

Regards,

Adam





Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Sun, 17 Oct 2010 07:09:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Sun, 17 Oct 2010 07:09:03 GMT) Full text and rfc822 format available.

Message #117 received at 546528@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: "Adam D. Barratt" <adam@adam-barratt.org.uk>
Cc: 546528@bugs.debian.org
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Sun, 17 Oct 2010 02:02:41 -0500
Adam D. Barratt wrote:

> The key thing is that if the move to dash-as-default - or an upgrade of
> dash whilst it is the default shell - fails, that should not leave the
> system without a working /bin/sh.  Having it not be a shell script seems
> a reasonable why of achieving that. :-)

Yes, makes sense.

>> if /bin/bash
>> is missing, aren't we in deep trouble anyway?
>
> Yes.  dash's preinst (in 0.5.5.1-7) currently has a /bin/sh shebang,
> however.

So how about something like this, for some peace of mind while
experimenting?

In the initial bootstrap, both dash and bash are unpacked before
either preinst runs.
---
diff --git a/debian/changelog b/debian/changelog
index 673c363..c3d33a1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+dash (0.5.5.1-7.1) experimental; urgency=low
+
+  * debian/dash.preinst: change shebang line to #!/bin/bash.
+
+ -- Jonathan Nieder <jrnieder@gmail.com>  Sun, 17 Oct 2010 01:58:20 -0500
+
 dash (0.5.5.1-7) unstable; urgency=low
 
   [ Raphael Geissert ]
diff --git a/debian/dash.preinst b/debian/dash.preinst
index 6553e2d..4fdbb0d 100644
--- a/debian/dash.preinst
+++ b/debian/dash.preinst
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 set -e
 
 divert() {
-- 




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Wed, 17 Nov 2010 13:45:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Adam D. Barratt" <adam@adam-barratt.org.uk>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Wed, 17 Nov 2010 13:45:03 GMT) Full text and rfc822 format available.

Message #122 received at 546528@bugs.debian.org (full text, mbox):

From: "Adam D. Barratt" <adam@adam-barratt.org.uk>
To: 546528@bugs.debian.org
Cc: "Jonathan Nieder" <jrnieder@gmail.com>
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Wed, 17 Nov 2010 13:40:31 -0000
Hi,

This bug report seems to have branched in to a couple of issues relating
to dash's use of diversions and its use as /bin/sh, rather than the
original issue of whether the preinst should be moved to something that
doesn't rely on /bin/sh working; some of these should probably be moved
elsewhere:

* handling of local diversions
- already #538822
- as such diversions must have been manually added, for squeeze this may
be a documented upgrade issue (in the release notes)

* extending the handling of /bin/sh to include more shells than bash and dash
- definitely post-squeeze material

* the preinst isn't idempotent
- from a few quick tests, it looks like this could be resolved by changing
the execution order to "cp, ln, divert" rather than "divert, cp, ln"; I
may have missed something, however

That leaves us with the question of what should be done in terms of not
having dash's preinst be a /bin/sh script.  I think everyone agrees that
this should be done; the current suggestions appear to be:

* make it a /bin/bash script instead

This is a "no brainer" change in terms of ensuring correctness; no changes
are required to the remainder of the script.  It does mean that dash can't
be reinstalled in a situation where the installation of bash is damaged.

* make it a compiled C program

This means that dash can be reinstalled in situations where both bash and
dash are damaged or otherwise unavailable and means dash doesn't require
bash.  Both of these are certainly reasonable goals, but this approach is
a more fundamental change and may be more difficult to test, so the
question is whether the potential gains are worth the risk at this stage
of the release process.

The transition to dash-as-bin-sh won't realistically allow users to remove
bash from squeeze systems without both overriding the package manager and
careful consideration of the consequences in any case - bash is still
essential and there are therefore a number of packages which ship
/bin/bash scripts with no dependency (devscripts being an example I know
ottomh).

Regards,

Adam





Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Wed, 17 Nov 2010 16:21:08 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Wed, 17 Nov 2010 16:21:08 GMT) Full text and rfc822 format available.

Message #127 received at 546528@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: "Adam D. Barratt" <adam@adam-barratt.org.uk>
Cc: 546528@bugs.debian.org, 538822@bugs.debian.org, 602483@bugs.debian.org
Subject: Re: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Wed, 17 Nov 2010 10:17:37 -0600
Hi,

Adam D. Barratt wrote:

> This bug report seems to have branched in to a couple of issues relating
> to dash's use of diversions and its use as /bin/sh, rather than the
> original issue of whether the preinst should be moved to something that
> doesn't rely on /bin/sh working; some of these should probably be moved
> elsewhere:

Thanks, this is a good summary.

> * handling of local diversions
> - already #538822
> - as such diversions must have been manually added, for squeeze this may
> be a documented upgrade issue (in the release notes)

This was advertised by bash as the way to use dash as /bin/sh for a long
time.

An automagic upgrade is a lovely thing, but for a few reasons this
seems less important than the other issues, especially:

 - it's a noisy failure, not silent breakage.
 - if those diversions were added in order to set dash as /bin/sh,
   it's easy to repair.

> * extending the handling of /bin/sh to include more shells than bash and dash
> - definitely post-squeeze material

That's probably the right choice, since only one person seems to be
working on it. :(

This is a serious regression from lenny.  I wish it would be fixed
soon in squeeze-backports at least.

The main component (an upgrade path in bash to remove /bin/sh from its
files list without disturbing the configured shell) has been written
and seems to work fine.  See Bug#602483.  I have some cosmetic
improvements saved up for that patch but I can't tell if there's any
interest...

To be clear, anyone can help out with this; it does not have to be a
release manager or bash maintainer.  A nice first step to work towards
would be a collection of updated packages in experimental, so we can
have people test it.

> * the preinst isn't idempotent
> - from a few quick tests, it looks like this could be resolved by changing
> the execution order to "cp, ln, divert" rather than "divert, cp, ln"; I
> may have missed something, however

Technically one would need

	# nothing except dash prerm seems to care about the .distrib
	# file, so this is relatively safe.
	cp -dp $dfile $distrib

	# ln -sf is not idempotent, though ln -s to temporary + mv is.
	ln -sf $ltarget $tmpfile
	mv -f $tmpfile $dfile

	dpkg-divert --package dash --divert $distrib --add $dfile

The window when this can happen is very short, and the failure modes
are not so bad (except if ln -sf is interrupted in the middle.  That
one would mean no /bin/sh).

> * make it a /bin/bash script instead
>
> This is a "no brainer" change in terms of ensuring correctness; no changes
> are required to the remainder of the script.  It does mean that dash can't
> be reinstalled in a situation where the installation of bash is damaged.

That is not a big problem.  dash can't be reinstalled in a situation
where the installation of libc is damaged, either.  In practice what
you would do is, from an open shell,

 1. Reinstall bash.
 2. Reinstall dash.

and all is well again.

> * make it a compiled C program
>
> This means that dash can be reinstalled in situations where both bash and
> dash are damaged or otherwise unavailable and means dash doesn't require
> bash.  Both of these are certainly reasonable goals, but this approach is
> a more fundamental change and may be more difficult to test, so the
> question is whether the potential gains are worth the risk at this stage
> of the release process.

I think this could be done safely, but the effect on maintainability
just doesn't seem worth it.

> Regards,

Thanks.
Jonathan




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Wed, 17 Nov 2010 16:30:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Wed, 17 Nov 2010 16:30:05 GMT) Full text and rfc822 format available.

Message #132 received at 546528@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: "Adam D. Barratt" <adam@adam-barratt.org.uk>
Cc: 546528@bugs.debian.org, 538822@bugs.debian.org, 602483@bugs.debian.org
Subject: Re: Bug#538822: Bug#546528: [PATCH] make dash's preinst a C binary
Date: Wed, 17 Nov 2010 10:26:11 -0600
Jonathan Nieder wrote:
> Adam D. Barratt wrote:

>> * the preinst isn't idempotent
>> - from a few quick tests, it looks like this could be resolved by changing
>> the execution order to "cp, ln, divert" rather than "divert, cp, ln"; I
>> may have missed something, however
>
> Technically one would need
> 
> 	# nothing except dash prerm seems to care about the .distrib
> 	# file, so this is relatively safe.
> 	cp -dp $dfile $distrib
> 
> 	# ln -sf is not idempotent, though ln -s to temporary + mv is.
> 	ln -sf $ltarget $tmpfile
> 	mv -f $tmpfile $dfile
> 
> 	dpkg-divert --package dash --divert $distrib --add $dfile
> 
> The window when this can happen is very short, and the failure modes
> are not so bad (except if ln -sf is interrupted in the middle.  That
> one would mean no /bin/sh).

To be precise, of course "ln -sf dash /bin/sh" is idempotent; it's just that
it's not safe to interrupt it because it works by calling unlink() followed
by symlink().  Sorry for the lack of clarify.




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Fri, 19 Nov 2010 23:51:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Adam D. Barratt" <adam@adam-barratt.org.uk>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Fri, 19 Nov 2010 23:51:03 GMT) Full text and rfc822 format available.

Message #137 received at 546528@bugs.debian.org (full text, mbox):

From: "Adam D. Barratt" <adam@adam-barratt.org.uk>
To: debian-release@lists.debian.org
Cc: 546528@bugs.debian.org, Jonathan Nieder <jrnieder@gmail.com>
Subject: Pre-unblock: dash 0.5.5.1-7.3
Date: Fri, 19 Nov 2010 23:47:55 +0000
[Message part 1 (text/plain, inline)]
Hi,

I'm proposing NMUing dash to fix #546528, which relates to the fact that
the preinst script uses a /bin/sh shebang.

For ease of review and to reduce the risk of breaking things at this
stage of the cycle, I've chosen the simpler approach of moving the
script to use bash as its interpreter instead.  Moving it to be ELF - as
per bash - might be preferable in the longer run, but at least for the
squeeze stable cycle users aren't going to be able to remove bash from
their systems in any case.

I'm also proposing a few smaller changes to the preinst to make it (more
or less) idempotent, as discussed in the bug.  Things can probably still
go wrong if the install is interrupted between the mv and the divert,
but imho that's an improvement relative to the current version.

I've attached a debdiff of the changes, which I've verified by
installing the package in both lenny and squeeze chroots and as part of
an "install" by injecting it in to a local mirror and pointing
"cdebootstrap squeeze" at that.

(The postinst also has possible idempotency issues, but these seemed
more invasive to fix so I've avoided trying to resolve them at this
point.)

Comments welcome.

Regards,

Adam
[dash_546528.diff (text/x-patch, attachment)]

Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Sat, 20 Nov 2010 00:12:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonathan Nieder <jrnieder@gmail.com>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Sat, 20 Nov 2010 00:12:03 GMT) Full text and rfc822 format available.

Message #142 received at 546528@bugs.debian.org (full text, mbox):

From: Jonathan Nieder <jrnieder@gmail.com>
To: "Adam D. Barratt" <adam@adam-barratt.org.uk>
Cc: debian-release@lists.debian.org, 546528@bugs.debian.org
Subject: Re: Pre-unblock: dash 0.5.5.1-7.3
Date: Fri, 19 Nov 2010 18:08:25 -0600
Adam D. Barratt wrote:

> diff -u dash-0.5.5.1/debian/dash.preinst dash-0.5.5.1/debian/dash.preinst
> --- dash-0.5.5.1/debian/dash.preinst
> +++ dash-0.5.5.1/debian/dash.preinst
> @@ -1,4 +1,4 @@
> -#!/bin/sh
> +#!/bin/bash
>  set -e
>  
>  divert() {
> @@ -6,16 +6,19 @@
>  	ltarget=$2
>  	div=$(dpkg-divert --list $dfile)
>  	distrib=${3:-$dfile.distrib}
> +	temp=$dfile.tmp
>  	if [ -z "$div" ]; then
> -		dpkg-divert --package dash --divert $distrib --add $dfile
>  		# This differs from dpkg-divert's --rename because we
>  		# first make a copy of $dfile (the file being diverted)
>  		# in $distrib. Then, a symlink to $ltarget is forcibly created
> -		# from $dfile.
> +		# from $dfile; this is performed in two stages with an
> +		# intermediate temporary file as ln -sf is not idempotent.

The word I was thinking of before is atomic.  ln -sf is not atomic.

>  		# dpkg-divert's --rename direct equivalent would be:
>  		# mv $dfile $distrib -- but we could end up without a symlink
>  		cp -dp $dfile $distrib
> -		ln -sf $ltarget $dfile
> +		ln -sf $ltarget $temp
> +		mv -f $temp $dfile
> +		dpkg-divert --package dash --divert $distrib --add $dfile

If preinst is interrupted after the mv but before the dpkg-divert,
then /bin/sh will point to dash but it will not be diverted yet, so if
bash were installed before preinst gets a chance to run again, /bin/sh
would be overwritten.  That seems fine to me, expected even.

Thanks, this looks good.

Jonathan




Information forwarded to debian-bugs-dist@lists.debian.org, Gerrit Pape <pape@smarden.org>:
Bug#546528; Package dash. (Mon, 22 Nov 2010 20:51:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Adam D. Barratt" <adam@adam-barratt.org.uk>:
Extra info received and forwarded to list. Copy sent to Gerrit Pape <pape@smarden.org>. (Mon, 22 Nov 2010 20:51:03 GMT) Full text and rfc822 format available.

Message #147 received at 546528@bugs.debian.org (full text, mbox):

From: "Adam D. Barratt" <adam@adam-barratt.org.uk>
To: 546528@bugs.debian.org
Subject: dash: diff for NMU version 0.5.5.1-7.3
Date: Mon, 22 Nov 2010 20:47:16 +0000
[Message part 1 (text/plain, inline)]
tags 546528 + pending
thanks

Dear maintainer,

I've prepared an NMU for dash (versioned as 0.5.5.1-7.3) and
uploaded it to DELAYED/1. Please feel free to tell me if I
should delay it longer.

Regards,

Adam
[dash_0.5.5.1-7.3.diff (text/x-patch, attachment)]

Added tag(s) pending. Request was from "Adam D. Barratt" <adam@adam-barratt.org.uk> to control@bugs.debian.org. (Mon, 22 Nov 2010 20:51:06 GMT) Full text and rfc822 format available.

Reply sent to adam@adam-barratt.org.uk (Adam D. Barratt):
You have taken responsibility. (Tue, 23 Nov 2010 21:06:07 GMT) Full text and rfc822 format available.

Notification sent to Sven Joachim <svenjoac@gmx.de>:
Bug acknowledged by developer. (Tue, 23 Nov 2010 21:06:07 GMT) Full text and rfc822 format available.

Message #154 received at 546528-close@bugs.debian.org (full text, mbox):

From: adam@adam-barratt.org.uk (Adam D. Barratt)
To: 546528-close@bugs.debian.org
Subject: Bug#546528: fixed in dash 0.5.5.1-7.3
Date: Tue, 23 Nov 2010 21:02:51 +0000
Source: dash
Source-Version: 0.5.5.1-7.3

We believe that the bug you reported is fixed in the latest version of
dash, which is due to be installed in the Debian FTP archive:

ash_0.5.5.1-7.3_all.deb
  to main/d/dash/ash_0.5.5.1-7.3_all.deb
dash_0.5.5.1-7.3.diff.gz
  to main/d/dash/dash_0.5.5.1-7.3.diff.gz
dash_0.5.5.1-7.3.dsc
  to main/d/dash/dash_0.5.5.1-7.3.dsc
dash_0.5.5.1-7.3_amd64.deb
  to main/d/dash/dash_0.5.5.1-7.3_amd64.deb



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 546528@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Adam D. Barratt <adam@adam-barratt.org.uk> (supplier of updated dash package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Format: 1.8
Date: Wed, 17 Nov 2010 21:41:30 +0000
Source: dash
Binary: dash ash
Architecture: source all amd64
Version: 0.5.5.1-7.3
Distribution: unstable
Urgency: medium
Maintainer: Gerrit Pape <pape@smarden.org>
Changed-By: Adam D. Barratt <adam@adam-barratt.org.uk>
Description: 
 ash        - compatibility package for dash
 dash       - POSIX-compliant shell
Closes: 546528
Changes: 
 dash (0.5.5.1-7.3) unstable; urgency=medium
 .
   * Non-maintainer upload.
   * Modify the preinst to use /bin/bash rather than /bin/sh to avoid having
     to rely on /bin/sh being available during unpack.  (Closes: #546528)
   * Adapt preinst diversion handling to be idempotent; thanks to
     Jonathan Nieder.
Checksums-Sha1: 
 a483a83200ddc4715bf98ed93d2d89fd5020e843 1675 dash_0.5.5.1-7.3.dsc
 263db9612c1fc7b22a70353054a3a3e6edee9dfd 50441 dash_0.5.5.1-7.3.diff.gz
 0c5c54c8466d3a4704e42f0459d9e3e7787bf9c5 25500 ash_0.5.5.1-7.3_all.deb
 9de42db3d2232925011a7d2e8013d0efcc5d1696 107622 dash_0.5.5.1-7.3_amd64.deb
Checksums-Sha256: 
 60de60104fb5ff35ad52f104c5dd66f148ba4da75421c2bf840a84955e5077a1 1675 dash_0.5.5.1-7.3.dsc
 b015748fb4e8e7c775ca461e9bd34cdd60a7dc35bf82adbbf1fdab2100d61836 50441 dash_0.5.5.1-7.3.diff.gz
 1b5cbc0a4bfd907476f9447d1f0dd05040189f745135cd22e0e51127743127d3 25500 ash_0.5.5.1-7.3_all.deb
 34ced694ea9a0bb29cc8eb42f18fc0d63317ead0d404f3efe738dbe3266d2390 107622 dash_0.5.5.1-7.3_amd64.deb
Files: 
 33b745a7921989675de5b99a14bc6469 1675 shells optional dash_0.5.5.1-7.3.dsc
 1f5bbe8527e4320857aadd9f8eac603b 50441 shells optional dash_0.5.5.1-7.3.diff.gz
 b45d0ab86c1a833e4889ef2a702455a7 25500 shells optional ash_0.5.5.1-7.3_all.deb
 ecfee63acad6f6bd513361051935fe1d 107622 shells required dash_0.5.5.1-7.3_amd64.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQIcBAEBCAAGBQJM6tWFAAoJEMXOXcLFQs1ZiZ0P/12LCmbfyI9VokpcbPqaBeK2
IzgyDOMBRDtEqFaumVbh+WZfqsrkrQIViyEDu8e/hPRjppDLsnq6rUWyaMWHyTuu
FYxJZTWXlknMQ+lAzpw0yemQ5lMBCgKVlb54dVVmunJnxhMRkZihYK8DtnuStEX/
kOEpu+8iBs+b0iqkC1jn7tb3dEl3A9ewhO15IIJsJdmZ+tbWULI07WiDmYBRhihr
FaAJk4NRuHRumS1b+DhoZAPRsx6YRPu0nvn86LvP5OJXMFT6peTlyJVqm0uhgaiz
1oOcua7q8BG9zMKOGlthDXqqRp4q0BL3SEU4Ig13Eugd4iaxIP4BJe3z5y32EG6k
6Cb31GAySViGmayDdDjdEFHvlUxlINc2SMHGdUB+dAUzhDo/2qRo8ro+m71fEiJT
i75X2S7EgvkdSoFQQnvZhEzZ1oB7UaASiQvk1zBzzLJv+SxebXD2uDOHdsANpUzs
mjqKVPOXkB9JvzHtZfVx/L5WKm8Gm3IiqXes1e7/aVoHUNTN0MmZsoynR58lzkLS
jX/7zvWVCBxy6g6hUdSuvcBTs4wAbQdKQ7M13YMYQouW0zJTCGM/TFp6Y882Evz7
wZZIWj5waILHC5UgTdN9qEfb2Lhb/cwiRWCap2kKGC5J9hiOcG2SqJKYxW8msg5U
Ll2tSeNeWyoGhgI2TOyD
=zudr
-----END PGP SIGNATURE-----





Bug 546528 cloned as bug 604873. Request was from Adam D. Barratt <adam@adam-barratt.org.uk> to control@bugs.debian.org. (Wed, 24 Nov 2010 23:42:01 GMT) Full text and rfc822 format available.

Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Mon, 27 Dec 2010 07:31:51 GMT) Full text and rfc822 format available.

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Sat Apr 19 02:13:49 2014; Machine Name: buxtehude.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.