Skip to content

Commit 4328467

Browse files
committed
Make using PATH an error and explain in README
1 parent 48cc518 commit 4328467

File tree

2 files changed

+63
-16
lines changed

2 files changed

+63
-16
lines changed

EnvPane/EnvPane.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,13 @@ - (void) applyChanges
9191
}];
9292
[self.editableEnvironment enumerateObjectsUsingBlock:
9393
^( NSMutableDictionary *entry, NSUInteger idx, BOOL *stop ) {
94-
InterpolationException *error = [errors valueForKey: entry[ @"name" ]];
95-
entry[ @"error" ] = error ? error.reason : nil;
94+
if( [@"PATH" isEqualToString: entry[ @"name" ]] ) {
95+
entry[ @"error" ] = @"The PATH environment variable is not supported. "
96+
"See About EnvPane below for an explanation.";
97+
} else {
98+
InterpolationException *error = [errors valueForKey: entry[ @"name" ]];
99+
entry[ @"error" ] = error ? error.reason : nil;
100+
}
96101
}];
97102
if( errors.count == 0 && ![environment isEqualToEnvironment: _savedEnvironment] ) {
98103
NSError *error = nil;

README.md

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# EnvPane - An OS X preference pane for environment variables
1+
# EnvPane - An macOS preference pane for environment variables
22

33
<img src="http://diaryproducts.net/files/EnvPane.png" style="float:left"/>
44
EnvPane is a preference pane for Mac OS X (10.8 or newer) that lets you set
@@ -9,15 +9,20 @@ immediately, without the need to log out and back in. This works for changes
99
made by manually editing `~/.MacOSX/environment.plist` as well via the
1010
preference pane UI.
1111

12-
EnvPane still works on OS X 10.11 "El Capitan". I haven't tried it on 10.12
13-
"Sierra" yet. Apple [reimplemented][new_launchd] launchd in 10.10 and in the
14-
course of doing so deprecated the APIs used by EnvPane and even broke some of
15-
them (see [issue #11][issue_11]). EnvPane v0.6 adds support for the new but
16-
undocumented APIs, addressing the deprecation and [issue #11][issue_11].
12+
EnvPane was tested on OS X 10.09 "Mavericks", OS X 10.11 "El Capitan" and macOS
13+
Sierra (10.12). It should also work on 10.10 "Yosemite". Apple
14+
[reimplemented][new_launchd] launchd in 10.10 and in the course of doing so
15+
deprecated the APIs used by EnvPane and even [broke][issue_11] some of them.
16+
EnvPane v0.6 adds support for the new but undocumented APIs, addressing the
17+
deprecation and broken APIs.
1718

1819
[new_launchd]: http://newosxbook.com/articles/jlaunchctl.html
1920
[issue_11]: https://github.com/hschmidt/EnvPane/issues/11
2021

22+
EnvPane does not work for setting the PATH environment variable. See the [FAQ
23+
on that topic](#why-cant-I-set-path-with-envpane).
24+
25+
2126
## Download
2227

2328
For convenience, the pre-built and code-signed binary of EnvPane can be
@@ -110,7 +115,8 @@ removing the preference pane doesn't leave orphaned files on the system. The
110115

111116
### v0.5 and v0.4
112117

113-
Ignore. They are releases made from a fork of this repository, not by the original author and inauspiciously using the EnvPane name.
118+
Ignore. They are releases made from a fork of this repository, not by the
119+
original author and inauspiciously using the EnvPane name.
114120

115121
### v0.3
116122

@@ -138,7 +144,8 @@ Initial release.
138144
Building from source
139145
--------------------
140146

141-
### Requirements ###
147+
148+
## Build Requirements
142149

143150
* Mac OS X 10.8, Mountain Lion
144151

@@ -158,7 +165,8 @@ Building from source
158165
[launchd_source]: https://opensource.apple.com/source/launchd/launchd-442.26.2/
159166
[discount]: http://www.pell.portland.or.us/~orc/Code/discount/
160167

161-
### Build ###
168+
169+
## Building
162170

163171
1. Clone the [EnvPane repository][envpane_repo] on Github
164172

@@ -222,16 +230,48 @@ The environment of running applications has already been copied and will _not_
222230
be affected.
223231

224232
For applications other than Terminal the only workaround is to restart the
225-
application. In Terminal, you can update the shell's environment by running
233+
application. In Terminal on OS X 10.09 and older, you can update the shell's
234+
environment by running
226235

227236
eval `launchctl export`
228237

229238
This will update the shell's environment, not Terminal's. Terminal's
230239
environment is still unchanged and will be passed on to each new shell window
231240
or tab. This means you will have to run the above command in each subsequently
232241
opened Terminal tab or window. Ultimately it might be better to just restart
233-
Terminal.
234-
242+
Terminal. Unfortunately, 10.10 removed the `export` functionality.
243+
244+
<a id="why-cant-I-set-path-with-envpane"></a>
245+
### Why can't I set PATH with EnvPane?
246+
247+
That's because OS X treats PATH differently to other environment variables, I
248+
suspect for security reasons. The special treatment differs from version to
249+
version of OS X but in a nutshell there are two issues: Firstly, launchd will
250+
forcefully set PATH to a fixed value, overriding a value set using the standard
251+
launchd APIs used by EnvPane. Secondly, a login shell launched in Terminal will
252+
mangle the value by placing entries from `/etc/paths` and `/etc/paths.d` at the
253+
beginning of the PATH variable. There are workarounds for both issues but
254+
EnvPane doesn't currently implement those, mainly because they involve root
255+
privileges, something I've shyed away from so far. You will have to perform
256+
them manually. The launchd override for PATH can be configured using `launchctl
257+
config user path` or `launchctl config system path`. See the `man launchctl`
258+
for details. I *think* the `user` form of that command is broken on El Capitan,
259+
so you'll have to resort to `system` there. Amusingly, there is no documented
260+
way revert to the defaults. You'll have to delete
261+
`/private/var/db/com.apple.xpc.launchd/config/system.plist` and/or
262+
`/private/var/db/com.apple.xpc.launchd/config/user.plist` and reboot. The
263+
`/etc/paths` issue can be worked around by duplicating the additional entries
264+
from `launchctl config … path` in `/etc/paths`. See `man path_helper` for
265+
details.
266+
267+
My personal opinion is that the hardcoding of PATH by launchd is misguided.
268+
PATH was meant to be a mere convenience for interactive shell use. If a
269+
security-sensitive system component needs to ensure that a particular binary is
270+
executed, it should specify that binary using an absolute PATH.
271+
272+
Another rant: the fact that `launchtl config user path` has system-wide scope
273+
and therefore needs sudo privileges is also amusing. If it's called "user" then
274+
it should be user-specific, not global.
235275

236276
## License
237277

@@ -273,6 +313,8 @@ Terminal.
273313

274314
## Acknowledgements
275315

276-
Kudos to Jonathan Levin for his [reversing][new_launchd] of the new launchd and launchctl. I used the trial version of the [Hopper Disassembler/debugger for OS X][hopper] to figure out the rest.
316+
Kudos to Jonathan Levin for his [reversing][new_launchd] of the new launchd and
317+
launchctl. I used the trial version of the [Hopper Disassembler/debugger for OS
318+
X][hopper] to figure out the rest.
277319

278-
[hopper]: https://www.hopperapp.com/
320+
[hopper]: https://www.hopperapp.com/

0 commit comments

Comments
 (0)