Re: Setting env var CYGWIN for Cygwin service?

2021-01-04 Thread Bill Stewart
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 "". 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\\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
--
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


Re: Setting env var CYGWIN for Cygwin service?

2021-01-04 Thread Oleksandr Gavenko via 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 "". There
is no problem to read "environ" for other Cygwin processes.

-- 
http://defun.work/

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


Re: Setting env var CYGWIN for Cygwin service?

2020-12-31 Thread Brian Inglis

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


Re: Setting env var CYGWIN for Cygwin service?

2020-12-31 Thread Oleksandr Gavenko via Cygwin
On 2020-12-31, Bill Stewart wrote:

> cygrunsrv --help shows this:
>
> -e, --env 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\\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/

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


Re: Setting env var CYGWIN for Cygwin service?

2020-12-31 Thread Oleksandr Gavenko via 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 
  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/

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


Re: Setting env var CYGWIN for Cygwin service?

2020-12-31 Thread Bill Stewart
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 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\\Parameters\Environment
registry subkey.

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


Re: Setting env var CYGWIN for Cygwin service?

2020-12-31 Thread Franz Fehringer via 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




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


Setting env var CYGWIN for Cygwin service?

2020-12-30 Thread 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

-- 
http://defun.work/

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