work on chansrv

ulab-original
jsorg71 16 years ago
parent da99343957
commit c6b9952fa2

@ -1697,6 +1697,13 @@ g_get_strerror(void)
#endif
}
/*****************************************************************************/
int APP_CC
g_get_errno(void)
{
return errno;
}
/*****************************************************************************/
/* does not work in win32 */
int APP_CC

@ -191,6 +191,8 @@ g_system(char* aexec);
char* APP_CC
g_get_strerror(void);
int APP_CC
g_get_errno(void);
int APP_CC
g_execvp(const char* p1, char* args[]);
int APP_CC
g_execlp3(const char* a1, const char* a2, const char* a3);

@ -173,6 +173,7 @@ process_message_channel_setup(struct stream* s)
g_writeln("xrdp-chansrv: in process_message_channel_setup");
in_uint16_le(s, num_chans);
g_writeln("xrdp-chansrv: num_chans %d", num_chans);
for (index = 0; index < num_chans; index++)
{
ci = &(g_chan_items[g_num_chan_items]);
@ -180,8 +181,8 @@ process_message_channel_setup(struct stream* s)
in_uint8a(s, ci->name, 8);
in_uint16_le(s, ci->id);
in_uint16_le(s, ci->flags);
g_writeln("xrdp-chansrv: chan name %s id %d flags %d", ci->name, ci->id,
ci->flags);
g_writeln("xrdp-chansrv: chan name %s id %d flags %8.8x",
ci->name, ci->id, ci->flags);
if (g_strcasecmp(ci->name, "cliprdr") == 0)
{
g_clip_index = g_num_chan_items;
@ -470,7 +471,7 @@ main(int argc, char** argv)
char* display_text;
pid = g_getpid();
g_writeln("xrdp-chansrv: started pid %d(0x%8.8x)", pid, pid);
g_writeln("xrdp-chansrv: app started pid %d(0x%8.8x)", pid, pid);
g_signal_kill(term_signal_handler); /* SIGKILL */
g_signal_terminate(term_signal_handler); /* SIGTERM */
g_signal_user_interrupt(term_signal_handler); /* SIGINT */
@ -490,9 +491,10 @@ main(int argc, char** argv)
g_writeln("xrdp-chansrv: error, display is zero");
return 1;
}
g_snprintf(text, 255, "xrdp_chansrv_term_%8.8x", pid);
g_writeln("xrdp-chansrv: using DISPLAY %d", g_display);
g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid);
g_term_event = g_create_wait_obj(text);
g_snprintf(text, 255, "xrdp_chansrv_thread_done_%8.8x", pid);
g_snprintf(text, 255, "xrdp_chansrv_%8.8x_thread_done", pid);
g_thread_done_event = g_create_wait_obj(text);
tc_thread_create(channel_thread_loop, 0);
if (g_obj_wait(&g_term_event, 1, 0, 0, 0) != 0)
@ -507,5 +509,6 @@ main(int argc, char** argv)
/* cleanup */
g_delete_wait_obj(g_term_event);
g_delete_wait_obj(g_thread_done_event);
g_writeln("xrdp-chansrv: app exiting pid %d(0x%8.8x)", pid, pid);
return 0;
}

