From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28977 invoked by alias); 29 Nov 2016 16:01:58 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 28424 invoked by uid 89); 29 Nov 2016 16:01:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=moss@cs.umass.edu, sk:mosscs, D*cs.umass.edu, sk:moss@cs X-HELO: mail-wm0-f49.google.com Received: from mail-wm0-f49.google.com (HELO mail-wm0-f49.google.com) (74.125.82.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Nov 2016 16:01:47 +0000 Received: by mail-wm0-f49.google.com with SMTP id f82so192814265wmf.1 for ; Tue, 29 Nov 2016 08:01:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=SKhBuOQkonWahEXXYS/GzJrXywXG/sfWi6M9h1taxWw=; b=IwJDlYIFqRL+725LsrQ/8epe+RHMSXdYuf0+fFzKrFh/kAXXxroIJP+C7scUwAGMuS KIfEeWX9aT+n4riHeQ+p++iN30WxmoDZZ0buMwi1TVaDu7mUeBY+gZ16UtzGL1YF77RQ /2Tq9a59sU+f/Od2vUgSiisaF/IBKXedBxHeP++0CSnYrOdl0t3/1LWptJeMFFK3/n7u M6uU/Zks7z/+TYH3w/eROsWDovE/0Esz87jUt1vEW8vuLDTqK1FhWEkuzsT9aJlg91ZL kDengMTWFI2zQMsUBRc/XvqPdF2YP3U1wSfR6y1n825lx05r+i0S9UfGHLUqrK9iVGld IhIQ== X-Gm-Message-State: AKaTC02AIUYoDwF2WBsNEgTNNqTTysUY57qi1bCDUOMA4ELYQ++hwZvx1989lE0rcko8IhqX8s7iIGo0oqY3gg== X-Received: by 10.28.9.80 with SMTP id 77mr25227902wmj.68.1480435305587; Tue, 29 Nov 2016 08:01:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.151.46 with HTTP; Tue, 29 Nov 2016 08:01:44 -0800 (PST) In-Reply-To: <98eb08bf-5012-fe14-b10c-241b427c4366@cs.umass.edu> References: <20161117140012.GA23664@calimero.vinschen.de> <98eb08bf-5012-fe14-b10c-241b427c4366@cs.umass.edu> From: Erik Bray Date: Tue, 29 Nov 2016 17:42:00 -0000 Message-ID: Subject: Re: Retrieving per-process environment block? To: moss@cs.umass.edu, cygwin@cygwin.com Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-11/txt/msg00327.txt.bz2 On Tue, Nov 29, 2016 at 3:28 PM, Eliot Moss wrote: > On 11/29/2016 8:26 AM, Erik Bray wrote: >> >> On Thu, Nov 17, 2016 at 3:00 PM, Corinna Vinschen >> wrote: >>> >>> On Nov 17 14:30, Erik Bray wrote: >>>> >>>> Hi all, >>>> >>>> For a quick bit of background, I'm working on porting the highly >>>> useful psutil [1] Python library to Cygwin. This has proved an >>>> interesting exercise, as much of the functionality of psutil works on >>>> Cygwin through existing POSIX interfaces, and a handful of >>>> Linux-specific interfaces as well. But there are some bits that >>>> simply don't map at all. >>>> >>>> The one I'm struggling with right now is retrieving Cygwin environment >>>> variables for a process (under inspection--i.e. not listing a >>>> process's environment from within that process which is obviously >>>> trivial). >>>> >>>> I've looked at every route I could conceive of but as far as I can >>>> tell this is currently impossible. That's fine for now--I simply >>>> disable that functionality in psutil. But it is unfortunate, though, >>>> since the information is there. >>>> >>>> There are a couple avenues I could see to this. The most "obvious" >>>> (to me) being to implement /proc//environ. >>>> >>>> I would be willing to provide a patch for this if it would be >>>> accepted. Is there some particular non-obvious hurdle to this that it >>>> hasn't been implemented? Obviously there are security >>>> implications--the /proc//environ should only be readable to the >>>> process's owner, but that is already within Cygwin's capabilities, and >>>> works for other /proc files. >>> >>> >>> Patch welcome. Implementing this should be fairly straightforward. >>> The only hurdle is winsup/CONTRIBUTORS ;) >> >> >> Thanks--I went to go work on this finally but it turns out not to be >> straightforward after all, as the process's environment is not shared >> in any way between processes. >> >> I could do this, if each process kept a copy of its environment block >> in shared memory, which would in turn have to be updated every time >> the process's environment is updated. But I don't know what the >> impact of that would be performance-wise. > > > Sorry, no advice getting around this, but a thought about why it may have > been hard -- it can be a security hole. Given Windows' complex access > rights, > how would one determine which processes should reasonably have access to > another process's environment variables? Maybe Windows decided to punt the > issue. (I don't know anything about this at all - as I said, just a > thought.) > > A question: Are there any Windows tools that can do this? If so, you might > be able to trace them to find what they do. Hi, Thanks for the reply. The issue here isn't getting the Windows process environment--that can be done, albeit trickily [1]. While it's true there are security implications, in this case that is handled at the OpenProcess call required to obtain a handle to the process. It's true you can't just read the environment from a process you don't have permission to. The issue here though is reading the Cygwin process's environment which is separate from its Windows environment, and the above technique is inapplicable. The easiest way, as I suggested, would be to keep a copy of each process's Cygwin environment in shared memory as is the case with the pinfo struct. I just don't know if it's worth the effort for this relatively narrow case (it's no so much effort to implement, I just worry what performance impacts that could have, though I suppose I could just try it and see...) [1] https://theroadtodelphi.com/2012/06/09/getting-the-environment-variables-of-an-external-x86-and-x64-process/ -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple