Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
06f72ab3
Commit
06f72ab3
authored
9 years ago
by
Xu Cheng
Browse files
Options
Downloads
Patches
Plain Diff
move safe_fork into a standalone method
parent
c952fda2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Library/Homebrew/formula_installer.rb
+5
-42
5 additions, 42 deletions
Library/Homebrew/formula_installer.rb
Library/Homebrew/utils.rb
+1
-0
1 addition, 0 deletions
Library/Homebrew/utils.rb
Library/Homebrew/utils/fork.rb
+44
-0
44 additions, 0 deletions
Library/Homebrew/utils/fork.rb
with
50 additions
and
42 deletions
Library/Homebrew/formula_installer.rb
+
5
−
42
View file @
06f72ab3
...
...
@@ -11,8 +11,6 @@ require 'install_renamed'
require
'cmd/tap'
require
'hooks/bottles'
require
'debrew'
require
'fcntl'
require
'socket'
require
'sandbox'
class
FormulaInstaller
...
...
@@ -458,9 +456,6 @@ class FormulaInstaller
end
def
build
socket_path
=
"
#{
Dir
.
mktmpdir
(
"homebrew"
,
HOMEBREW_TEMP
)
}
/socket"
server
=
UNIXServer
.
new
(
socket_path
)
FileUtils
.
rm
Dir
[
"
#{
HOMEBREW_LOGS
}
/
#{
formula
.
name
}
/*"
]
@start_time
=
Time
.
now
...
...
@@ -468,9 +463,6 @@ class FormulaInstaller
# 1. formulae can modify ENV, so we must ensure that each
# installation has a pristine ENV when it starts, forking now is
# the easiest way to do this
read
,
write
=
IO
.
pipe
ENV
[
"HOMEBREW_ERROR_PIPE"
]
=
socket_path
args
=
%W[
nice
#{
RUBY_PATH
}
-W0
...
...
@@ -480,39 +472,13 @@ class FormulaInstaller
#{
formula
.
path
}
]
.
concat
(
build_argv
)
pid
=
fork
do
begin
server
.
close
read
.
close
write
.
fcntl
(
Fcntl
::
F_SETFD
,
Fcntl
::
FD_CLOEXEC
)
if
Sandbox
.
available?
&&
ARGV
.
sandbox?
sandbox
=
Sandbox
.
new
(
formula
)
sandbox
.
exec
(
*
args
)
else
exec
(
*
args
)
end
rescue
Exception
=>
e
Marshal
.
dump
(
e
,
write
)
write
.
close
exit!
1
end
end
ignore_interrupts
(
:quietly
)
do
# the child will receive the interrupt and marshal it back
begin
socket
=
server
.
accept_nonblock
rescue
Errno
::
EAGAIN
,
Errno
::
EWOULDBLOCK
,
Errno
::
ECONNABORTED
,
Errno
::
EPROTO
,
Errno
::
EINTR
retry
unless
Process
.
waitpid
(
pid
,
Process
::
WNOHANG
)
Utils
.
safe_fork
do
if
Sandbox
.
available?
&&
ARGV
.
sandbox?
sandbox
=
Sandbox
.
new
(
formula
)
sandbox
.
exec
(
*
args
)
else
socket
.
send_io
(
write
)
exec
(
*
args
)
end
write
.
close
data
=
read
.
read
read
.
close
Process
.
wait
(
pid
)
unless
socket
.
nil?
raise
Marshal
.
load
(
data
)
unless
data
.
nil?
or
data
.
empty?
raise
Interrupt
if
$?
.
exitstatus
==
130
raise
"Suspicious installation failure"
unless
$?
.
success?
end
raise
"Empty installation"
if
Dir
[
"
#{
formula
.
prefix
}
/*"
].
empty?
...
...
@@ -524,9 +490,6 @@ class FormulaInstaller
formula
.
rack
.
rmdir_if_possible
end
raise
ensure
server
.
close
FileUtils
.
rm_r
File
.
dirname
(
socket_path
)
end
def
link
(
keg
)
...
...
This diff is collapsed.
Click to expand it.
Library/Homebrew/utils.rb
+
1
−
0
View file @
06f72ab3
...
...
@@ -4,6 +4,7 @@ require 'os/mac'
require
'utils/json'
require
'utils/inreplace'
require
'utils/popen'
require
'utils/fork'
require
'open-uri'
class
Tty
...
...
This diff is collapsed.
Click to expand it.
Library/Homebrew/utils/fork.rb
0 → 100644
+
44
−
0
View file @
06f72ab3
require
"fcntl"
require
"socket"
module
Utils
def
self
.
safe_fork
(
&
block
)
socket_path
=
"
#{
Dir
.
mktmpdir
(
"homebrew"
,
HOMEBREW_TEMP
)
}
/socket"
server
=
UNIXServer
.
new
(
socket_path
)
ENV
[
"HOMEBREW_ERROR_PIPE"
]
=
socket_path
read
,
write
=
IO
.
pipe
pid
=
fork
do
begin
server
.
close
read
.
close
write
.
fcntl
(
Fcntl
::
F_SETFD
,
Fcntl
::
FD_CLOEXEC
)
yield
rescue
Exception
=>
e
Marshal
.
dump
(
e
,
write
)
write
.
close
exit!
1
end
end
ignore_interrupts
(
:quietly
)
do
# the child will receive the interrupt and marshal it back
begin
socket
=
server
.
accept_nonblock
rescue
Errno
::
EAGAIN
,
Errno
::
EWOULDBLOCK
,
Errno
::
ECONNABORTED
,
Errno
::
EPROTO
,
Errno
::
EINTR
retry
unless
Process
.
waitpid
(
pid
,
Process
::
WNOHANG
)
else
socket
.
send_io
(
write
)
end
write
.
close
data
=
read
.
read
read
.
close
Process
.
wait
(
pid
)
unless
socket
.
nil?
raise
Marshal
.
load
(
data
)
unless
data
.
nil?
or
data
.
empty?
raise
Interrupt
if
$?
.
exitstatus
==
130
raise
"Suspicious failure"
unless
$?
.
success?
end
ensure
server
.
close
FileUtils
.
rm_r
File
.
dirname
(
socket_path
)
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment