From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-developers@cygwin.com
Subject: Re: Root directory being a junction fools realpath()
Date: Mon, 15 Feb 2021 13:25:38 +0100 [thread overview]
Message-ID: <20210215122538.GN4251@calimero.vinschen.de> (raw)
In-Reply-To: <CAH2Hv8++XJ67t3Zyf=G3TOkhejC3nxbOZfRxB9M=g_WQW0Scmg@mail.gmail.com>
On Feb 14 12:56, David Macek via Cygwin-developers wrote:
> Greetings.
>
> I think I found a way to fool Cygwin into misplacing its root
> directory. Given recent Cygwin with GCC and a simple test program:
>
> ```
> #include <stdio.h>
> #include <limits.h>
> #include <stdlib.h>
> int main() {
> char real[PATH_MAX];
> realpath("/", real);
> printf("/ -> %s\n", real);
> return 0;
> }
> ```
>
> ... compiled with:
>
> $ gcc -D_DEFAULT_SOURCE -o new.exe -Wall -Wextra -std=c11 new.c
>
> ... and my set-up with a junction (`mklink /j link target`) realpath()
> result is dependent on which path I use to invoke the Cygwin root
> process:
>
> > dir C:\ | findstr cygwin64
> 10. 02. 2021 12:13 <DIR> cygwin64
>
> > dir D:\ | findstr cygwin64
> 14. 02. 2021 12:19 <JUNCTION> cygwin64 [C:\cygwin64]
>
> > C:\cygwin64\bin\bash -lc /cygdrive/w/new
> / -> /
>
> > D:\cygwin64\bin\bash -lc /cygdrive/w/new
> / -> /cygdrive/c/cygwin64
This isn't realpath's fault. You're circumventing the mount point
handling which is automated in terms of /, depending on the path
returned from GetModuleFileNameW for the Cygwin DLL. Since you're
calling D:\cygwin64\bin\bash the dir returned from GetModuleFileNameW is
D:\cygwin64\bin, thus root is D:\cygwin64.
However, junctions are treated as symlinks in Cygwin. Thus the result
you see above.
Corinna
next prev parent reply other threads:[~2021-02-15 12:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-14 11:56 David Macek
2021-02-15 12:25 ` Corinna Vinschen [this message]
2021-02-15 13:20 ` Corinna Vinschen
2021-02-18 11:46 ` David Macek
2021-02-18 13:09 ` Corinna Vinschen
2021-02-19 18:24 ` Corinna Vinschen
2021-03-07 13:15 ` David Macek
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=20210215122538.GN4251@calimero.vinschen.de \
--to=corinna-cygwin@cygwin.com \
--cc=cygwin-developers@cygwin.com \
/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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).