X-Recipient: archive-cygwin AT delorie DOT com X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 41912386F0EB Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=nifty.ne.jp Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nifty.ne.jp DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-02.nifty.com 25RCF3i8025001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.ne.jp; s=dec2015msa; t=1656332104; bh=tLrvcOh81iunH2SNzn/ZF39iMsM26f4fV88ACMpFjeA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fyP+r7Z4uK3rnsAgl5vCZe9sT2mbXSlFdW6ErCkG0Bhufh2O1ekNRQvX9eEKqhEVb nkb+fLdGcCxztZqHdwaO9a4VkJg9SMYnMPw7n4ikmunX+NdXBRKMemYj5bVExGh2S5 IpNmJrVpdGlhYe27sT0tJjC/zRFMuX79RETkv6aVTE0DGQ86lrWhB2W8NZDxI27Xsd tmzk/sNvpFYrsrG2mampAAvv2/J8rDGOM7KOxt4zcpvxXoKDRhK0qRUV+hxQPp3q+2 pv8KQi+Sd3TWZbVpFjphj9fbM7L64qO7svfmXOsN+LfMAOohal7OqsUYUKFw5rrqKN aQE+MMZRowPNA== X-Nifty-SrcIP: [119.150.44.95] Date: Mon, 27 Jun 2022 21:15:03 +0900 From: Takashi Yano To: cygwin AT cygwin DOT com Subject: Re: Cygwin's execlp() does not work with an empty $PATH element Message-Id: <20220627211503.32b6bcca377fc571393749ce@nifty.ne.jp> In-Reply-To: <20220627201636.46f55975dc6485a7d3f5ee27@nifty.ne.jp> References: <20220627201636 DOT 46f55975dc6485a7d3f5ee27 AT nifty DOT ne DOT jp> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" On Mon, 27 Jun 2022 20:16:36 +0900 Takashi Yano wrote: > How about the following patch? This is better a bit. diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index e0f1247e1..292cd5a42 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -95,6 +95,7 @@ find_exec (const char *name, path_conv& buf, const char *search, char *tmp = tp.c_get (); bool has_slash = !!strpbrk (name, "/\\"); int err = 0; + bool eopath = false; debug_printf ("find_exec (%s)", name); @@ -118,8 +119,10 @@ find_exec (const char *name, path_conv& buf, const char *search, the name of an environment variable. */ if (strchr (search, '/')) *stpncpy (tmp, search, NT_MAX_PATH - 1) = '\0'; - else if (has_slash || isdrive (name) || !(path = getenv (search)) || !*path) + else if (has_slash || isdrive (name)) goto errout; + else if (!(path = getenv (search)) || !*path) + strcpy (tmp, "."); /* Search the current directory when PATH is absent */ else *stpncpy (tmp, path, NT_MAX_PATH - 1) = '\0'; @@ -130,11 +133,17 @@ find_exec (const char *name, path_conv& buf, const char *search, do { char *eotmp = strccpy (tmp_path, &path, ':'); + if (*path) + path++; + else + eopath = true; /* An empty path or '.' means the current directory, but we've already tried that. */ if ((opt & FE_CWD) && (tmp_path[0] == '\0' || (tmp_path[0] == '.' && tmp_path[1] == '\0'))) continue; + else if (tmp_path[0] == '\0') /* An empty path means the current dir. */ + eotmp = stpcpy (tmp_path, "."); *eotmp++ = '/'; stpcpy (eotmp, name); @@ -155,7 +164,7 @@ find_exec (const char *name, path_conv& buf, const char *search, } } - while (*path && *++path); + while (!eopath); errout: /* Couldn't find anything in the given path. -- Takashi Yano -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple