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

Re: 4.0.1: problem with sourcing on Solaris

On Jun 5,  2:16pm, Jos Backus wrote:
} Subject: Re: 4.0.1: problem with sourcing on Solaris
} Here's a clue: for some reason, after re-running configure (because
} I changed a couple of entries in config.modules), BROKEN_KILL_ESRCH
} got define'd. When defined, I see the problem; when I undefine
} BROKEN_KILL_ESRCH (the default), the shell works fine. I'm wondering
} how this could end up being define'd...

It could end up being defined because the configure test for it is bad.

    pid=getpid() + 10000;
    ret=kill(pid, 0);

If a process whose PID is 10000 more than the current PID happens to be
running, then the test returns the wrong result.

Also, if getpid() returns a sufficiently large number, pid + 10000 might
be larger than the largest possible PID, causing a (legitimate) EINVAL,
or might wrap to negative and be interpreted as a pgrp.

The ideal solution would be to fork(), wait(), and then kill(), but the
vagaries of doing a proper wait() portably are such that it may be too
messy to use in a configure test.  So I suggest the following; it tries
at least 15 different PIDs (and no more than 23 of them) and concludes
BROKEN_KILL_ESRCH only if none of those give ESRCH.

The & 0xffffff is just because I'm paranoid that left-shifting a negative
number might do sign extension, causing an infinite loop.  Maybe that's
not really an issue, but it's a handy way to limit the number of shifts
as well.

Index: zshconfig.ac
RCS file: /extra/cvsroot/zsh/zsh-4.0/zshconfig.ac,v
retrieving revision 1.1
diff -c -r1.1 zshconfig.ac
--- zshconfig.ac	2001/06/08 03:53:13	1.1
+++ zshconfig.ac	2001/06/08 04:43:12
@@ -1377,10 +1377,9 @@
 #include <errno.h>
-    int pid, ret;
-    pid=getpid() + 10000;
-    ret=kill(pid, 0);
-    exit(ret<0 && errno!=ESRCH);
+    int pid = (getpid() + 10000) & 0xffffff;
+    while (pid && (kill(pid, 0) == 0 || errno != ESRCH)) pid >>= 1;
+    exit(errno!=ESRCH);

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   

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