public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Setting env var CYGWIN for Cygwin service?
@ 2020-12-30 20:09 Oleksandr Gavenko
  2020-12-31 11:07 ` Franz Fehringer
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Oleksandr Gavenko @ 2020-12-30 20:09 UTC (permalink / raw)
  To: cygwin

Hi!

What way can I pass env var "CYGWIN" to the Cygwin service?

There are no that many influential options here:

  https://cygwin.com/cygwin-ug-net/using-cygwinenv.html

I can think of "winsymlinks:native" or "wincmdln".

Process Explorer shows following env vars for Cygwin's Exim process:

  PATH
  SYSTEMDRIVE
  SYSTEMROOT
  WINDIR

I configured it with "exim-config" and it is in the list of:

  cygrunsrv -L

I'm not sure if it is served by cygserver:

  https://cygwin.com/cygwin-ug-net/using-cygserver.html

-- 
http://defun.work/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Setting env var CYGWIN for Cygwin service?
  2020-12-30 20:09 Setting env var CYGWIN for Cygwin service? Oleksandr Gavenko
@ 2020-12-31 11:07 ` Franz Fehringer
  2020-12-31 15:20   ` Oleksandr Gavenko
  2020-12-31 15:04 ` Bill Stewart
  2021-01-04 22:08 ` Oleksandr Gavenko
  2 siblings, 1 reply; 8+ messages in thread
From: Franz Fehringer @ 2020-12-31 11:07 UTC (permalink / raw)
  To: cygwin

Cygwin inherits Windows environment variables, this should be the 
simplest take.

Am 30.12.2020 um 21:09 schrieb Oleksandr Gavenko via Cygwin:
> Hi!
> 
> What way can I pass env var "CYGWIN" to the Cygwin service?
> 
> There are no that many influential options here:
> 
>    https://cygwin.com/cygwin-ug-net/using-cygwinenv.html
> 
> I can think of "winsymlinks:native" or "wincmdln".
> 
> Process Explorer shows following env vars for Cygwin's Exim process:
> 
>    PATH
>    SYSTEMDRIVE
>    SYSTEMROOT
>    WINDIR
> 
> I configured it with "exim-config" and it is in the list of:
> 
>    cygrunsrv -L
> 
> I'm not sure if it is served by cygserver:
> 
>    https://cygwin.com/cygwin-ug-net/using-cygserver.html
> 



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Setting env var CYGWIN for Cygwin service?
  2020-12-30 20:09 Setting env var CYGWIN for Cygwin service? Oleksandr Gavenko
  2020-12-31 11:07 ` Franz Fehringer
@ 2020-12-31 15:04 ` Bill Stewart
  2020-12-31 15:41   ` Oleksandr Gavenko
  2020-12-31 15:46   ` Brian Inglis
  2021-01-04 22:08 ` Oleksandr Gavenko
  2 siblings, 2 replies; 8+ messages in thread
From: Bill Stewart @ 2020-12-31 15:04 UTC (permalink / raw)
  To: cygwin

On Wed, Dec 30, 2020 at 1:09 PM Oleksandr Gavenko wrote:

> What way can I pass env var "CYGWIN" to the Cygwin service?

cygrunsrv --help shows this:

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

These are added as REG_SZ values in
HKLM\SYSTEM\CurrentControlSet\Services\<servicename>\Parameters\Environment
registry subkey.

Bill

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Setting env var CYGWIN for Cygwin service?
  2020-12-31 11:07 ` Franz Fehringer
@ 2020-12-31 15:20   ` Oleksandr Gavenko
  0 siblings, 0 replies; 8+ messages in thread
From: Oleksandr Gavenko @ 2020-12-31 15:20 UTC (permalink / raw)
  To: cygwin

On 2020-12-31, Franz Fehringer via Cygwin wrote:

> Cygwin inherits Windows environment variables, this should be the simplest take.

Normally does, no doubt.

So I made `srv.c`:

  #include <unistd.h>
  int main() {
      sleep(60);
  }

compiled:

  gcc -o srv.exe srv.c

registered:

  cygrunsrv -I mysrv -t manual -p $PWD/srv.exe -c $PWD -e MY=hello -d "My Srv" -f "Testing Cyg Service"

  $ cygrunsrv -L
  exim
  mysrv

launched:

  cygrunsrv --start mysrv

Finally checked with Process Explorer:

* corresponding `cygrunsrv` had many env vars
* my `srv.exe` had only:

>    PATH
>    SYSTEMDRIVE
>    SYSTEMROOT
>    WINDIR

Same was for exim as I wrote earlier. `cygrunsrv` has everything, `exim` only
4 env vars.

  uname -r
  3.1.7(0.340/5/3)

