zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Jos Backus <josb@cncdsl.com>, zsh-workers@sunsite.dk
Subject: Re: 4.0.1: problem with sourcing on Solaris
Date: Fri, 8 Jun 2001 04:50:49 +0000	[thread overview]
Message-ID: <1010608045050.ZM1210@candle.brasslantern.com> (raw)
In-Reply-To: <20010605141619.A36532@lizzy.bugworks.com>

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>
 main()
 {
-    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);
 }
 ],
   zsh_cv_sys_killesrch=yes,

-- 
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   


  reply	other threads:[~2001-06-08  4:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-04 21:37 Jos Backus
2001-06-05 10:12 ` Peter Stephenson
     [not found] ` <1010605061126.ZM4201@candle.brasslantern.com>
2001-06-05 21:16   ` Jos Backus
2001-06-08  4:50     ` Bart Schaefer [this message]
2001-06-08  6:15       ` Jos Backus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1010608045050.ZM1210@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=josb@cncdsl.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).