update dirname and finish daemon.cpp