/tmp changes
This commit is contained in:
parent
a866b7b330
commit
3d888c2280
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2004-2010 Jay Sorg
|
||||
Copyright (c) 2004-2012 Jay Sorg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
@ -79,7 +79,72 @@ extern char** environ;
|
||||
#define INADDR_NONE ((unsigned long)-1)
|
||||
#endif
|
||||
|
||||
static char g_temp_base[64] = "";
|
||||
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
|
||||
@ -91,17 +156,7 @@ g_init(const char* app_name)
|
||||
WSAStartup(2, &wsadata);
|
||||
#endif
|
||||
setlocale(LC_CTYPE, "");
|
||||
if (app_name != 0)
|
||||
{
|
||||
if (app_name[0] != 0)
|
||||
{
|
||||
snprintf(g_temp_base, sizeof(g_temp_base), "/tmp/%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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -111,7 +166,7 @@ g_deinit(void)
|
||||
#if defined(_WIN32)
|
||||
WSACleanup();
|
||||
#endif
|
||||
g_remove_dir(g_temp_base);
|
||||
g_rm_temp_dir();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -1829,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
|
||||
}
|
||||
|
||||
@ -1841,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
|
||||
}
|
||||
|
||||
@ -1911,6 +1976,17 @@ g_signal_pipe(void (*func)(int))
|
||||
#endif
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* does not work in win32 */
|
||||
void APP_CC
|
||||
g_signal_usr1(void (*func)(int))
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
#else
|
||||
signal(SIGUSR1, func);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* does not work in win32 */
|
||||
int APP_CC
|
||||
@ -1919,7 +1995,14 @@ g_fork(void)
|
||||
#if defined(_WIN32)
|
||||
return 0;
|
||||
#else
|
||||
return fork();
|
||||
int rv;
|
||||
|
||||
rv = fork();
|
||||
if (rv == 0) /* child */
|
||||
{
|
||||
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
|
||||
@ -218,6 +222,8 @@ void APP_CC
|
||||
g_signal_terminate(void (*func)(int));
|
||||
void APP_CC
|
||||
g_signal_pipe(void (*func)(int));
|
||||
void APP_CC
|
||||
g_signal_usr1(void (*func)(int));
|
||||
int APP_CC
|
||||
g_fork(void);
|
||||
int APP_CC
|
||||
|
@ -411,7 +411,7 @@ setup_listen(void)
|
||||
if (g_use_unix_socket)
|
||||
{
|
||||
g_lis_trans = trans_create(2, 8192, 8192);
|
||||
g_snprintf(port, 255, "/tmp/xrdp_chansrv_socket_%d", 7200 + g_display_num);
|
||||
g_snprintf(port, 255, "/tmp/.xrdp/xrdp_chansrv_socket_%d", 7200 + g_display_num);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -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();
|
||||
|
@ -167,6 +167,7 @@ main(int argc, char** argv)
|
||||
g_printf("-k, --kill kills running sesman\n");
|
||||
g_printf("-h, --help shows this help\n");
|
||||
g_printf("if no command is specified, sesman is started in background");
|
||||
g_deinit();
|
||||
g_exit(0);
|
||||
}
|
||||
else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--kill")) ||
|
||||
@ -178,6 +179,7 @@ main(int argc, char** argv)
|
||||
if (!g_file_exist(pid_file))
|
||||
{
|
||||
g_printf("sesman is not running (pid file not found - %s)\n", pid_file);
|
||||
g_deinit();
|
||||
g_exit(1);
|
||||
}
|
||||
|
||||
@ -194,6 +196,7 @@ main(int argc, char** argv)
|
||||
{
|
||||
g_printf("error reading pid file: %s\n", g_get_strerror());
|
||||
g_file_close(fd);
|
||||
g_deinit();
|
||||
g_exit(error);
|
||||
}
|
||||
g_file_close(fd);
|
||||
@ -208,7 +211,7 @@ main(int argc, char** argv)
|
||||
{
|
||||
g_file_delete(pid_file);
|
||||
}
|
||||
|
||||
g_deinit();
|
||||
g_exit(error);
|
||||
}
|
||||
else
|
||||
@ -217,6 +220,7 @@ main(int argc, char** argv)
|
||||
g_printf("sesman - xrdp session manager\n\n");
|
||||
g_printf("error: invalid command line\n");
|
||||
g_printf("usage: sesman [ --nodaemon | --kill | --help ]\n");
|
||||
g_deinit();
|
||||
g_exit(1);
|
||||
}
|
||||
|
||||
@ -226,6 +230,7 @@ main(int argc, char** argv)
|
||||
g_printf("if it's not running, try removing ");
|
||||
g_printf(pid_file);
|
||||
g_printf("\n");
|
||||
g_deinit();
|
||||
g_exit(1);
|
||||
}
|
||||
|
||||
@ -234,12 +239,14 @@ main(int argc, char** argv)
|
||||
if (0 == g_cfg)
|
||||
{
|
||||
g_printf("error creating config: quitting.\n");
|
||||
g_deinit();
|
||||
g_exit(1);
|
||||
}
|
||||
g_cfg->log.fd = -1; /* don't use logging before reading its config */
|
||||
if (0 != config_read(g_cfg))
|
||||
{
|
||||
g_printf("error reading config: %s\nquitting.\n", g_get_strerror());
|
||||
g_deinit();
|
||||
g_exit(1);
|
||||
}
|
||||
|
||||
@ -257,6 +264,7 @@ main(int argc, char** argv)
|
||||
g_printf("error opening log file [%s]. quitting.\n", g_cfg->log.log_file);
|
||||
break;
|
||||
}
|
||||
g_deinit();
|
||||
g_exit(1);
|
||||
}
|
||||
|
||||
@ -270,6 +278,7 @@ main(int argc, char** argv)
|
||||
|
||||
if (0 != g_pid)
|
||||
{
|
||||
g_deinit();
|
||||
g_exit(0);
|
||||
}
|
||||
|
||||
@ -312,6 +321,7 @@ main(int argc, char** argv)
|
||||
"error opening pid file[%s]: %s",
|
||||
pid_file, g_get_strerror());
|
||||
log_end(&(g_cfg->log));
|
||||
g_deinit();
|
||||
g_exit(1);
|
||||
}
|
||||
g_sprintf(pid_s, "%d", g_pid);
|
||||
|
@ -56,12 +56,12 @@ chansrv_cleanup(int pid)
|
||||
{
|
||||
char text[256];
|
||||
|
||||
g_snprintf(text, 255, "/tmp/xrdp_chansrv_%8.8x_main_term", pid);
|
||||
g_snprintf(text, 255, "/tmp/.xrdp/xrdp_chansrv_%8.8x_main_term", pid);
|
||||
if (g_file_exist(text))
|
||||
{
|
||||
g_file_delete(text);
|
||||
}
|
||||
g_snprintf(text, 255, "/tmp/xrdp_chansrv_%8.8x_thread_done", pid);
|
||||
g_snprintf(text, 255, "/tmp/.xrdp/xrdp_chansrv_%8.8x_thread_done", pid);
|
||||
if (g_file_exist(text))
|
||||
{
|
||||
g_file_delete(text);
|
||||
@ -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;
|
||||
|
@ -49,7 +49,7 @@ int main(int argc, char** argv)
|
||||
dis = strtol(display + 1, &p, 10);
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sun_family = AF_UNIX;
|
||||
sprintf(sa.sun_path, "/tmp/xrdp_disconnect_display_%d", dis);
|
||||
sprintf(sa.sun_path, "/tmp/.xrdp/xrdp_disconnect_display_%d", dis);
|
||||
if (access(sa.sun_path, F_OK) != 0)
|
||||
{
|
||||
printf("not in an xrdp session\n");
|
||||
|
@ -279,6 +279,7 @@ main(int argc, char** argv)
|
||||
g_writeln("Unknown Parameter");
|
||||
g_writeln("xrdp -h for help");
|
||||
g_writeln("");
|
||||
g_deinit();
|
||||
g_exit(0);
|
||||
}
|
||||
|
||||
@ -311,6 +312,7 @@ main(int argc, char** argv)
|
||||
}
|
||||
g_file_close(fd);
|
||||
}
|
||||
g_deinit();
|
||||
g_exit(0);
|
||||
}
|
||||
if (startup_params->no_daemon)
|
||||
@ -329,6 +331,7 @@ main(int argc, char** argv)
|
||||
g_writeln(" -nodaemon: don't fork into background");
|
||||
g_writeln(" -kill: shut down xrdp");
|
||||
g_writeln("");
|
||||
g_deinit();
|
||||
g_exit(0);
|
||||
}
|
||||
if (startup_params->version)
|
||||
@ -339,12 +342,14 @@ main(int argc, char** argv)
|
||||
g_writeln("See http://xrdp.sourceforge.net for more information.");
|
||||
g_writeln("Version %s",PACKAGE_VERSION);
|
||||
g_writeln("");
|
||||
g_deinit();
|
||||
g_exit(0);
|
||||
}
|
||||
if (g_file_exist(pid_file)) /* xrdp.pid */
|
||||
{
|
||||
g_writeln("It looks like xrdp is allready running,");
|
||||
g_writeln("if not delete the xrdp.pid file and try again");
|
||||
g_deinit();
|
||||
g_exit(0);
|
||||
}
|
||||
if (!no_daemon)
|
||||
@ -354,11 +359,13 @@ main(int argc, char** argv)
|
||||
if (fd == -1)
|
||||
{
|
||||
g_writeln("running in daemon mode with no access to pid files, quitting");
|
||||
g_deinit();
|
||||
g_exit(0);
|
||||
}
|
||||
if (g_file_write(fd, "0", 1) == -1)
|
||||
{
|
||||
g_writeln("running in daemon mode with no access to pid files, quitting");
|
||||
g_deinit();
|
||||
g_exit(0);
|
||||
}
|
||||
g_file_close(fd);
|
||||
@ -371,12 +378,14 @@ main(int argc, char** argv)
|
||||
if (pid == -1)
|
||||
{
|
||||
g_writeln("problem forking");
|
||||
g_deinit();
|
||||
g_exit(1);
|
||||
}
|
||||
if (0 != pid)
|
||||
{
|
||||
g_writeln("process %d started ok", pid);
|
||||
/* exit, this is the main process */
|
||||
g_deinit();
|
||||
g_exit(0);
|
||||
}
|
||||
g_sleep(1000);
|
||||
|
@ -59,6 +59,8 @@ name=freerdp-any
|
||||
lib=libxrdpfreerdp1.so
|
||||
ip=ask
|
||||
port=ask3389
|
||||
username=ask
|
||||
password=ask
|
||||
|
||||
[xrdp7]
|
||||
name=sesman-X11rdp
|
||||
|
@ -702,7 +702,7 @@ xrdp_mm_process_login_response(struct xrdp_mm* self, struct stream* s)
|
||||
{
|
||||
/* unix socket */
|
||||
self->chan_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);
|
||||
g_snprintf(port, 255, "/tmp/xrdp_chansrv_socket_%d", 7200 + display);
|
||||
g_snprintf(port, 255, "/tmp/.xrdp/xrdp_chansrv_socket_%d", 7200 + display);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user