chansrv: some fixes to log file path

master
Jay Sorg 8 years ago
parent ab69b8501d
commit 25fd585d55

@ -1387,57 +1387,55 @@ read_ini(void)
} }
/*****************************************************************************/ /*****************************************************************************/
static char* APP_CC static int APP_CC
get_log_path() get_log_path(char *path, int bytes)
{ {
char* log_path = 0; char* log_path;
char* cp = 0; int rv;
rv = 1;
log_path = g_getenv("CHANSRV_LOG_PATH"); log_path = g_getenv("CHANSRV_LOG_PATH");
if (log_path == 0) if (log_path == 0)
{ {
log_path = g_getenv("XDG_DATA_HOME"); log_path = g_getenv("XDG_DATA_HOME");
if (log_path != 0) if (log_path != 0)
{ {
cp = g_new(char, strlen(log_path) + strlen("/xrdp") + 1); g_snprintf(path, bytes, "%s%s", log_path, "/xrdp");
if (g_directory_exist(path) || (g_mkdir(path) == 0))
if (cp != 0)
{
memcpy(cp, log_path, strlen(log_path));
memcpy(cp + strlen(log_path), "/xrdp", strlen("/xrdp") + 1);
if (g_directory_exist(cp) || g_mkdir(cp))
{ {
log_path = cp; rv = 0;
} }
else
{
free(cp);
} }
} }
else
{
g_snprintf(path, bytes, "%s", log_path);
if (g_directory_exist(path) || (g_mkdir(path) == 0))
{
rv = 0;
} }
} }
if (rv != 0)
if (log_path == 0)
{ {
log_path = g_getenv("HOME"); log_path = g_getenv("HOME");
if (log_path != 0) if (log_path != 0)
{ {
cp = g_new(char, strlen(log_path) + strlen("/.local/share/xrdp") + 1); g_snprintf(path, bytes, "%s%s", log_path, "/.local");
if (g_directory_exist(path) || (g_mkdir(path) == 0))
if (cp != 0)
{ {
memcpy(cp, log_path, strlen(log_path)); g_snprintf(path, bytes, "%s%s", log_path, "/.local/share");
memcpy(cp + strlen(log_path), "/.local/share/xrdp", strlen("/.local/share/xrdp") + 1); if (g_directory_exist(path) || (g_mkdir(path) == 0))
if (g_directory_exist(cp) || g_mkdir(cp)) {
log_path = cp; g_snprintf(path, bytes, "%s%s", log_path, "/.local/share/xrdp");
else if (g_directory_exist(path) || (g_mkdir(path) == 0))
free(cp); {
rv = 0;
} }
} }
} }
}
return log_path; }
return rv;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1501,7 +1499,7 @@ main(int argc, char **argv)
tbus waiters[4]; tbus waiters[4];
int pid = 0; int pid = 0;
char text[256]; char text[256];
char* log_path; char log_path[256];
char *display_text; char *display_text;
char log_file[256]; char log_file[256];
enum logReturns error; enum logReturns error;
@ -1510,8 +1508,8 @@ main(int argc, char **argv)
g_init("xrdp-chansrv"); /* os_calls */ g_init("xrdp-chansrv"); /* os_calls */
log_path = get_log_path(); log_path[255] = 0;
if (log_path == 0) if (get_log_path(log_path, 255) != 0)
{ {
g_writeln("error reading CHANSRV_LOG_PATH and HOME environment variable"); g_writeln("error reading CHANSRV_LOG_PATH and HOME environment variable");
g_deinit(); g_deinit();

Loading…
Cancel
Save