Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] allows configure to run in the background

Philippe Troin <phil@xxxxxxxx> writes:

> The checking "if tcsetpgrp() actually works" configure test stops the
> configure script if it is ran in the background. The enclose patch
> prevents this from happening by ignoring SIGTTOU for the duration of
> this test.

This is a second spin on the same idea, following up on comments from
Jens Petersen <petersen@xxxxxxxxxx> in <m3d6bgq2tk.wl%petersen@xxxxxxxxxx>.

Extra stuff taken care of:

 - works if stdin is redirected (opens /dev/tty instead of relying on stdin)

 - detects if ran without controlling tty, and aborts

Stuff taken care of with the first patch, included with this patch:

 - does not stop if ran on the background.

I think this patch will address all of Jens's concerns. There are
still some quirks, but I believe they will only show up very

 - configure completely fails if ran without a controlling tty. Should
   not be a major problem, processes running the background still have
   a controlling tty. Running without a ctty only happens when running
   from cron or some other batch facilities. Anybody doing that?

 - there still is a tiny race window if the shell decides to switch
   the foreground process between the tcgetpgrp() and tcsetpgrp()

It is probably better to go this route rather than running this
particular configure test on its own pty: this would add a lot of very
platform specific cruft to the test itself, and configure is supposed
to be robust.

Index: zshconfig.ac
RCS file: /cvsroot/zsh/zsh/zshconfig.ac,v
retrieving revision 1.42
diff -b -u -r1.42 zshconfig.ac
--- zshconfig.ac	13 Nov 2003 14:34:34 -0000	1.42
+++ zshconfig.ac	25 Nov 2003 20:16:35 -0000
@@ -1576,24 +1576,38 @@
 dnl if found tcsetpgrp, test to see if it actually works
 dnl for instance, BeOS R4.51 does not support it yet
 dnl -----------
-if test -t 0 && test $ac_cv_func_tcsetpgrp = yes; then
+if test $ac_cv_func_tcsetpgrp = yes; then
+    trap "" SIGTTOU > /dev/null 2>&1 || :
     AC_CACHE_CHECK(if tcsetpgrp() actually works,
 #include <sys/types.h>
 #include <unistd.h>
+#include <fcntl.h>
 main() {
+    int fd;
     int ret;
-    ret=tcsetpgrp(0, tcgetpgrp(0));
-    exit(ret<0);
+    fd=open("/dev/tty", O_RDWR);
+    if (fd < 0) exit(2);
+    ret=tcsetpgrp(fd, tcgetpgrp(fd));
+    if (ret < 0) exit(1);
+    exit(0);
-      zsh_cv_sys_tcsetpgrp=yes,
-      zsh_cv_sys_tcsetpgrp=no,
-      zsh_cv_sys_tcsetpgrp=yes)])
-    if test $zsh_cv_sys_tcsetpgrp = no; then
-    fi
+      zsh_cv_sys_tcsetpgrp=yes, [
+case $? in
+    1) zsh_cv_sys_tcsetpgrp=no;;
+    2) zsh_cv_sys_tcsetpgrp=notty;;
+    *) zsh_cv_sys_tcsetpgrp=error;;
+      ], zsh_cv_sys_tcsetpgrp=yes)])
+    case "x$zsh_cv_sys_tcsetpgrp" in
+      xyes)   :;;
+      xnotty) AC_ERROR([no controlling tty]);;
+      *)      AC_ERROR([unexpected return status]);;
+    esac
+    trap - SIGTTOU > /dev/null 2>&1 || :
 dnl -----------

Messages sorted by: Reverse Date, Date, Thread, Author