static void handle_signal(int sig_no){ int iret = -1; switch(sig_no){ case SIGINT: write_log(LOG_NOTIFY , "logic server: receive sig int. ready to exit..."); /*脱离BUS*/ iret = close_bus(connect_server_id , logic_server_id); if(iret < 0){ write_log(LOG_ERR , "logic server: detach bus to connect failed!"); } write_log(LOG_NOTIFY , "logic server: detach bus to connect success!"); /*脱离游戏运行时环境共享资源*/ iret = detach_shm_res(GAME_RT_ENV , world_id , line_id); if(iret < 0){ write_log(LOG_ERR , "logic server: detach runtime_env failed!"); } write_log(LOG_NOTIFY , "logic server: detach runtime_env success!"); /*脱离在线玩家共享资源*/ iret = detach_shm_res(GAME_ONLINE_PLAYERS , world_id , line_id); if(iret < 0){ write_log(LOG_ERR , "logic server: detach online_players failed!"); } write_log(LOG_NOTIFY , "logic server: detach online_players success!"); exit(0); break; /*设置重新加载模块标志*/ case SIGUSR1: printf("recv sig usr1~\n"); ctrl_msg = 1; break; default: break; } }
/* * First of all, creates a transaction; * then reads the newly created bus path, * adds a match to the bus to wait until installation is really finished before notifying the user. * finally, calls InstallFiles method, and processes the bus while finished == 0. */ void *install_package(void *str) { sd_bus_error error = SD_BUS_ERROR_NULL; sd_bus_message *mess = NULL; sd_bus *install_bus = NULL; const char *path; int r, inhibit_fd = -1, finished = 0; r = sd_bus_open_system(&install_bus); if (r < 0) { print_and_warn(strerror(-r), ERR_LINE); goto finish; } INFO("calling CreateTransaction on bus."); r = sd_bus_call_method(install_bus, "org.freedesktop.PackageKit", "/org/freedesktop/PackageKit", "org.freedesktop.PackageKit", "CreateTransaction", &error, &mess, NULL); if (r < 0) { print_and_warn(error.message, ERR_LINE); goto finish; } if (config.inhibit) { inhibit_fd = inhibit_suspend("Package installation..."); } sd_bus_message_read(mess, "o", &path); r = sd_bus_add_match(install_bus, NULL, "type='signal',interface='org.freedesktop.PackageKit.Transaction',member='Finished'", match_callback, &finished); if (r < 0) { print_and_warn(strerror(-r), ERR_LINE); goto finish; } sd_bus_flush(install_bus); INFO("calling InstallFiles on bus."); r = sd_bus_call_method(install_bus, "org.freedesktop.PackageKit", path, "org.freedesktop.PackageKit.Transaction", "InstallFiles", &error, NULL, "tas", 0, 1, (char *)str); if (r < 0) { print_and_warn(error.message, ERR_LINE); goto finish; } while (!finished) { r = sd_bus_process(install_bus, NULL); if (r > 0) { continue; } r = sd_bus_wait(install_bus, (uint64_t) -1); if (r < 0) { break; } } finish: stop_inhibition(inhibit_fd); close_bus(&error, mess, install_bus); pthread_detach(pthread_self()); pthread_exit(NULL); }