summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaniv Kamay <ykamay@redhat.com>2010-01-09 15:49:44 +0200
committerYaniv Kamay <ykamay@redhat.com>2010-01-10 13:40:31 +0200
commitdb5375a5f898c396fc7e66abf1bb761b16c5a684 (patch)
treeef8cf19fa87c199b9f52803b07382387c3177bdd
parent15fff174ebe05d34541a28769686f860fa9adbb3 (diff)
downloadspice-db5375a5f898c396fc7e66abf1bb761b16c5a684.tar.gz
spice-db5375a5f898c396fc7e66abf1bb761b16c5a684.tar.xz
spice-db5375a5f898c396fc7e66abf1bb761b16c5a684.zip
client: move log file to spicec appdata dir
-rw-r--r--client/application.cpp14
-rw-r--r--client/platform.h4
-rw-r--r--client/windows/platform.cpp26
-rw-r--r--client/x11/platform.cpp19
4 files changed, 49 insertions, 14 deletions
diff --git a/client/application.cpp b/client/application.cpp
index 3566adba..d429ad31 100644
--- a/client/application.cpp
+++ b/client/application.cpp
@@ -55,6 +55,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();
@@ -1600,8 +1602,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);
@@ -1754,15 +1756,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 f0ffc0df..a36cdc50 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();
@@ -47,8 +49,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 f8465c26..f92f2cce 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;
@@ -432,6 +430,7 @@ bool Platform::is_monitors_pos_valid()
return true;
}
+/*
void Platform::get_spice_config_dir(std::string& path)
{
char app_data_path[MAX_PATH];
@@ -446,6 +445,29 @@ void Platform::get_spice_config_dir(std::string& path)
}
path += SPICE_CONFIG_DIR;
}
+*/
+
+static 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);
+ if (res != S_OK) {
+ throw Exception("get user app data dir failed");
+ }
+
+ path = app_data_path;
+ path_append(path, app_name);
+
+ if (!CreateDirectory(path.c_str()) && GetLastError() != ERROR_ALREADY_EXISTS) {
+ throw Exception("create user app data dir failed");
+ }
+}
+
+static 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 cff22891..473ba892 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;
@@ -1897,16 +1895,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)