-- 
http://defun.work/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Setting env var CYGWIN for Cygwin service?
  2020-12-31 15:04 ` Bill Stewart
@ 2020-12-31 15:41   ` Oleksandr Gavenko
  2020-12-31 15:46   ` Brian Inglis
  1 sibling, 0 replies; 8+ messages in thread
From: Oleksandr Gavenko @ 2020-12-31 15:41 UTC (permalink / raw)
  To: cygwin

On 2020-12-31, Bill Stewart wrote:

> cygrunsrv --help shows this:
>
> -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.

I made experiment few minutes ago (was curious to pass as many options as
possible):

  cygrunsrv -I mysrv -t manual -p $PWD/srv.exe -c $PWD -e MY=hello -d "My Srv" -f "Testing Cyg Service"

and didn't see "MY" in the list of env vars of actual running processes...

> These are added as REG_SZ values in
> HKLM\SYSTEM\CurrentControlSet\Services\<servicename>\Parameters\Environment
> registry subkey.

Right:

  ls /proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/mysrv/Parameters/Environment
  MY

  cat
  /proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/mysrv/Parameters/Environment/MY | strings
  hello

There is:

https://web.archive.org/web/20100306183453/http://support.microsoft.com/kb/821761
  Changes that you make to environment variables do not affect services that
  run under the Local System account until you restart Windows.

but I'm not sure that has effect:

  This behavior occurs because services that run under the Local System
  account inherit their environment from the Services.exe process. The
  Services.exe process receives the environment settings for the Local System
  account when Windows starts.

because SYSTEM/CurrentControlSet/Services is something different...

Haven't tried to reboot...

For my purpose (ensuring that env var CYGWIN is propagated into every possible
running executable) `-e` is not necessary as `cygrunsrv` inherits CYGWIN from
`SYSTEM\CurrentControlSet\Control\Session Manager\Environment`. But strangely
it is not passed to controlled process (like exim)...

-- 
http://defun.work/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Setting env var CYGWIN for Cygwin service?
  2020-12-31 15:04 ` Bill Stewart
  2020-12-31 15:41   ` Oleksandr Gavenko
@ 2020-12-31 15:46   ` Brian Inglis
  1 sibling, 0 replies; 8+ messages in thread
From: Brian Inglis @ 2020-12-31 15:46 UTC (permalink / raw)
  To: cygwin

On 2020-12-31 08:04, Bill Stewart wrote:
> On Wed, Dec 30, 2020 at 1:09 PM Oleksandr Gavenko wrote:
>> What way can I pass env var "CYGWIN" to the Cygwin service?
> cygrunsrv --help shows this:
> -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.
> These are added as REG_SZ values in
> HKLM\SYSTEM\CurrentControlSet\Services\<servicename>\Parameters\Environment
> registry subkey.

The HKLM/System env vars are where I would expect to add env vars to be used by 
all services or any particular service.
For visibility, I would make them global HKLM/System env vars, or load them from 
/etc/config files.

The HKCU/HKU env vars are only used by processes running under a user login.

-- 
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 binary units and prefixes, physical quantities in SI.]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Setting env var CYGWIN for Cygwin service?
  2020-12-30 20:09 Setting env var CYGWIN for Cygwin service? Oleksandr Gavenko
  2020-12-31 11:07 ` Franz Fehringer
  2020-12-31 15:04 ` Bill Stewart
@ 2021-01-04 22:08 ` Oleksandr Gavenko
  2021-01-04 22:39   ` Bill Stewart
  2 siblings, 1 reply; 8+ messages in thread
From: Oleksandr Gavenko @ 2021-01-04 22:08 UTC (permalink / raw)
  To: cygwin

On 2020-12-30, Oleksandr Gavenko via Cygwin wrote:

> What way can I pass env var "CYGWIN" to the Cygwin service?

Today I reinstalled Cygwin & Exim.

"exim-config" script asked me:

  Enter the value of CYGWIN for the daemon: []

/usr/bin/exim-config has line with:

  cygrunsrv -I exim -p /usr/bin/exim -e CYGWIN="${cygenv}" ...

So it is the answer (as pointed by others).

Still "procexp" doesn't show anything else besides PATH/WINDIR for "exim"
process. It can be that cygrunsrv passed env vars in some Cygwin *magical way*.

Cannot confirm this, attempt to read /proc/X/environ gives "<defunct>". There
is no problem to read "environ" for other Cygwin processes.

-- 
http://defun.work/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Setting env var CYGWIN for Cygwin service?
  2021-01-04 22:08 ` Oleksandr Gavenko
@ 2021-01-04 22:39   ` Bill Stewart
  0 siblings, 0 replies; 8+ messages in thread
From: Bill Stewart @ 2021-01-04 22:39 UTC (permalink / raw)
  To: cygwin

On Mon, Jan 4, 2021 at 3:08 PM Oleksandr Gavenko wrote:

> /usr/bin/exim-config has line with:
>
>   cygrunsrv -I exim -p /usr/bin/exim -e CYGWIN="${cygenv}" ...
>
> So it is the answer (as pointed by others).
>
> Still "procexp" doesn't show anything else besides PATH/WINDIR for "exim"
> process. It can be that cygrunsrv passed env vars in some Cygwin *magical way*.
>
> Cannot confirm this, attempt to read /proc/X/environ gives "<defunct>". There
> is no problem to read "environ" for other Cygwin processes.

I have observed the same thing. The environment variable setting
exists in the HKLM\System\CurrentControlSet\Services\<servicename>\Parameters\Environment
registry subkey, but Process Explorer does not show the environment
variable in the list of environment variables for the process.

I have not looked at the code, but it seems that environment variables
specified in this way are not propagated to the environment block for
the process but instead are read some other way.

Bill

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-01-04 22:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-30 20:09 Setting env var CYGWIN for Cygwin service? Oleksandr Gavenko
2020-12-31 11:07 ` Franz Fehringer
2020-12-31 15:20   ` Oleksandr Gavenko
2020-12-31 15:04 ` Bill Stewart
2020-12-31 15:41   ` Oleksandr Gavenko
2020-12-31 15:46   ` Brian Inglis
2021-01-04 22:08 ` Oleksandr Gavenko
2021-01-04 22:39   ` Bill Stewart

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