@ -205,24 +205,24 @@ session_start_fork(int width, int height, int bpp, char* username,
/* check to limit concurrent sessions */
if (g_session_count >= g_cfg->sess.max_sessions)
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "max concurrent session limit exceeded. login \
for user %s denied", username);
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "max concurrent session limit "
"exceeded. login for user %s denied", username);
return 0;
}
temp = (struct session_chain*)g_malloc(sizeof(struct session_chain), 0);
if (temp == 0)
{
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "cannot create new chain element - user %s",
username);
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "cannot create new chain "
"element - user %s", username);
return 0;
}
temp->item = (struct session_item*)g_malloc(sizeof(struct session_item), 0);
if (temp->item == 0)
{
g_free(temp);
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "cannot create new session item - user %s",
username);
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "cannot create new session "
"item - user %s", username);
return 0;
}
@ -283,15 +283,17 @@ for user %s denied", username);
if (g_file_exist(text))
{
g_execlp3(text, g_cfg->user_wm, 0);
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting user wm for user %s - pid %d",
username, g_getpid());
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting user "
"wm for user %s - pid %d", username, g_getpid());
/* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno,
g_get_strerror());
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"execlp3 parameter list:");
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[0] = %s", text);
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg->user_wm);
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, "
"description: %s", errno, g_get_strerror());
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"execlp3 parameter "
"list:");
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[0] = %s",
text);
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[1] = %s",
g_cfg->user_wm);
}
}
/* if we're here something happened to g_execlp3
@ -299,29 +301,31 @@ for user %s denied", username);
g_sprintf(text, "%s/%s", XRDP_CFG_PATH, g_cfg->default_wm);
g_execlp3(text, g_cfg->default_wm, 0);
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting default wm for user %s - pid %d",
username, g_getpid());
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting default "
"wm for user %s - pid %d", username, g_getpid());
/* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno,
g_get_strerror());
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: "
"%s", errno, g_get_strerror());
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"execlp3 parameter list:");
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[0] = %s", text);
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg->default_wm);
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[0] = %s",
text);
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[1] = %s",
g_cfg->default_wm);
/* still a problem starting window manager just start xterm */
g_execlp3("xterm", "xterm", 0);
/* should not get here */
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting xterm for user %s - pid %d",
username, g_getpid());
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,"error starting xterm "
"for user %s - pid %d", username, g_getpid());
/* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror());
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: "
"%s", errno, g_get_strerror());
}
else
{
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "another Xserver is already active on display %d", display);
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "another Xserver is "
"already active on display %d", display);
}
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG,"aborting connection...");
g_exit(0);
@ -384,29 +388,35 @@ for user %s denied", username);
}
else
{
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "bad session type - user %s - pid %d",
username, g_getpid());
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "bad session type - "
"user %s - pid %d", username, g_getpid());
g_exit(1);
}
/* should not get here */
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "error starting X server - user %s - pid %d",
username, g_getpid());
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "error starting X server "
"- user %s - pid %d", username, g_getpid());
/* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror());
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "execve parameter list: %d", (xserver_params)->count);
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "errno: %d, description: "
"%s", errno, g_get_strerror());
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "execve parameter list: "
"%d", (xserver_params)->count);
for (i=0; i<(xserver_params->count); i++)
{
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[%d] = %s", i, (char*)list_get_item(xserver_params, i));
log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, " argv[%d] = %s",
i, (char*)list_get_item(xserver_params, i));
}
list_delete(xserver_params);
g_exit(1);
}
else /* parent (child sesman)*/
{
g_snprintf(text, 255, "%d", display);
g_setenv("XRDP_SESSVC_DISPLAY", text, 1);
g_snprintf(text, 255, ":%d.0", display);
g_setenv("DISPLAY", text, 1);
/* new style waiting for clients */
session_start_sessvc(xpid, wmpid, data);
}
@ -505,8 +515,8 @@ session_kill(int pid)
{
if (tmp->item == 0)
{
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "session descriptor for pid %d is null!",
pid);
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "session descriptor for "
"pid %d is null!", pid);
if (prev == 0)
{
/* prev does no exist, so it's the first element - so we set
@ -525,8 +535,8 @@ session_kill(int pid)
if (tmp->item->pid == pid)
{
/* deleting the session */
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "session %d - user %s - terminated",
tmp->item->pid, tmp->item->name);
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "session %d - user %s - "
"terminated", tmp->item->pid, tmp->item->name);
g_free(tmp->item);
if (prev == 0)
{
@ -570,7 +580,8 @@ session_sigkill_all()
{
if (tmp->item == 0)
{
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "found null session descriptor!");
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "found null session "
"descriptor!");
}
else
{
@ -607,8 +618,8 @@ session_get_bypid(int pid)
{
if (tmp->item == 0)
{
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "session descriptor for pid %d is null!",
pid);
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "session descriptor for "
"pid %d is null!", pid);
/*THREAD-FIX release chain lock */
lock_chain_release();
return 0;
@ -652,7 +663,9 @@ session_get_byuser(char* user, int* cnt, unsigned char flags)
LOG_DBG(&(g_cfg->log), "user: %s", user);
if ((NULL == user) || (!g_strncasecmp(user, tmp->item->name, 256)))
{
LOG_DBG(&(g_cfg->log), "session_get_byuser: status=%d, flags=%d, result=%d", (tmp->item->status), flags, ((tmp->item->status) & flags));
LOG_DBG(&(g_cfg->log), "session_get_byuser: status=%d, flags=%d, "
"result=%d", (tmp->item->status), flags,
((tmp->item->status) & flags));
if ((tmp->item->status) & flags)
{
count++;
@ -733,4 +746,3 @@ session_get_byuser(char* user, int* cnt, unsigned char flags)
(*cnt)=count;
return sess;
}

@ -14,7 +14,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2005-2008
Copyright (C) Jay Sorg 2005-2009
*/
/**
@ -25,43 +25,53 @@
*
*/
#if defined(HAVE_CONFIG_H)
#include "config_ac.h"
#endif
#include "file_loc.h"
#include "os_calls.h"
#include "arch.h"
#include "log.h"
#include <sys/types.h>
#include <errno.h>
pid_t wm_pid;
pid_t x_pid;
void DEFAULT_CC
signal_handler(int sig)
{
g_sigterm(x_pid);
g_sigterm(wm_pid);
g_exit(0);
}
/******************************************************************************/
int DEFAULT_CC
main(int argc, char** argv)
{
int ret=0;
int ret;
int chansrv_pid;
int wm_pid;
int x_pid;
char exe_path[262];
if (argc < 3)
{
g_writeln("xrdp-sessvc: exiting, not enough params");
return 1;
}
x_pid = g_atoi(argv[1]);
wm_pid = g_atoi(argv[2]);
g_printf("\n[sessvc] Setting signal handler\n");
g_signal(9, signal_handler); /* SIGKILL */
g_signal(15, signal_handler); /* SIGTERM */
g_signal(17, signal_handler); /* SIGCHLD */
g_printf("\n[sessvc] Waiting for X (pid %d) and WM (pid %d)\n", x_pid, wm_pid);
g_writeln("xrdp-sessvc: waiting for X (pid %d) and WM (pid %d)",
x_pid, wm_pid);
/* run xrdp-chansrv as a seperate process */
chansrv_pid = g_fork();
if (chansrv_pid == -1)
{
g_writeln("xrdp-sessvc: fork error");
return 1;
}
else if (chansrv_pid == 0) /* child */
{
g_snprintf(exe_path, 261, "%s/xrdp-chansrv", XRDP_SBIN_PATH);
g_execvp(exe_path, 0);
/* should not get here */
return 1;
}
/* wait for window manager to get done */
ret = g_waitpid(wm_pid);
/* kill X server */
g_sigterm(x_pid);
g_printf("\n[sessvc] WM is dead (waitpid said %d, errno is %d). exiting...\n", ret, errno);
/* kill channel server */
g_sigterm(chansrv_pid);
g_writeln("xrdp-sessvc: WM is dead (waitpid said %d, errno is %d) "
"exiting...", ret, g_get_errno());
return 0;
}

Loading…
Cancel
Save