when use system() or %x() call shell command git, there would be a new child process to do git command. And it seems the child process doesn't clear everytime when it's finished. It needs to be waited by parent process.
But it often comes out 'no child' error when wait in main thread, so I trap SIGCHLD to SIG_IGN, and the init process will handle it.
Signed-off-by: Li Yuanchao lyc163mail@163.com --- lib/git_mirror.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/git_mirror.rb b/lib/git_mirror.rb index 88a94ac..0420c10 100644 --- a/lib/git_mirror.rb +++ b/lib/git_mirror.rb @@ -46,7 +46,7 @@ class GitMirror def git_fetch(mirror_dir) fetch_info = %x(git -C #{mirror_dir} fetch 2>&1) # Check whether mirror_dir is a good git repository by 3 conditions. If not, delete it. - if ($CHILD_STATUS.exitstatus == ERR_CODE) && fetch_info.include?(ERR_MESSAGE) && Dir.empty?(mirror_dir) + if fetch_info.include?(ERR_MESSAGE) && Dir.empty?(mirror_dir) FileUtils.rmdir(mirror_dir) end return fetch_info.include? '->' @@ -89,6 +89,7 @@ class MirrorMain connection.start channel = connection.create_channel @message_queue = channel.queue('new_refs') + Signal.trap(:SIGCHLD, 'SIG_IGN') end
def fork_stat_init(stat_key)