Skip to content

Commit

Permalink
Finally close #328. This took deep meditation.
Browse files Browse the repository at this point in the history
Sorry that took so long, Jeff.
  • Loading branch information
StefanKarpinski committed Mar 13, 2012
1 parent 682fd27 commit cfcc147
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
17 changes: 10 additions & 7 deletions jl/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,22 +327,25 @@ end

(|)(src::Cmds, dst::Ports) = stdout(src) | dst
(|)(src::Ports, dst::Cmds) = (src | stdin(dst); dst)
(|)(src::Cmds, dst::Cmds) = (stdout(src)| stdin(dst); src & dst)
(|)(src::Cmds, dst::Cmds) = (stdout(src) | stdin(dst); src & dst)

# spawn(cmd) starts all processes connected to cmd

function spawn(cmd::Cmd)
fds = Set{FileDes}()
for c = cmd.pipeline
fds_ = Set{FileDes}()
for c in cmd.pipeline
if !isa(cmd.status,ProcessNotRun)
if isa(cmd.status,ProcessRunning)
error("already running: ", c)
else
error("already run: ", c)
end
end
for (f,p) = c.pipes
for (f,p) in c.pipes
add(fds, fd(p))
add(fds, other(p))
add(fds_, fd(p))
end
end
gc_disable()
Expand All @@ -353,7 +356,7 @@ function spawn(cmd::Cmd)
dup2_fds = Array(Int32, 2*numel(c.pipes))
close_fds_ = copy(fds)
i = 0
for (f,p) = c.pipes
for (f,p) in c.pipes
dup2_fds[i+=1] = fd(p).fd
dup2_fds[i+=1] = f.fd
del(close_fds_, fd(p))
Expand All @@ -369,7 +372,7 @@ function spawn(cmd::Cmd)
i = 1
n = length(dup2_fds)
while i <= n
# dup2 manually inlined for performance
# dup2 manually inlined to avoid potential heap stomping
r = ccall(:dup2, Int32, (Int32, Int32), dup2_fds[i], dup2_fds[i+1])
if r == -1
println("dup2: ", strerror())
Expand All @@ -380,7 +383,7 @@ function spawn(cmd::Cmd)
i = 1
n = length(close_fds)
while i <= n
# close manually inlined for performance
# close manually inlined to avoid potential heap stomping
r = ccall(:close, Int32, (Int32,), close_fds[i])
if r != 0
println("close: ", strerror())
Expand All @@ -406,7 +409,7 @@ function spawn(cmd::Cmd)
end
c.pid = pid
end
for f in fds
for f in fds_
close(f)
end
gc_enable()
Expand Down
1 change: 1 addition & 0 deletions jl/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ print(x...) = for i=x; print(i); end
println(args...) = print(args..., '\n')

show(s::String) = print_quoted(s)
showln(x) = (show(x); println())

This comment has been minimized.

Copy link
@Keno

Keno Mar 14, 2012

Member

This line seems to be causing #577. I don't know why yet, but uncommenting it solves the problem

This comment has been minimized.

Copy link
@StefanKarpinski

StefanKarpinski Mar 14, 2012

Author Member

Jeff: "This is the craziest thing I've ever seen." I concur.


(*)(s::String...) = strcat(s...)
(^)(s::String, r::Integer) = repeat(s,r)
Expand Down

0 comments on commit cfcc147

Please sign in to comment.