xrdp: pid file fixes
This commit is contained in:
parent
0566da74eb
commit
62bf3c61f5
@ -1404,6 +1404,44 @@ g_create_dir(const char* dirname)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* will try to create directories up to last / in name
|
||||||
|
example /tmp/a/b/c/readme.txt will try to create /tmp/a/b/c
|
||||||
|
returns boolean */
|
||||||
|
int APP_CC
|
||||||
|
g_create_path(const char* path)
|
||||||
|
{
|
||||||
|
char* pp;
|
||||||
|
char* sp;
|
||||||
|
char* copypath;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
status = 1;
|
||||||
|
copypath = g_strdup(path);
|
||||||
|
pp = copypath;
|
||||||
|
sp = strchr(pp, '/');
|
||||||
|
while (sp != 0)
|
||||||
|
{
|
||||||
|
if (sp != pp)
|
||||||
|
{
|
||||||
|
*sp = 0;
|
||||||
|
if (!g_directory_exist(copypath))
|
||||||
|
{
|
||||||
|
if (!g_create_dir(copypath))
|
||||||
|
{
|
||||||
|
status = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*sp = '/';
|
||||||
|
}
|
||||||
|
pp = sp + 1;
|
||||||
|
sp = strchr(pp, '/');
|
||||||
|
}
|
||||||
|
g_free(copypath);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns boolean */
|
/* returns boolean */
|
||||||
int APP_CC
|
int APP_CC
|
||||||
|
@ -161,6 +161,8 @@ g_directory_exist(const char* dirname);
|
|||||||
int APP_CC
|
int APP_CC
|
||||||
g_create_dir(const char* dirname);
|
g_create_dir(const char* dirname);
|
||||||
int APP_CC
|
int APP_CC
|
||||||
|
g_create_path(const char* path);
|
||||||
|
int APP_CC
|
||||||
g_remove_dir(const char* dirname);
|
g_remove_dir(const char* dirname);
|
||||||
int APP_CC
|
int APP_CC
|
||||||
g_file_delete(const char* filename);
|
g_file_delete(const char* filename);
|
||||||
|
28
xrdp/xrdp.c
28
xrdp/xrdp.c
@ -330,7 +330,7 @@ main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
g_writeln("problem opening to xrdp.pid");
|
g_writeln("problem opening to xrdp.pid [%s]", pid_file);
|
||||||
g_writeln("maybe its not running");
|
g_writeln("maybe its not running");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -389,6 +389,10 @@ main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
if (!no_daemon)
|
if (!no_daemon)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/* make sure containing directory exists */
|
||||||
|
g_create_path(pid_file);
|
||||||
|
|
||||||
/* make sure we can write to pid file */
|
/* make sure we can write to pid file */
|
||||||
fd = g_file_open(pid_file); /* xrdp.pid */
|
fd = g_file_open(pid_file); /* xrdp.pid */
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
@ -424,16 +428,6 @@ main(int argc, char** argv)
|
|||||||
g_exit(0);
|
g_exit(0);
|
||||||
}
|
}
|
||||||
g_sleep(1000);
|
g_sleep(1000);
|
||||||
g_file_close(0);
|
|
||||||
g_file_close(1);
|
|
||||||
g_file_close(2);
|
|
||||||
g_file_open("/dev/null");
|
|
||||||
g_file_open("/dev/null");
|
|
||||||
g_file_open("/dev/null");
|
|
||||||
/* end of daemonizing code */
|
|
||||||
}
|
|
||||||
if (!no_daemon)
|
|
||||||
{
|
|
||||||
/* write the pid to file */
|
/* write the pid to file */
|
||||||
pid = g_getpid();
|
pid = g_getpid();
|
||||||
fd = g_file_open(pid_file); /* xrdp.pid */
|
fd = g_file_open(pid_file); /* xrdp.pid */
|
||||||
@ -449,6 +443,14 @@ main(int argc, char** argv)
|
|||||||
g_file_write(fd, text, g_strlen(text));
|
g_file_write(fd, text, g_strlen(text));
|
||||||
g_file_close(fd);
|
g_file_close(fd);
|
||||||
}
|
}
|
||||||
|
g_sleep(1000);
|
||||||
|
g_file_close(0);
|
||||||
|
g_file_close(1);
|
||||||
|
g_file_close(2);
|
||||||
|
g_file_open("/dev/null");
|
||||||
|
g_file_open("/dev/null");
|
||||||
|
g_file_open("/dev/null");
|
||||||
|
/* end of daemonizing code */
|
||||||
}
|
}
|
||||||
g_threadid = tc_get_threadid();
|
g_threadid = tc_get_threadid();
|
||||||
g_listen = xrdp_listen_create();
|
g_listen = xrdp_listen_create();
|
||||||
@ -475,8 +477,12 @@ main(int argc, char** argv)
|
|||||||
tc_mutex_delete(g_sync1_mutex);
|
tc_mutex_delete(g_sync1_mutex);
|
||||||
g_delete_wait_obj(g_term_event);
|
g_delete_wait_obj(g_term_event);
|
||||||
g_delete_wait_obj(g_sync_event);
|
g_delete_wait_obj(g_sync_event);
|
||||||
|
/* only main process should delete pid file */
|
||||||
|
if ((!no_daemon) && (pid == g_getpid()))
|
||||||
|
{
|
||||||
/* delete the xrdp.pid file */
|
/* delete the xrdp.pid file */
|
||||||
g_file_delete(pid_file);
|
g_file_delete(pid_file);
|
||||||
|
}
|
||||||
g_free(startup_params);
|
g_free(startup_params);
|
||||||
g_deinit();
|
g_deinit();
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user