X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76622385EC45
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1609429307;
	bh=XAdq7VyuuXzEOsH2euUghETYcvLzoLzW0Zfhpb5HuNg=;
	h=To:Subject:Date:References:List-Id:List-Unsubscribe:List-Archive:
	 List-Post:List-Help:List-Subscribe:From:Reply-To:From;
	b=d1k4cdQuKJ+aUidBNRKYjI2hR+14nzRWKy2p3IJapnri/+Q0igA08xGN7Yx8jJwBb
	 tmikcduKNMyMwPTEJDasr9O4te3BorZ5LNBsF0enRw0/2XQRfZ0bRSniY/pKbUnpSy
	 YdD/Nbxg6loUcfHquCy/R3EWCf7hUoUIMxycL0Zk=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2D541385800A
X-Injected-Via-Gmane: http://gmane.org/
To: cygwin@cygwin.com
Subject: Re: Setting env var CYGWIN for Cygwin service?
Date: Thu, 31 Dec 2020 17:41:42 +0200
Organization: Oleksandr Gavenko <gavenkoa@gmail.com>, http://defun.work/
Message-ID: <vriuk0synft5.fsf@gavenkoa.example.com>
References: <vriuwnwznjj7.fsf@gavenkoa.example.com>
 <CANV9t=S_nuHHOszBa3Q0-VEcGmxVO0VBL0rystJ3fL4ivDP6=A@mail.gmail.com>
Mime-Version: 1.0
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (cygwin)
Cancel-Lock: sha1:aPPmWNi/gP/hvqg7EwMhPri+T5M=
X-Spam-Status: No, score=2.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,
 FORGED_GMAIL_RCVD, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,
 HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_OTHER_BAD_TLD,
 NML_ADSP_CUSTOM_MED, PDS_OTHER_BAD_TLD, SPF_HELO_NONE, SPF_PASS,
 TXREP autolearn=no autolearn_force=no version=3.4.2
X-Spam-Level: **
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Oleksandr Gavenko via Cygwin <cygwin@cygwin.com>
Reply-To: Oleksandr Gavenko <gavenkoa@gmail.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: "Cygwin" <cygwin-bounces@cygwin.com>

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/

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