diff options
author | Yaniv Kamay <ykamay@redhat.com> | 2010-01-11 19:30:39 +0200 |
---|---|---|
committer | Yaniv Kamay <ykamay@redhat.com> | 2010-01-11 19:30:39 +0200 |
commit | ad121810278c1e2851f74c370e1cb36e52367be3 (patch) | |
tree | e6cf3525bcf2b1161bbe5177d9c60f90183736a4 /client | |
parent | 3eae1c80d97ce6d1e0eee69f7454973abdb94ef6 (diff) | |
download | spice-ad121810278c1e2851f74c370e1cb36e52367be3.tar.gz spice-ad121810278c1e2851f74c370e1cb36e52367be3.tar.xz spice-ad121810278c1e2851f74c370e1cb36e52367be3.zip |
client: move log file to spicec appdata dir
Diffstat (limited to 'client')
-rw-r--r-- | client/application.cpp | 14 | ||||
-rw-r--r-- | client/platform.h | 4 | ||||
-rw-r--r-- | client/windows/platform.cpp | 17 | ||||
-rw-r--r-- | client/x11/platform.cpp | 19 |
4 files changed, 36 insertions, 18 deletions
diff --git a/client/application.cpp b/client/application.cpp index d4fe59f6..a0e34360 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -57,6 +57,8 @@ mutex_t cairo_surface_user_data_mutex; #endif +static const char* app_name = "spicec"; + void ConnectedEvent::response(AbstractProcessLoop& events_loop) { static_cast<Application*>(events_loop.get_owner())->on_connected(); @@ -1822,8 +1824,8 @@ bool Application::process_cmd_line(int argc, char** argv) _host_auth_opt.type_flags = RedPeer::HostAuthOptions::HOST_AUTH_OP_NAME; - Platform::get_spice_config_dir(_host_auth_opt.CA_file); - _host_auth_opt.CA_file += CA_FILE_NAME; + Platform::get_app_data_dir(_host_auth_opt.CA_file, app_name); + Platform::path_append(_host_auth_opt.CA_file, CA_FILE_NAME); parser.begin(argc, argv); @@ -1954,15 +1956,17 @@ bool Application::process_cmd_line(int argc, char** argv) void Application::init_logger() { - std::string temp_dir_name; - Platform::get_temp_dir(temp_dir_name); - std::string log_file_name = temp_dir_name + "spicec.log"; + std::string log_file_name; + Platform::get_app_data_dir(log_file_name, app_name); + Platform::path_append(log_file_name, "spicec.log"); int fd = ::open(log_file_name.c_str(), O_CREAT | O_APPEND | O_WRONLY, 0644); + if (fd == -1) { log4cpp::BasicConfigurator::configure(); return; } + log4cpp::Category& root = log4cpp::Category::getRoot(); #ifdef RED_DEBUG root.setPriority(log4cpp::Priority::DEBUG); diff --git a/client/platform.h b/client/platform.h index 87a44bb5..ec335540 100644 --- a/client/platform.h +++ b/client/platform.h @@ -38,6 +38,8 @@ public: static void yield(); static uint64_t get_monolithic_time(); static void get_temp_dir(std::string& path); + static void get_app_data_dir(std::string& path, const std::string& app_name); + static void path_append(std::string& path, const std::string& partial_path); static uint64_t get_process_id(); static uint64_t get_thread_id(); static void error_beep(); @@ -48,8 +50,6 @@ public: static void send_quit_request(); - static void get_spice_config_dir(std::string& path); - enum ThreadPriority { PRIORITY_INVALID, PRIORITY_TIME_CRITICAL, diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp index f332fac0..67bb1a02 100644 --- a/client/windows/platform.cpp +++ b/client/windows/platform.cpp @@ -30,8 +30,6 @@ #include "cursor.h" #include "named_pipe.h" -#define SPICE_CONFIG_DIR "spicec\\" - int gdi_handlers = 0; extern HINSTANCE instance; @@ -437,7 +435,7 @@ bool Platform::is_monitors_pos_valid() return true; } -void Platform::get_spice_config_dir(std::string& path) +void Platform::get_app_data_dir(std::string& path, const std::string& app_name) { char app_data_path[MAX_PATH]; HRESULT res = SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, app_data_path); @@ -446,10 +444,17 @@ void Platform::get_spice_config_dir(std::string& path) } path = app_data_path; - if (strcmp((app_data_path + strlen(app_data_path) - 2), "\\") != 0) { - path += "\\"; + path_append(path, app_name); + + if (!CreateDirectoryA(path.c_str(), NULL) && GetLastError() != ERROR_ALREADY_EXISTS) { + throw Exception("create user app data dir failed"); } - path += SPICE_CONFIG_DIR; +} + +void Platform::path_append(std::string& path, const std::string& partial_path) +{ + path += "\\"; + path += partial_path; } void Platform::init() diff --git a/client/x11/platform.cpp b/client/x11/platform.cpp index 4a1f9b23..df689c03 100644 --- a/client/x11/platform.cpp +++ b/client/x11/platform.cpp @@ -64,8 +64,6 @@ #define USE_XRANDR_1_2 #endif -#define SPICE_CONFIG_DIR ".spicec/" - static Display* x_display = NULL; static bool x_shm_avail = false; static XVisualInfo **vinfo = NULL; @@ -1913,16 +1911,27 @@ bool Platform::is_monitors_pos_valid() return (ScreenCount(x_display) == 1); } -void Platform::get_spice_config_dir(std::string& path) +void Platform::get_app_data_dir(std::string& path, const std::string& app_name) { - char* home_dir = getenv("HOME"); + const char* home_dir = getenv("HOME"); + if (!home_dir) { throw Exception("get home dir failed"); } path = home_dir; + path += "/."; + path += app_name; + + if (mkdir(path.c_str(), 0700) == -1 && errno != EEXIST) { + throw Exception("create appdata dir failed"); + } +} + +void Platform::path_append(std::string& path, const std::string& partial_path) +{ path += "/"; - path += SPICE_CONFIG_DIR; + path += partial_path; } static void root_win_proc(XEvent& event) |