Proposal for addition of a new Process.environ property returning the environment variables registered by a process, possibly as a dictionary.
Comment #1
Posted on May 12, 2009 by Grumpy Lion(No comment was entered for this change.)
Comment #2
Posted on May 13, 2009 by Quick GiraffeOn Windows this seems to be painful to determine although still possible: http://www.codeguru.com/forum/archive/index.php/t-416841.html
Comment #3
Posted on Jul 14, 2009 by Grumpy LionUgh, this is just as ugly as determining the cmdline was, it uses basically the same method and will likely suffer from the same reliability problems we're seeing there.
Comment #4
Posted on Sep 17, 2009 by Quick GiraffeRemoving 0.1.3 milestone
Comment #5
Posted on Feb 4, 2010 by Quick Giraffe(No comment was entered for this change.)
Comment #6
Posted on Feb 26, 2010 by Helpful WombatI'm the guy who helped you with the command line retrieval on Windows. Please ignore those CreateRemoteThread idiots. Take a look at this code (function PhGetProcessEnvironmentVariables):
Comment #7
Posted on Mar 1, 2010 by Quick Giraffe(No comment was entered for this change.)
Comment #8
Posted on Jul 9, 2010 by Happy MonkeyJust for the record when we'll reconsider this, Linux code was committed as r406 and removed in r464 and r599.
Comment #9
Posted on Sep 24, 2010 by Happy Monkey(No comment was entered for this change.)
Comment #10
Posted on Mar 1, 2011 by Happy MonkeyOn FreeBSD we can use kvm_getenvv(): http://fuse4bsd.creo.hu/localcgi/man-cgi.cgi?kvm_getenvv+3
Comment #11
Posted on Jan 24, 2012 by Happy MonkeyIssue 247 has been merged into this issue.
Comment #12
Posted on Jan 31, 2012 by Happy MonkeyAnother article about Windows: http://www.codeproject.com/Articles/25647/Read-Environment-Strings-of-Remote-Process
Comment #13
Posted on Feb 1, 2012 by Happy MonkeyReopening as I have a partial working patch for Windows. I'd like to have this ready for 0.5.0.
Comment #14
Posted on Feb 1, 2012 by Happy MonkeyLinux implementation readded as r1259. Windows implementation added as r1260.
Comment #15
Posted on Feb 1, 2012 by Happy Monkeykvm_getenvv() on FreeBSD can only be used if /proc filesystem is mounted (and it's not by default). Partial implementation is below but I guess we better off not supporting FreeBSD at all.
static PyObject* get_process_environ(PyObject* self, PyObject* args) { long pid; char **env; struct kinfo_proc *pinfo; int num; static kvm_t **kd;
if (! PyArg_ParseTuple(args, "l", &pid)) {
return NULL;
}
kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
pinfo = kvm_getprocs(kd, KERN_PROC_PID, pid, &num);
if (pinfo == NULL) {
return PyErr_SetFromErrno(PyExc_OSError);
}
env = kvm_getenvv(kd, pinfo, 9086);
if (env == NULL) {
return PyErr_SetFromErrno(PyExc_OSError);
}
return Py_BuildValue("i", 33);
}
Comment #16
Posted on Apr 25, 2012 by Massive KangarooI fixed the heap corruption issue happening with the get_process_environ() call on windows in r1297
Comment #17
Posted on Apr 25, 2012 by Happy MonkeyGreat! Thanks.
Comment #18
Posted on Apr 25, 2012 by Happy MonkeyLooking back at this I start to doubt the usefulness for two reasons:
- on Linux this seems to work just fine but if the environment of the process is modified the change is not propagated:
p = psutil.Process(os.getpid()) os.putenv('XXX', '1') 'XXX' in p.get_environ() False
- on Windows this can be used for the current process only; for all other processes, including the ones owned by the current user, we get an AccessDenied exception - also, if the environment of the current process is changed we also get AccessDenied.
That said, it probably make sense to give up on this. I'm going to leave this open for a while a take a definitive decision later.
Comment #19
Posted on Jun 26, 2012 by Happy MonkeyMore info about Linux not updating /proc/PID/environ: http://serverfault.com/questions/66363/environment-variables-of-a-running-process-on-unix/79463#79463
Comment #20
Posted on Jun 26, 2012 by Happy MonkeyOk, I'm still inclined to remove this due to the unreliabilities explained above for both Windows and Linux. Removal done in r1366 and closing this out as WontFix.
Comment #21
Posted on Mar 1, 2013 by Happy MonkeyComment deleted
Comment #22
Posted on Mar 2, 2013 by Happy MonkeyUpdated csets after the SVN -> Mercurial migration: r406 == revision 3e6905e0c623 r1260 == revision a299e2431879 r1297 == revision e278f365986c r1366 == revision b1dd9bd9ba25
Status: WontFix
Labels:
Type-Enhancement
Priority-Medium
Progress-2in4