Re: UPDATE 2: Windows XP, Cygwin 1.3.22-1, PostgreSQL 7.3.2,

From: Frank Seesink <frank(at)mail(dot)wvnet(dot)edu>
To: pgsql-cygwin(at)postgresql(dot)org
Subject: Re: UPDATE 2: Windows XP, Cygwin 1.3.22-1, PostgreSQL 7.3.2,
Date: 2003-05-12 17:22:03
Message-ID: b9ol64$b57$1@main.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-cygwin

Jason Tishler wrote:
[snip]
>>I notice that if I look at the environment table from a DOS shell,
>>C:\cygwin\bin is listed after the Windows system paths (the way I set
>>it). However, if I run the BASH shell, I see that Cygwin
>>automatically puts its own paths first, before tacking on the NT
>>environment table version of PATH; e.g.,
>>
>>From within BASH:
>>PATH='/usr/local/bin:/usr/bin:/bin:/cygdrive/c/WINDOWS/system32:...
>
>
> IIRC, Cygwin's /etc/profile does the above. Note that I use my own
> /etc/profile that predates the Cygwin one so I'm not 100% sure. But,
> what else would set PATH as such?
>
>
>>The big question, I guess is, when 'postmaster' runs as an NT service,
>>does it run within the Cygwin 'shell' (giving it access to the 'sort'
>>and 'find' it expects),
>
>
> No.
>
>
>>or does it run in the NT context, where it suddenly accesses the NT
>>utilities 'sort' and 'find'?
>
>
> Kinda. It runs in the postgres context (or whatever user is assigned to
> the postmaster service) which will use the PATH defined for that user.
>
> However, you made me think of another option which may suit some users
> better. Add the Cygwin bin directories to the end of the Windows system
> PATH. But, use cygrunsrv's --env option when installing postmaster and
> set postmaster's PATH so that the Cygwin bin directories are searched
> first. In this way, one does not need to affect the Windows system PATH
> or any user's PATH (including postgres) just to keep postmaster happy.

Just did 'cygrunsrv --help', and listed in there is the following:
______________________________________________________________________
...
-e, --env <VAR=VALUE> Optional environment strings which are added
to the environment when service is started.
You can add up to 255 environment strings
using the `--env' option.
Note: /bin is always added to $PATH to allow
all started applications to find at least
cygwin1.dll.
...
______________________________________________________________________

This seems to imply that this is automagically done by cygrunsrv. But
how do you make sure the Cygwin bin directories are searched FIRST? The
above section of help just says ".../bin is always added to $PATH...",
but doesn't state if at the end (which I would assume is the case) or
the beginning. And how could one tell?

Never mind. Just looked in /usr/doc/Cygwin/cygrunsrv.README, and it
contains the following info (emphasis mine):
______________________________________________________________________
...In the 'daemonize' mode, cygrunsrv sets up
the environment (according to flags set via the 'commandline'
mode). It adds '/bin' TO _THE FRONT_ of the PATH so that the
target service can find cygwin1.dll easily.
______________________________________________________________________

Further down is more info on how -env works:
______________________________________________________________________
...
-e, --env <VAR=value>
Optional environment strings which are added to the environment
when the service is started. You can add up to 255 environment strings
using multiple `--env' options. Note that '/bin:' is always appended
to the path to allow started applications to find cygwin1.dll. You
may also specify PATH=/a/path:/list if you like, but /bin WILL be
appended.

cygrunsrv -I foo -p /usr/bin/bar -e HOME=/e/services -e TMP=/var/tmp

A single level of quoting with either single (') or double (") quotes
is allowed:

cygrunsrv -I foo -p /usr/bin/bar -e BAR="\"/d/My Documents/services\""

results in an environment where BAR has the value
"/d/My Documents/services" *including the quotes* (the \-escaping and
the outer quotes are required to protect the command itself from bash).
If you don't understand this discussion about quoting, don't worry --
you probably don't need it.
______________________________________________________________________

So in short, your earlier post that C:\cygwin\bin needs to be placed in
front of the Windows system path may not be necessary after all...at
least for postmaster. And since a user running the 'psql' client under
Cygwin basically is doing so from a shell, IF (and I suspect this is NOT
the case) performing a sorted SELECT, for example, is handled by the
'psql' client, then all's well. But I'm guessing that postmaster does
the sorting (in the context of postmaster...hence Cygwin sort.exe takes
precedence over Win32 sort.exe). So problem solved. :-)

Your recommendation is more for those who always want Unix/Cygwin
functionality of functions like sort.exe, find.exe, and the others I
listed over the Win32 equivalents. Fair assessment?

In response to

Responses

Browse pgsql-cygwin by date

  From Date Subject
Next Message Jason Tishler 2003-05-12 18:35:46 Re: UPDATE 2: Windows XP, Cygwin 1.3.22-1, PostgreSQL 7.3.2,
Previous Message Jason Tishler 2003-05-12 16:43:20 Re: vacuumdb and pg_dump are not running under cron