/tmp cleanup
This commit is contained in:
parent
2225aa80ad
commit
cadad6e181
@ -82,6 +82,70 @@ extern char** environ;
|
||||
static char g_temp_base[128] = "";
|
||||
static char g_temp_base_org[128] = "";
|
||||
|
||||
/*****************************************************************************/
|
||||
int APP_CC
|
||||
g_rm_temp_dir(void)
|
||||
{
|
||||
if (g_temp_base[0] != 0)
|
||||
{
|
||||
if (!g_remove_dir(g_temp_base))
|
||||
{
|
||||
printf("g_rm_temp_dir: removing temp directory [%s] failed\n", g_temp_base);
|
||||
}
|
||||
g_temp_base[0] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int APP_CC
|
||||
g_mk_temp_dir(const char* app_name)
|
||||
{
|
||||
if (app_name != 0)
|
||||
{
|
||||
if (app_name[0] != 0)
|
||||
{
|
||||
if (!g_directory_exist("/tmp/.xrdp"))
|
||||
{
|
||||
if (!g_create_dir("/tmp/.xrdp"))
|
||||
{
|
||||
printf("g_mk_temp_dir: g_create_dir failed\n");
|
||||
return 1;
|
||||
}
|
||||
g_chmod_hex("/tmp/.xrdp", 0x1777);
|
||||
}
|
||||
snprintf(g_temp_base, sizeof(g_temp_base),
|
||||
"/tmp/.xrdp/%s-XXXXXX", app_name);
|
||||
snprintf(g_temp_base_org, sizeof(g_temp_base_org),
|
||||
"/tmp/.xrdp/%s-XXXXXX", app_name);
|
||||
if (mkdtemp(g_temp_base) == 0)
|
||||
{
|
||||
printf("g_mk_temp_dir: mkdtemp failed [%s]\n", g_temp_base);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("g_mk_temp_dir: bad app name\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_temp_base_org[0] == 0)
|
||||
{
|
||||
printf("g_mk_temp_dir: g_temp_base_org not set\n");
|
||||
return 1;
|
||||
}
|
||||
g_strncpy(g_temp_base, g_temp_base_org, 127);
|
||||
if (mkdtemp(g_temp_base) == 0)
|
||||
{
|
||||
printf("g_mk_temp_dir: mkdtemp failed [%s]\n", g_temp_base);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void APP_CC
|
||||
g_init(const char* app_name)
|
||||
@ -92,25 +156,7 @@ g_init(const char* app_name)
|
||||
WSAStartup(2, &wsadata);
|
||||
#endif
|
||||
setlocale(LC_CTYPE, "");
|
||||
if (app_name != 0)
|
||||
{
|
||||
if (app_name[0] != 0)
|
||||
{
|
||||
if (!g_directory_exist("/tmp/.xrdp"))
|
||||
{
|
||||
g_create_dir("/tmp/.xrdp");
|
||||
g_chmod_hex("/tmp/.xrdp", 0x1777);
|
||||
}
|
||||
snprintf(g_temp_base, sizeof(g_temp_base),
|
||||
"/tmp/.xrdp/%s-XXXXXX", app_name);
|
||||
snprintf(g_temp_base_org, sizeof(g_temp_base_org),
|
||||
"/tmp/.xrdp/%s-XXXXXX", app_name);
|
||||
if (mkdtemp(g_temp_base) == 0)
|
||||
{
|
||||
printf("g_init: mkdtemp failed [%s]\n", g_temp_base);
|
||||
}
|
||||
}
|
||||
}
|
||||
g_mk_temp_dir(app_name);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -120,7 +166,7 @@ g_deinit(void)
|
||||
#if defined(_WIN32)
|
||||
WSACleanup();
|
||||
#endif
|
||||
g_remove_dir(g_temp_base);
|
||||
g_rm_temp_dir();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -1838,7 +1884,12 @@ g_execvp(const char* p1, char* args[])
|
||||
#if defined(_WIN32)
|
||||
return 0;
|
||||
#else
|
||||
return execvp(p1, args);
|
||||
int rv;
|
||||
|
||||
g_rm_temp_dir();
|
||||
rv = execvp(p1, args);
|
||||
g_mk_temp_dir(0);
|
||||
return rv;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1850,7 +1901,12 @@ g_execlp3(const char* a1, const char* a2, const char* a3)
|
||||
#if defined(_WIN32)
|
||||
return 0;
|
||||
#else
|
||||
return execlp(a1, a2, a3, (void*)0);
|
||||
int rv;
|
||||
|
||||
g_rm_temp_dir();
|
||||
rv = execlp(a1, a2, a3, (void*)0);
|
||||
g_mk_temp_dir(0);
|
||||
return rv;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1944,11 +2000,7 @@ g_fork(void)
|
||||
rv = fork();
|
||||
if (rv == 0) /* child */
|
||||
{
|
||||
g_strncpy(g_temp_base, g_temp_base_org, 127);
|
||||
if (mkdtemp(g_temp_base) == 0)
|
||||
{
|
||||
printf("g_fork: mkdtemp failed [%s]\n", g_temp_base);
|
||||
}
|
||||
g_mk_temp_dir(0);
|
||||
}
|
||||
return rv;
|
||||
#endif
|
||||
|
@ -31,6 +31,10 @@
|
||||
|
||||
#include "arch.h"
|
||||
|
||||
int APP_CC
|
||||
g_rm_temp_dir(void);
|
||||
int APP_CC
|
||||
g_mk_temp_dir(const char* app_name);
|
||||
void APP_CC
|
||||
g_init(const char* app_name);
|
||||
void APP_CC
|
||||
|
@ -74,6 +74,7 @@ env_set_user(char* username, char* passwd_file, int display)
|
||||
pw_gecos);
|
||||
if (error == 0)
|
||||
{
|
||||
g_rm_temp_dir();
|
||||
error = g_setgid(pw_gid);
|
||||
if (error == 0)
|
||||
{
|
||||
@ -84,6 +85,7 @@ env_set_user(char* username, char* passwd_file, int display)
|
||||
uid = pw_uid;
|
||||
error = g_setuid(uid);
|
||||
}
|
||||
g_mk_temp_dir(0);
|
||||
if (error == 0)
|
||||
{
|
||||
g_clearenv();
|
||||
|
@ -86,6 +86,7 @@ main(int argc, char** argv)
|
||||
if (argc < 3)
|
||||
{
|
||||
g_writeln("xrdp-sessvc: exiting, not enough parameters");
|
||||
g_deinit();
|
||||
return 1;
|
||||
}
|
||||
g_signal_kill(term_signal_handler); /* SIGKILL */
|
||||
@ -101,6 +102,7 @@ main(int argc, char** argv)
|
||||
if (chansrv_pid == -1)
|
||||
{
|
||||
g_writeln("xrdp-sessvc: fork error");
|
||||
g_deinit();
|
||||
return 1;
|
||||
}
|
||||
else if (chansrv_pid == 0) /* child */
|
||||
@ -110,6 +112,7 @@ main(int argc, char** argv)
|
||||
g_execlp3(exe_path, "xrdp-chansrv", 0);
|
||||
/* should not get here */
|
||||
g_writeln("xrdp-sessvc: g_execlp3() failed");
|
||||
g_deinit();
|
||||
return 1;
|
||||
}
|
||||
lerror = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user