public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
To: cygwin@cygwin.com
Subject: Re: TMP/TEMP environment variable and /tmp
Date: Thu, 17 Sep 2020 21:56:09 -0600	[thread overview]
Message-ID: <7cdf4b72-bc51-0c9f-de36-8494eeba4083@SystematicSw.ab.ca> (raw)
In-Reply-To: <687db96b-9f7e-8c50-4673-14435a20864b@cornell.edu>

On 2020-09-17 20:17, Ken Brown via Cygwin wrote:
> On 9/17/2020 7:58 PM, Doug Henderson via Cygwin wrote:
>> On Thu, 17 Sep 2020 at 15:56, Ken Brown via Cygwin <> wrote:
>>>
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> int
>> main ()
>> {
>>      char *temp_nam;
>>      char *p_tmp_nam;
>>
>>      printf ("$TMP      is '%s'\n", getenv ("TMP"));
>>      printf ("$TMPDIR   is '%s'\n", getenv ("TMPDIR"));
>>      printf ("$TEMP     is '%s'\n", getenv ("TEMP"));
>>      printf ("P_tmpdir  is '%s'\n", P_tmpdir);
>>      p_tmp_nam = tmpnam(0);
>>      printf ("tmpnam()  is '%s'\n", p_tmp_nam);
>>      temp_nam = tempnam(0, 0);
>>      printf ("tempnam() is '%s'\n", temp_nam);
>>      free(temp_nam);
>> }
>>
>>
>> # start a new shell
>> $ sh
>> $ TMP= TEMP= ./show_tmp
>> $TMP      is ''
>> $TMPDIR   is '(null)'
>> $TEMP     is ''
>> P_tmpdir  is '/tmp'
>> tmpnam()  is '/tmp/t707.0'
>> tempnam() is '/tmp/ffffd187.2'
>>
>> # start cmd.exe
>> $ /cygdrive/c/windows/system32/cmd.exe
>> Microsoft Windows [Version 10.0.18363.1082]
>> (c) 2019 Microsoft Corporation. All rights reserved.
>>> set TMP=
>>> set TEMP=
>>> show_tmp
>> $TMP      is '(null)'
>> $TMPDIR   is '(null)'
>> $TEMP     is '(null)'
>> P_tmpdir  is '/tmp'
>> tmpnam()  is '/tmp/t709.0'
>> tempnam() is '/tmp/ffffd189.2'
>>
>> P_tmpdir is defined in <stdio.h>
> 
> Sorry, but I'm missing your point.  How is this related to Kristian's claim that
> Cygwin is changing the value of the TMP environment variable to "/tmp"?

It demonstrates that Cygwin programs don't themselves change TEMP/TMP, unless
they call an API routine that generates a filename in a directory, when the
filesystem handling may translate a nonexistent or unmounted /tmp/ to ../tmp/.

That jives with the defaults I see in the registry and in the cmd environments:

$ regtool list -v
/proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session\
Manager/Environment | grep 'T.*MP'
TEMP (REG_EXPAND_SZ) = "%SystemRoot%\TEMP"
TMP (REG_EXPAND_SZ) = "%SystemRoot%\TEMP"

$ regtool list -v /proc/registry/HKEY_CURRENT_USER/Environment | grep 'T.*MP'
TEMP (REG_EXPAND_SZ) = "%UserProfile%\AppData\Local\TEMP"
TMP (REG_EXPAND_SZ) = "%UserProfile%\AppData\Local\TEMP"

C:\Windows\system32>set | grep "T.*MP"
TEMP=C:\Windows\TEMP
TMP=C:\Windows\TEMP
C:\Windows\system32>which env
/usr/bin/env
C:\Windows\system32>env | grep "T.*MP"
TEMP=/cygdrive/c/Windows/TEMP
TMP=/cygdrive/c/Windows/TEMP

C:\Users\...>set | grep "T.*MP"
TEMP=C:\Users\...\AppData\Local\Temp
TMP=C:\Users\...\AppData\Local\Temp
C:\Users\...>env | grep "T.*MP"
TEMP=/cygdrive/c/Users/.../AppData/Local/Temp
TMP=/cygdrive/c/Users/.../AppData/Local/Temp

and I know you can just delete those environment variables and registry keys at
the risk of upsetting any Windows programs that need temp space and do not
provide an accessible fallback.

The same goes for any Cygwin script or program: each application needs to check
it has access to any output locations: the directory is writable and the file
can be created e.g. in /var/log/ or /tmp/, or try to create a directory, or try
elsewhere /usr/tmp/, /var/tmp/, or create that, or try the current directory ./
or home directory $HOME/, known paths $USERPROFILE/ or $LOCALAPPDATA/Temp/, or
exit with a failure condition.

I think we need to see the environment or registry and application code around
creating the file to diagnose the cause, but I expect the environment may not
define TMPDIR/TMP/TEMP, the application provides no accessible fallback(s), and
Cygwin defaults the path.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in IEC units and prefixes, physical quantities in SI.]

  reply	other threads:[~2020-09-18  3:56 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16  8:51 sten.kristian.ivarsson
2020-09-16 11:04 ` marco atzeri
2020-09-16 11:12   ` Thomas Wolff
2020-09-16 19:27     ` Hans-Bernhard Bröker
2020-09-17 12:12       ` Sv: " sten.kristian.ivarsson
2020-09-17 15:23         ` Thomas Wolff
2020-09-17 21:07           ` Kristian Ivarsson
2020-09-17 21:55             ` Ken Brown
2020-09-17 23:58               ` Doug Henderson
2020-09-18  2:17                 ` Ken Brown
2020-09-18  3:56                   ` Brian Inglis [this message]
2020-09-18  5:56               ` Kristian Ivarsson
2020-09-18 13:15                 ` Brian Inglis
2020-09-21  7:57                   ` Sv: " sten.kristian.ivarsson
2020-09-20  7:20         ` Andrey Repin
2020-09-17 16:13     ` Ken Brown

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=7cdf4b72-bc51-0c9f-de36-8494eeba4083@SystematicSw.ab.ca \
    --to=brian.inglis@systematicsw.ab.ca \
    --cc=cygwin@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).