-
-
Notifications
You must be signed in to change notification settings - Fork 195
feat: fix path injection on macos 15 #841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -31,20 +31,31 @@ def self.inject_icon_options | |||||
| end | ||||||
|
|
||||||
| def inject_path | ||||||
| ohai "Injecting PATH value to Emacs.app/Contents/Info.plist" | ||||||
| ohai "Injecting PATH via wrapper script in Emacs.app/Contents/MacOS/Emacs" | ||||||
| app = "#{prefix}/Emacs.app" | ||||||
| plist = "#{app}/Contents/Info.plist" | ||||||
| emacs_binary = "#{app}/Contents/MacOS/Emacs" | ||||||
| emacs_real = "#{app}/Contents/MacOS/Emacs-real" | ||||||
| path = PATH.new(ORIGINAL_PATHS) | ||||||
|
|
||||||
| puts "Patching plist at #{plist} with following PATH value:" | ||||||
| puts "Creating wrapper script with following PATH value:" | ||||||
| path.each_entry { |x| | ||||||
| puts x | ||||||
| } | ||||||
|
|
||||||
| system "/usr/libexec/PlistBuddy -c 'Add :LSEnvironment dict' '#{plist}'" | ||||||
| system "/usr/libexec/PlistBuddy -c 'Add :LSEnvironment:PATH string' '#{plist}'" | ||||||
| system "/usr/libexec/PlistBuddy -c 'Set :LSEnvironment:PATH #{path}' '#{plist}'" | ||||||
| system "/usr/libexec/PlistBuddy -c 'Print :LSEnvironment' '#{plist}'" | ||||||
| # Rename original binary | ||||||
| File.rename(emacs_binary, emacs_real) unless File.exist?(emacs_real) | ||||||
|
|
||||||
| # Create wrapper script | ||||||
| File.open(emacs_binary, "w") do |f| | ||||||
| f.write <<~EOS | ||||||
| #!/bin/bash | ||||||
|
||||||
| #!/bin/bash | |
| #!/usr/bin/env bash |
I think this would be a better idea to allow newer bash versions as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure there is difference; if Emacs is run via launchctl (finder, spotlight, etc), it will be built-in bash anyways
this actually makes me wonder if we need to provide an env variable to skip setting PATH here - for cases when you want run Emacs from terminal, but... oh maybe I also need to make emacs bin to run original Emacs executable instead of this modified version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh fair point! I guess I just knee jerk look for that shebang lol. I agree having an opt out knob in the form of something like EMACS_PLUS_NO_PATH_INJECTION even if overly verbose is a good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, I am on a party right now, so not super focused
hence - all feedback and comments are appreciated even more than usually ❤️
p.s. pushed ability to dynamically disable path injection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably be more correct here to use #!/bin/sh . macOS does unfortunately depend on bash pretty closely, but /bin/sh is a slightly leaner and more standards-compliant build of bash which will make startup a little faster. Apple has been (extremely slowly, since it's such a core system component) moving away from bash by steering users to zsh as the default login shell, so we can expect it'll go away eventually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I really appreciate the work keeping this project alive for emacs on macOS. Thanks for all the time you spend on it! PR LGTM!
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the users's homebrew path has a shell metacharacter in it you'll trigger the same kinds of bugs as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, disregard, it was about original exec "#{emacs_real}" "$@" and not the proposed code. I will update PR after I test that it works.
Not sure I understand you. Are you talking about a situation when someone installed Homebrew in a path like:
- /path with spaces/homebrew
- /foo$bar/homebrew
- /some/path
withbackticks/homebrew
If that's what you are talking about, then let's trace through what happens:
$0= path to the wrapper script (e.g.,/opt/homebrew/.../Emacs)dirname "$0"= directory containing the script$(dirname "$0")/Emacs-real= constructs the path toEmacs-real- The whole thing is wrapped in
"..."(double quotes)
The double quotes around the entire "$(dirname "$0")/Emacs-real" protect against spaces and most special characters. The inner "$0" also protects the path when passed to dirname.
So are you concerned about extremely exotic cases like:
- Paths with newlines
- Paths with $ that might expand inside the double quotes
?
Honestly, if someone's Homebrew prefix contains shell metacharacters, everything would break, not just Emacs. So this sounds more like a theoretical concern.
Or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Computing the absolute path here makes the app bundle non-relocatable. No need to introduce more problems here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to clarify, what I mean is that the script can itself compute a relative path internally, with something like
"$(dirname $0)/Emacs-real", which avoids the need for havingemacs_realdefined at all in Ruby.