split main loop
split main loop
add sigusr1, fix log errr