Re: bash: Fails to upgrade in kFreeBSD jails
Jonathan Nieder wrote:
> Stefan Ott wrote:
>> bash.preinst: cannot set close-on-exec flag: Inappropriate ioctl for device
[...]
> Thought you might be interested in this report, since it feels like a
> libc or kernel bug. Hints?
Of course I should give more context than that. :)
That message comes from set_cloexec(), which is defined as follows:
void set_cloexec(int fd)
{
int flags = fcntl(fd, F_GETFL);
if (flags < 0 || fcntl(fd, F_SETFL, flags | FD_CLOEXEC))
die_errno("cannot set close-on-exec flag");
}
It is called on /dev/null and the two file descriptors returned from
pipe() to avoid leaking file descriptors.
Presumably this should be a warning instead of a fatal error or the
set_cloexec() calls could be dropped altogether. But why is fcntl()
failing?
Thanks,
Jonathan
diff --git i/debian/bash.preinst-lib.c w/debian/bash.preinst-lib.c
index bb13a166..701a5874 100644
--- i/debian/bash.preinst-lib.c
+++ w/debian/bash.preinst-lib.c
@@ -58,19 +58,10 @@ int exists(const char *file)
die_errno("cannot get status of %s", file);
}
-void set_cloexec(int fd)
-{
- int flags = fcntl(fd, F_GETFL);
- if (flags < 0 || fcntl(fd, F_SETFL, flags | FD_CLOEXEC))
- die_errno("cannot set close-on-exec flag");
-}
-
void xpipe(int pipefd[2])
{
if (pipe(pipefd))
die_errno("cannot create pipe");
- set_cloexec(pipefd[0]);
- set_cloexec(pipefd[1]);
}
void wait_or_die(pid_t child, const char *name, int flags)
diff --git i/debian/bash.preinst.c w/debian/bash.preinst.c
index 14baeab0..2badd2ae 100644
--- i/debian/bash.preinst.c
+++ w/debian/bash.preinst.c
@@ -85,8 +85,6 @@ static int binsh_in_filelist(const char *package)
* fails, no problem; leave stderr alone in that case.
*/
sink = open("/dev/null", O_WRONLY);
- if (sink >= 0)
- set_cloexec(sink);
in = spawn_pipe(&child, cmd, sink);
/* ... | grep "^/bin/sh\$" */
diff --git i/debian/bash.preinst.h w/debian/bash.preinst.h
index 82faf497..4d4a5abb 100644
--- i/debian/bash.preinst.h
+++ w/debian/bash.preinst.h
@@ -26,7 +26,6 @@ extern NORETURN PRINTFLIKE void die_errno(const char *fmt, ...);
extern NORETURN PRINTFLIKE void die(const char *fmt, ...);
extern int exists(const char *path);
-extern void set_cloexec(int fd);
extern void xpipe(int pipefd[2]);
extern void wait_or_die(pid_t child, const char *desc, int flags);
diff --git i/debian/changelog w/debian/changelog
index 310ec061..40dcb4c5 100644
--- i/debian/changelog
+++ w/debian/changelog
@@ -1,3 +1,11 @@
+bash (4.2-2.1) local; urgency=low
+
+ * bash.preinst: Let a few file descriptors leak instead of setting
+ the close-on-exec flag. This avoids some portability gotchas.
+ Closes: #679198.
+
+ -- Jonathan Nieder <jrnieder@gmail.com> Tue, 26 Jun 2012 20:55:36 -0500
+
bash (4.2-2) unstable; urgency=low
* Fix command-not-found location. Closes: #529313.
Reply to: