lib/rflow/child_process.rb in rflow-1.0.0 vs lib/rflow/child_process.rb in rflow-1.0.1
- old
+ new
@@ -24,10 +24,11 @@
def run_child_process
@child_pipe_w.close
register_logging_context
update_process_name
+ detach_process_group
handle_signals
RFlow.logger.info "#{@role} started"
run_process
exit 0
@@ -59,11 +60,11 @@
self
end
def register_logging_context
# arrange for child's name to appear in log messages
- Log4r::NDC.push @name
+ Log4r::NDC.push sprintf("%-#{RFlow.logger.context_width}s", @name)
end
def clone_logging_context
Log4r::NDC.clone_stack
end
@@ -73,9 +74,15 @@
end
def update_process_name
# set the visible process name to match the child's name
$0 += " #{@name}"
+ end
+
+ # detach from parent process group so shutdown remains orderly (prevent
+ # signals from being delivered to entire group)
+ def detach_process_group
+ Process.setpgid(0, 0)
end
def handle_signals
Signal.trap 'SIGCHLD', 'DEFAULT' # make sure child process can run subshells