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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/git_mirror.rb b/lib/git_mirror.rb index 88a94ac..4ab5e32 100644 --- a/lib/git_mirror.rb +++ b/lib/git_mirror.rb @@ -45,8 +45,8 @@ 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) + # Check whether mirror_dir is a good git repository by 2 conditions. If not, delete it. + 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)