sesman: remove the thread

ulab-next-nosound
Jay Sorg 9 years ago
parent 4f128c530c
commit 4e0d0f3ba0

@ -1,4 +1,6 @@
EXTRA_DIST = sesman.ini startwm.sh sesman.h access.h auth.h config.h env.h lock.h scp.h scp_v0.h scp_v1.h scp_v1_mng.h session.h sig.h thread.h
EXTRA_DIST = sesman.ini startwm.sh sesman.h access.h auth.h config.h env.h \
scp.h scp_v0.h scp_v1.h scp_v1_mng.h session.h sig.h
AM_CFLAGS = \ AM_CFLAGS = \
-DXRDP_CFG_PATH=\"${sysconfdir}/xrdp\" \ -DXRDP_CFG_PATH=\"${sysconfdir}/xrdp\" \
@ -44,8 +46,6 @@ xrdp_sesman_SOURCES = \
sesman.c \ sesman.c \
session.c \ session.c \
sig.c \ sig.c \
thread.c \
lock.c \
access.c \ access.c \
config.c \ config.c \
env.c \ env.c \

@ -1,7 +1,7 @@
/** /**
* xrdp: A Remote Desktop Protocol server. * xrdp: A Remote Desktop Protocol server.
* *
* Copyright (C) Jay Sorg 2004-2013 * Copyright (C) Jay Sorg 2004-2015
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,121 +0,0 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2013
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* session manager
* linux only
*/
#include "sesman.h"
extern struct config_sesman *g_cfg; /* in sesman.c */
static tbus g_sync_mutex = 0;
static tbus g_lock_chain = 0;
static tbus g_sync_sem = 0;
static tbus g_lock_socket = 0;
/******************************************************************************/
void APP_CC
lock_init(void)
{
g_sync_mutex = tc_mutex_create();
g_lock_chain = tc_mutex_create();
g_sync_sem = tc_sem_create(0);
g_lock_socket = tc_sem_create(1);
}
/******************************************************************************/
void APP_CC
lock_deinit(void)
{
tc_mutex_delete(g_sync_mutex);
tc_mutex_delete(g_lock_chain);
tc_sem_delete(g_sync_sem);
tc_sem_delete(g_lock_socket);
}
/******************************************************************************/
void APP_CC
lock_chain_acquire(void)
{
/* lock the chain */
LOG_DBG("lock_chain_acquire()");
tc_mutex_lock(g_lock_chain);
}
/******************************************************************************/
void APP_CC
lock_chain_release(void)
{
/* unlock the chain */
LOG_DBG("lock_chain_release()");
tc_mutex_unlock(g_lock_chain);
}
/******************************************************************************/
void APP_CC
lock_socket_acquire(void)
{
/* lock socket variable */
LOG_DBG("lock_socket_acquire()");
tc_sem_dec(g_lock_socket);
}
/******************************************************************************/
void APP_CC
lock_socket_release(void)
{
/* unlock socket variable */
LOG_DBG("lock_socket_release()");
tc_sem_inc(g_lock_socket);
}
/******************************************************************************/
void APP_CC
lock_sync_acquire(void)
{
/* lock sync variable */
LOG_DBG("lock_sync_acquire()");
tc_mutex_lock(g_sync_mutex);
}
/******************************************************************************/
void APP_CC
lock_sync_release(void)
{
/* unlock socket variable */
LOG_DBG("lock_sync_release()");
tc_mutex_unlock(g_sync_mutex);
}
/******************************************************************************/
void APP_CC
lock_sync_sem_acquire(void)
{
/* dec sem */
LOG_DBG("lock_sync_sem_acquire()");
tc_sem_dec(g_sync_sem);
}
/******************************************************************************/
void APP_CC
lock_sync_sem_release(void)
{
/* inc sem */
LOG_DBG("lock_sync_sem_release()");
tc_sem_inc(g_sync_sem);
}

@ -1,104 +0,0 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2013
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LOCK_H
#define LOCK_H
#include "sesman.h"
/**
*
* @brief initializes all the locks
*
*/
void APP_CC
lock_init(void);
/**
*
* @brief cleanup all the locks
*
*/
void APP_CC
lock_deinit(void);
/**
*
* @brief acquires the lock for the session chain
*
*/
void APP_CC
lock_chain_acquire(void);
/**
*
* @brief releases the session chain lock
*
*/
void APP_CC
lock_chain_release(void);
/**
*
* @brief request the socket lock
*
*/
void APP_CC
lock_socket_acquire(void);
/**
*
* @brief releases the socket lock
*
*/
void APP_CC
lock_socket_release(void);
/**
*
* @brief request the main sync lock
*
*/
void APP_CC
lock_sync_acquire(void);
/**
*
* @brief releases the main sync lock
*
*/
void APP_CC
lock_sync_release(void);
/**
*
* @brief request the sync sem lock
*
*/
void APP_CC
lock_sync_sem_acquire(void);
/**
*
* @brief releases the sync sem lock
*
*/
void APP_CC
lock_sync_sem_release(void);
#endif

@ -1,7 +1,7 @@
/** /**
* xrdp: A Remote Desktop Protocol server. * xrdp: A Remote Desktop Protocol server.
* *
* Copyright (C) Jay Sorg 2004-2013 * Copyright (C) Jay Sorg 2004-2015
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,7 +29,6 @@
#include "sesman.h" #include "sesman.h"
extern int g_thread_sck; /* in thread.c */
extern struct config_sesman *g_cfg; /* in sesman.c */ extern struct config_sesman *g_cfg; /* in sesman.c */
/******************************************************************************/ /******************************************************************************/
@ -39,14 +38,9 @@ scp_process_start(void *sck)
struct SCP_CONNECTION scon; struct SCP_CONNECTION scon;
struct SCP_SESSION *sdata; struct SCP_SESSION *sdata;
/* making a local copy of the socket (it's on the stack) */ scon.in_sck = (int)(tintptr)sck;
/* probably this is just paranoia */
scon.in_sck = g_thread_sck;
LOG_DBG("started scp thread on socket %d", scon.in_sck); LOG_DBG("started scp thread on socket %d", scon.in_sck);
/* unlocking g_thread_sck */
lock_socket_release();
make_stream(scon.in_s); make_stream(scon.in_s);
make_stream(scon.out_s); make_stream(scon.out_s);

@ -35,9 +35,9 @@ scp_v0_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
int display = 0; int display = 0;
tbus data; tbus data;
struct session_item *s_item; struct session_item *s_item;
int errorcode = 0 ; int errorcode = 0;
data = auth_userpass(s->username, s->password,&errorcode); data = auth_userpass(s->username, s->password, &errorcode);
if (s->type == SCP_GW_AUTHENTICATION) if (s->type == SCP_GW_AUTHENTICATION)
{ {

@ -1,7 +1,7 @@
/** /**
* xrdp: A Remote Desktop Protocol server. * xrdp: A Remote Desktop Protocol server.
* *
* Copyright (C) Jay Sorg 2004-2013 * Copyright (C) Jay Sorg 2004-2015
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,7 +1,7 @@
/** /**
* xrdp: A Remote Desktop Protocol server. * xrdp: A Remote Desktop Protocol server.
* *
* Copyright (C) Jay Sorg 2004-2013 * Copyright (C) Jay Sorg 2004-2015
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,10 +31,7 @@ int g_pid;
unsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 }; unsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 };
struct config_sesman *g_cfg; /* defined in config.h */ struct config_sesman *g_cfg; /* defined in config.h */
tbus g_term_event = 0; tintptr g_term_event = 0;
tbus g_sync_event = 0;
extern int g_thread_sck; /* in thread.c */
/******************************************************************************/ /******************************************************************************/
/** /**
@ -49,6 +46,7 @@ sesman_main_loop(void)
int error; int error;
int robjs_count; int robjs_count;
int cont; int cont;
int pid;
tbus sck_obj; tbus sck_obj;
tbus robjs[8]; tbus robjs[8];
@ -80,7 +78,6 @@ sesman_main_loop(void)
robjs_count = 0; robjs_count = 0;
robjs[robjs_count++] = sck_obj; robjs[robjs_count++] = sck_obj;
robjs[robjs_count++] = g_term_event; robjs[robjs_count++] = g_term_event;
robjs[robjs_count++] = g_sync_event;
/* wait */ /* wait */
if (g_obj_wait(robjs, robjs_count, 0, 0, -1) != 0) if (g_obj_wait(robjs, robjs_count, 0, 0, -1) != 0)
@ -94,12 +91,6 @@ sesman_main_loop(void)
break; break;
} }
if (g_is_wait_obj_set(g_sync_event)) /* sync */
{
g_reset_wait_obj(g_sync_event);
session_sync_start();
}
if (g_is_wait_obj_set(sck_obj)) /* incoming connection */ if (g_is_wait_obj_set(sck_obj)) /* incoming connection */
{ {
in_sck = g_tcp_accept(g_sck); in_sck = g_tcp_accept(g_sck);
@ -118,8 +109,8 @@ sesman_main_loop(void)
{ {
/* we've got a connection, so we pass it to scp code */ /* we've got a connection, so we pass it to scp code */
LOG_DBG("new connection"); LOG_DBG("new connection");
thread_scp_start(in_sck); scp_process_start((void*)(tintptr)in_sck);
/* todo, do we have to wait here ? */ g_sck_close(in_sck);
} }
} }
} }
@ -138,9 +129,7 @@ sesman_main_loop(void)
"port '%s': %d (%s)", g_cfg->listen_port, "port '%s': %d (%s)", g_cfg->listen_port,
g_get_errno(), g_get_strerror()); g_get_errno(), g_get_strerror());
} }
g_tcp_close(g_sck);
if (g_sck != -1)
g_tcp_close(g_sck);
} }
/******************************************************************************/ /******************************************************************************/
@ -292,6 +281,9 @@ main(int argc, char **argv)
g_writeln("error opening log file [%s]. quitting.", g_writeln("error opening log file [%s]. quitting.",
getLogFile(text, 255)); getLogFile(text, 255));
break; break;
default:
g_writeln("error");
break;
} }
g_deinit(); g_deinit();
@ -329,9 +321,6 @@ main(int argc, char **argv)
} }
} }
/* initializing locks */
lock_init();
/* signal handling */ /* signal handling */
g_pid = g_getpid(); g_pid = g_getpid();
/* old style signal handling is now managed synchronously by a /* old style signal handling is now managed synchronously by a
@ -387,8 +376,6 @@ main(int argc, char **argv)
g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_term", g_pid); g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_term", g_pid);
g_term_event = g_create_wait_obj(text); g_term_event = g_create_wait_obj(text);
g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_sync", g_pid);
g_sync_event = g_create_wait_obj(text);
sesman_main_loop(); sesman_main_loop();
@ -399,7 +386,6 @@ main(int argc, char **argv)
} }
g_delete_wait_obj(g_term_event); g_delete_wait_obj(g_term_event);
g_delete_wait_obj(g_sync_event);
if (!daemon) if (!daemon)
{ {

@ -42,9 +42,6 @@
#include "session.h" #include "session.h"
#include "access.h" #include "access.h"
#include "scp.h" #include "scp.h"
#include "thread.h"
#include "lock.h"
#include "thread_calls.h"
#include "libscp.h" #include "libscp.h"

@ -1,7 +1,7 @@
/** /**
* xrdp: A Remote Desktop Protocol server. * xrdp: A Remote Desktop Protocol server.
* *
* Copyright (C) Jay Sorg 2004-2013 * Copyright (C) Jay Sorg 2004-2015
* *
* BSD process grouping by: * BSD process grouping by:
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland. * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland.
@ -32,33 +32,13 @@
#include "sesman.h" #include "sesman.h"
#include "libscp_types.h" #include "libscp_types.h"
#include <errno.h>
//#include <time.h>
extern tbus g_sync_event;
extern unsigned char g_fixedkey[8]; extern unsigned char g_fixedkey[8];
extern struct config_sesman *g_cfg; /* in sesman.c */ extern struct config_sesman *g_cfg; /* in sesman.c */
extern int g_sck; /* in sesman.c */ extern int g_sck; /* in sesman.c */
extern int g_thread_sck; /* in thread.c */
struct session_chain *g_sessions; struct session_chain *g_sessions;
int g_session_count; int g_session_count;
extern tbus g_term_event; /* in sesman.c */ extern tbus g_term_event; /* in sesman.c */
extern tbus g_sync_event; /* in sesman.c */
static int g_sync_width;
static int g_sync_height;
static int g_sync_bpp;
static char *g_sync_username;
static char *g_sync_password;
static char *g_sync_domain;
static char *g_sync_program;
static char *g_sync_directory;
static char *g_sync_client_ip;
static tbus g_sync_data;
static tui8 g_sync_type;
static int g_sync_result;
static int g_sync_cmd;
/** /**
* Creates a string consisting of all parameters that is hosted in the param list * Creates a string consisting of all parameters that is hosted in the param list
@ -71,7 +51,6 @@ char *APP_CC
dumpItemsToString(struct list *self, char *outstr, int len) dumpItemsToString(struct list *self, char *outstr, int len)
{ {
int index; int index;
tbus item;
int totalLen = 0; int totalLen = 0;
g_memset(outstr, 0, len); g_memset(outstr, 0, len);
@ -103,9 +82,6 @@ session_get_bydata(char *name, int width, int height, int bpp, int type, char *c
struct session_chain *tmp; struct session_chain *tmp;
enum SESMAN_CFG_SESS_POLICY policy = g_cfg->sess.policy; enum SESMAN_CFG_SESS_POLICY policy = g_cfg->sess.policy;
/*THREAD-FIX require chain lock */
lock_chain_acquire();
tmp = g_sessions; tmp = g_sessions;
/* convert from SCP_SESSION_TYPE namespace to SESMAN_SESSION_TYPE namespace */ /* convert from SCP_SESSION_TYPE namespace to SESMAN_SESSION_TYPE namespace */
@ -122,7 +98,6 @@ session_get_bydata(char *name, int width, int height, int bpp, int type, char *c
type = SESMAN_SESSION_TYPE_XORG; type = SESMAN_SESSION_TYPE_XORG;
break; break;
default: default:
lock_chain_release();
return 0; return 0;
} }
@ -154,16 +129,12 @@ session_get_bydata(char *name, int width, int height, int bpp, int type, char *c
tmp->item->bpp == bpp && tmp->item->bpp == bpp &&
tmp->item->type == type) tmp->item->type == type)
{ {
/*THREAD-FIX release chain lock */
lock_chain_release();
return tmp->item; return tmp->item;
} }
tmp = tmp->next; tmp = tmp->next;
} }
/*THREAD-FIX release chain lock */
lock_chain_release();
return 0; return 0;
} }
@ -267,7 +238,6 @@ x_server_running(int display)
{ {
char text[256]; char text[256];
int x_running; int x_running;
int sck;
g_sprintf(text, "/tmp/.X11-unix/X%d", display); g_sprintf(text, "/tmp/.X11-unix/X%d", display);
x_running = g_file_exist(text); x_running = g_file_exist(text);
@ -309,9 +279,9 @@ session_start_sessvc(int xpid, int wmpid, long data, char *username, int display
/* building parameters */ /* building parameters */
g_snprintf(exe_path, 261, "%s/xrdp-sessvc", XRDP_SBIN_PATH); g_snprintf(exe_path, 261, "%s/xrdp-sessvc", XRDP_SBIN_PATH);
list_add_item(sessvc_params, (long)g_strdup(exe_path)); list_add_item(sessvc_params, (tintptr)g_strdup(exe_path));
list_add_item(sessvc_params, (long)g_strdup(xpid_str)); list_add_item(sessvc_params, (tintptr)g_strdup(xpid_str));
list_add_item(sessvc_params, (long)g_strdup(wmpid_str)); list_add_item(sessvc_params, (tintptr)g_strdup(wmpid_str));
list_add_item(sessvc_params, 0); /* mandatory */ list_add_item(sessvc_params, 0); /* mandatory */
env_set_user(username, 0, display, env_set_user(username, 0, display,
@ -329,7 +299,7 @@ session_start_sessvc(int xpid, int wmpid, long data, char *username, int display
/* no problem calling strerror for thread safety: other threads /* no problem calling strerror for thread safety: other threads
are blocked */ are blocked */
log_message(LOG_LEVEL_DEBUG, "errno: %d, description: %s", log_message(LOG_LEVEL_DEBUG, "errno: %d, description: %s",
errno, g_get_strerror()); g_get_errno(), g_get_strerror());
log_message(LOG_LEVEL_DEBUG, "execve parameter list:"); log_message(LOG_LEVEL_DEBUG, "execve parameter list:");
for (i = 0; i < (sessvc_params->count); i++) for (i = 0; i < (sessvc_params->count); i++)
@ -383,7 +353,6 @@ session_get_aval_display_from_chain(void)
int display; int display;
display = g_cfg->sess.x11_display_offset; display = g_cfg->sess.x11_display_offset;
lock_chain_acquire();
while ((display - g_cfg->sess.x11_display_offset) <= g_cfg->sess.max_sessions) while ((display - g_cfg->sess.x11_display_offset) <= g_cfg->sess.max_sessions)
{ {
@ -391,7 +360,6 @@ session_get_aval_display_from_chain(void)
{ {
if (!x_server_running_check_ports(display)) if (!x_server_running_check_ports(display))
{ {
lock_chain_release();
return display; return display;
} }
} }
@ -399,7 +367,6 @@ session_get_aval_display_from_chain(void)
display++; display++;
} }
lock_chain_release();
log_message(LOG_LEVEL_ERROR, "X server -- no display in range is available"); log_message(LOG_LEVEL_ERROR, "X server -- no display in range is available");
return 0; return 0;
} }
@ -503,17 +470,16 @@ session_start_fork(int width, int height, int bpp, char *username,
return 0; return 0;
} }
pid = g_fork(); pid = g_fork(); /* parent is fork from tcp accpet,
child forks X and wm, then becomes scp */
if (pid == -1) if (pid == -1)
{ {
} }
else if (pid == 0) /* child sesman */ else if (pid == 0)
{ {
g_tcp_close(g_term_event); g_tcp_close(g_term_event);
g_tcp_close(g_sync_event);
g_tcp_close(g_sck); g_tcp_close(g_sck);
g_tcp_close(g_thread_sck);
g_sprintf(geometry, "%dx%d", width, height); g_sprintf(geometry, "%dx%d", width, height);
g_sprintf(depth, "%d", bpp); g_sprintf(depth, "%d", bpp);
g_sprintf(screen, ":%d", display); g_sprintf(screen, ":%d", display);
@ -553,19 +519,21 @@ session_start_fork(int width, int height, int bpp, char *username,
g_waitpid(bsdsespid); g_waitpid(bsdsespid);
#endif #endif
wmpid = g_fork(); wmpid = g_fork(); /* parent becomes X,
child forks wm, and waits, todo */
if (wmpid == -1) if (wmpid == -1)
{ {
} }
else if (wmpid == 0) /* child (child sesman) xserver */ else if (wmpid == 0)
{ {
wait_for_xserver(display); wait_for_xserver(display);
auth_start_session(data, display); auth_start_session(data, display);
pampid = g_fork(); pampid = g_fork(); /* parent waits, todo
child becomes wm */
if (pampid == -1) if (pampid == -1)
{ {
} }
else if (pampid == 0) /* child: X11/client */ else if (pampid == 0)
{ {
env_set_user(username, 0, display, env_set_user(username, 0, display,
g_cfg->session_variables1, g_cfg->session_variables1,
@ -601,7 +569,7 @@ session_start_fork(int width, int height, int bpp, char *username,
"wm for user %s - pid %d", username, g_getpid()); "wm for user %s - pid %d", username, g_getpid());
/* logging parameters */ /* logging parameters */
log_message(LOG_LEVEL_DEBUG, "errno: %d, " log_message(LOG_LEVEL_DEBUG, "errno: %d, "
"description: %s", errno, g_get_strerror()); "description: %s", g_get_errno(), g_get_strerror());
log_message(LOG_LEVEL_DEBUG, "execlp3 parameter " log_message(LOG_LEVEL_DEBUG, "execlp3 parameter "
"list:"); "list:");
log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", log_message(LOG_LEVEL_DEBUG, " argv[0] = %s",
@ -619,7 +587,7 @@ session_start_fork(int width, int height, int bpp, char *username,
"wm for user %s - pid %d", username, g_getpid()); "wm for user %s - pid %d", username, g_getpid());
/* logging parameters */ /* logging parameters */
log_message(LOG_LEVEL_DEBUG, "errno: %d, description: " log_message(LOG_LEVEL_DEBUG, "errno: %d, description: "
"%s", errno, g_get_strerror()); "%s", g_get_errno(), g_get_strerror());
log_message(LOG_LEVEL_DEBUG, "execlp3 parameter list:"); log_message(LOG_LEVEL_DEBUG, "execlp3 parameter list:");
log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", log_message(LOG_LEVEL_DEBUG, " argv[0] = %s",
text); text);
@ -634,7 +602,7 @@ session_start_fork(int width, int height, int bpp, char *username,
"for user %s - pid %d", username, g_getpid()); "for user %s - pid %d", username, g_getpid());
/* logging parameters */ /* logging parameters */
log_message(LOG_LEVEL_DEBUG, "errno: %d, description: " log_message(LOG_LEVEL_DEBUG, "errno: %d, description: "
"%s", errno, g_get_strerror()); "%s", g_get_errno(), g_get_strerror());
} }
else else
{ {
@ -653,10 +621,10 @@ session_start_fork(int width, int height, int bpp, char *username,
g_exit(0); g_exit(0);
} }
} }
else /* parent (child sesman) */ else
{ {
xpid = g_fork(); xpid = g_fork(); /* parent becomes scp,
child becomes X */
if (xpid == -1) if (xpid == -1)
{ {
} }
@ -684,8 +652,8 @@ session_start_fork(int width, int height, int bpp, char *username,
xserver_params->auto_free = 1; xserver_params->auto_free = 1;
/* these are the must have parameters */ /* these are the must have parameters */
list_add_item(xserver_params, (long) g_strdup("Xorg")); list_add_item(xserver_params, (tintptr) g_strdup("Xorg"));
list_add_item(xserver_params, (long) g_strdup(screen)); list_add_item(xserver_params, (tintptr) g_strdup(screen));
/* additional parameters from sesman.ini file */ /* additional parameters from sesman.ini file */
list_append_list_strdup(g_cfg->xorg_params, xserver_params, 0); list_append_list_strdup(g_cfg->xorg_params, xserver_params, 0);
@ -714,14 +682,14 @@ session_start_fork(int width, int height, int bpp, char *username,
xserver_params->auto_free = 1; xserver_params->auto_free = 1;
/* these are the must have parameters */ /* these are the must have parameters */
list_add_item(xserver_params, (long)g_strdup("Xvnc")); list_add_item(xserver_params, (tintptr)g_strdup("Xvnc"));
list_add_item(xserver_params, (long)g_strdup(screen)); list_add_item(xserver_params, (tintptr)g_strdup(screen));
list_add_item(xserver_params, (long)g_strdup("-geometry")); list_add_item(xserver_params, (tintptr)g_strdup("-geometry"));
list_add_item(xserver_params, (long)g_strdup(geometry)); list_add_item(xserver_params, (tintptr)g_strdup(geometry));
list_add_item(xserver_params, (long)g_strdup("-depth")); list_add_item(xserver_params, (tintptr)g_strdup("-depth"));
list_add_item(xserver_params, (long)g_strdup(depth)); list_add_item(xserver_params, (tintptr)g_strdup(depth));
list_add_item(xserver_params, (long)g_strdup("-rfbauth")); list_add_item(xserver_params, (tintptr)g_strdup("-rfbauth"));
list_add_item(xserver_params, (long)g_strdup(passwd_file)); list_add_item(xserver_params, (tintptr)g_strdup(passwd_file));
/* additional parameters from sesman.ini file */ /* additional parameters from sesman.ini file */
//config_read_xserver_params(SESMAN_SESSION_TYPE_XVNC, //config_read_xserver_params(SESMAN_SESSION_TYPE_XVNC,
@ -740,12 +708,12 @@ session_start_fork(int width, int height, int bpp, char *username,
xserver_params->auto_free = 1; xserver_params->auto_free = 1;
/* these are the must have parameters */ /* these are the must have parameters */
list_add_item(xserver_params, (long)g_strdup("X11rdp")); list_add_item(xserver_params, (tintptr)g_strdup("X11rdp"));
list_add_item(xserver_params, (long)g_strdup(screen)); list_add_item(xserver_params, (tintptr)g_strdup(screen));
list_add_item(xserver_params, (long)g_strdup("-geometry")); list_add_item(xserver_params, (tintptr)g_strdup("-geometry"));
list_add_item(xserver_params, (long)g_strdup(geometry)); list_add_item(xserver_params, (tintptr)g_strdup(geometry));
list_add_item(xserver_params, (long)g_strdup("-depth")); list_add_item(xserver_params, (tintptr)g_strdup("-depth"));
list_add_item(xserver_params, (long)g_strdup(depth)); list_add_item(xserver_params, (tintptr)g_strdup(depth));
/* additional parameters from sesman.ini file */ /* additional parameters from sesman.ini file */
//config_read_xserver_params(SESMAN_SESSION_TYPE_XRDP, //config_read_xserver_params(SESMAN_SESSION_TYPE_XRDP,
@ -771,7 +739,7 @@ session_start_fork(int width, int height, int bpp, char *username,
/* logging parameters */ /* logging parameters */
log_message(LOG_LEVEL_DEBUG, "errno: %d, description: " log_message(LOG_LEVEL_DEBUG, "errno: %d, description: "
"%s", errno, g_get_strerror()); "%s", g_get_errno(), g_get_strerror());
log_message(LOG_LEVEL_DEBUG, "execve parameter list size: " log_message(LOG_LEVEL_DEBUG, "execve parameter list size: "
"%d", (xserver_params)->count); "%d", (xserver_params)->count);
@ -784,7 +752,7 @@ session_start_fork(int width, int height, int bpp, char *username,
list_delete(xserver_params); list_delete(xserver_params);
g_exit(1); g_exit(1);
} }
else /* parent (child sesman)*/ else
{ {
wait_for_xserver(display); wait_for_xserver(display);
g_snprintf(text, 255, "%d", display); g_snprintf(text, 255, "%d", display);
@ -796,7 +764,7 @@ session_start_fork(int width, int height, int bpp, char *username,
} }
} }
} }
else /* parent sesman process */ else
{ {
temp->item->pid = pid; temp->item->pid = pid;
temp->item->display = display; temp->item->display = display;
@ -820,16 +788,10 @@ session_start_fork(int width, int height, int bpp, char *username,
temp->item->type = type; temp->item->type = type;
temp->item->status = SESMAN_SESSION_STATUS_ACTIVE; temp->item->status = SESMAN_SESSION_STATUS_ACTIVE;
/*THREAD-FIX require chain lock */
lock_chain_acquire();
temp->next = g_sessions; temp->next = g_sessions;
g_sessions = temp; g_sessions = temp;
g_session_count++; g_session_count++;
/*THREAD-FIX release chain lock */
lock_chain_release();
return display; return display;
} }
@ -876,32 +838,9 @@ session_start(int width, int height, int bpp, char *username, char *password,
long data, tui8 type, char *domain, char *program, long data, tui8 type, char *domain, char *program,
char *directory, char *client_ip) char *directory, char *client_ip)
{ {
int display; return session_start_fork(width, height, bpp, username,
password, data, type, domain,
/* lock mutex */ program, directory, client_ip);
lock_sync_acquire();
/* set shared vars */
g_sync_cmd = 0;
g_sync_width = width;
g_sync_height = height;
g_sync_bpp = bpp;
g_sync_username = username;
g_sync_password = password;
g_sync_domain = domain;
g_sync_program = program;
g_sync_directory = directory;
g_sync_client_ip = client_ip;
g_sync_data = data;
g_sync_type = type;
/* set event for main thread to see */
g_set_wait_obj(g_sync_event);
/* wait for main thread to get done */
lock_sync_sem_acquire();
/* read result(display) from shared var */
display = g_sync_result;
/* unlock mutex */
lock_sync_release();
return display;
} }
/******************************************************************************/ /******************************************************************************/
@ -910,42 +849,7 @@ session_start(int width, int height, int bpp, char *username, char *password,
int DEFAULT_CC int DEFAULT_CC
session_reconnect(int display, char *username) session_reconnect(int display, char *username)
{ {
/* lock mutex */ return session_reconnect_fork(display, username);
lock_sync_acquire();
/* set shared vars */
g_sync_cmd = 1;
g_sync_width = display;
g_sync_username = username;
/* set event for main thread to see */
g_set_wait_obj(g_sync_event);
/* wait for main thread to get done */
lock_sync_sem_acquire();
/* unlock mutex */
lock_sync_release();
return 0;
}
/******************************************************************************/
/* called with the main thread */
int APP_CC
session_sync_start(void)
{
if (g_sync_cmd == 0)
{
g_sync_result = session_start_fork(g_sync_width, g_sync_height, g_sync_bpp,
g_sync_username, g_sync_password,
g_sync_data, g_sync_type, g_sync_domain,
g_sync_program, g_sync_directory,
g_sync_client_ip);
}
else
{
/* g_sync_width is really display */
g_sync_result = session_reconnect_fork(g_sync_width, g_sync_username);
}
lock_sync_sem_release();
return 0;
} }
/******************************************************************************/ /******************************************************************************/
@ -955,9 +859,6 @@ session_kill(int pid)
struct session_chain *tmp; struct session_chain *tmp;
struct session_chain *prev; struct session_chain *prev;
/*THREAD-FIX require chain lock */
lock_chain_acquire();
tmp = g_sessions; tmp = g_sessions;
prev = 0; prev = 0;
@ -979,8 +880,6 @@ session_kill(int pid)
prev->next = tmp->next; prev->next = tmp->next;
} }
/*THREAD-FIX release chain lock */
lock_chain_release();
return SESMAN_SESSION_KILL_NULLITEM; return SESMAN_SESSION_KILL_NULLITEM;
} }
@ -1003,8 +902,6 @@ session_kill(int pid)
g_free(tmp); g_free(tmp);
g_session_count--; g_session_count--;
/*THREAD-FIX release chain lock */
lock_chain_release();
return SESMAN_SESSION_KILL_OK; return SESMAN_SESSION_KILL_OK;
} }
@ -1013,8 +910,6 @@ session_kill(int pid)
tmp = tmp->next; tmp = tmp->next;
} }
/*THREAD-FIX release chain lock */
lock_chain_release();
return SESMAN_SESSION_KILL_NOTFOUND; return SESMAN_SESSION_KILL_NOTFOUND;
} }
@ -1024,9 +919,6 @@ session_sigkill_all()
{ {
struct session_chain *tmp; struct session_chain *tmp;
/*THREAD-FIX require chain lock */
lock_chain_acquire();
tmp = g_sessions; tmp = g_sessions;
while (tmp != 0) while (tmp != 0)
@ -1044,9 +936,6 @@ session_sigkill_all()
/* go on */ /* go on */
tmp = tmp->next; tmp = tmp->next;
} }
/*THREAD-FIX release chain lock */
lock_chain_release();
} }
/******************************************************************************/ /******************************************************************************/
@ -1064,9 +953,6 @@ session_get_bypid(int pid)
return 0; return 0;
} }
/*THREAD-FIX require chain lock */
lock_chain_acquire();
tmp = g_sessions; tmp = g_sessions;
while (tmp != 0) while (tmp != 0)
@ -1075,18 +961,13 @@ session_get_bypid(int pid)
{ {
log_message(LOG_LEVEL_ERROR, "session descriptor for " log_message(LOG_LEVEL_ERROR, "session descriptor for "
"pid %d is null!", pid); "pid %d is null!", pid);
/*THREAD-FIX release chain lock */
lock_chain_release();
g_free(dummy); g_free(dummy);
return 0; return 0;
} }
if (tmp->item->pid == pid) if (tmp->item->pid == pid)
{ {
/*THREAD-FIX release chain lock */
g_memcpy(dummy, tmp->item, sizeof(struct session_item)); g_memcpy(dummy, tmp->item, sizeof(struct session_item));
lock_chain_release();
/*return tmp->item;*/
return dummy; return dummy;
} }
@ -1094,8 +975,6 @@ session_get_bypid(int pid)
tmp = tmp->next; tmp = tmp->next;
} }
/*THREAD-FIX release chain lock */
lock_chain_release();
g_free(dummy); g_free(dummy);
return 0; return 0;
} }
@ -1111,9 +990,6 @@ session_get_byuser(char *user, int *cnt, unsigned char flags)
count = 0; count = 0;
/*THREAD-FIX require chain lock */
lock_chain_acquire();
tmp = g_sessions; tmp = g_sessions;
while (tmp != 0) while (tmp != 0)
@ -1139,8 +1015,6 @@ session_get_byuser(char *user, int *cnt, unsigned char flags)
if (count == 0) if (count == 0)
{ {
(*cnt) = 0; (*cnt) = 0;
/*THREAD-FIX release chain lock */
lock_chain_release();
return 0; return 0;
} }
@ -1150,8 +1024,6 @@ session_get_byuser(char *user, int *cnt, unsigned char flags)
if (sess == 0) if (sess == 0)
{ {
(*cnt) = 0; (*cnt) = 0;
/*THREAD-FIX release chain lock */
lock_chain_release();
return 0; return 0;
} }
@ -1160,7 +1032,7 @@ session_get_byuser(char *user, int *cnt, unsigned char flags)
while (tmp != 0) while (tmp != 0)
{ {
#warning FIXME: we should get only disconnected sessions! /* #warning FIXME: we should get only disconnected sessions! */
if ((NULL == user) || (!g_strncasecmp(user, tmp->item->name, 256))) if ((NULL == user) || (!g_strncasecmp(user, tmp->item->name, 256)))
{ {
if ((tmp->item->status) & flags) if ((tmp->item->status) & flags)
@ -1170,7 +1042,7 @@ session_get_byuser(char *user, int *cnt, unsigned char flags)
(sess[index]).height = tmp->item->height; (sess[index]).height = tmp->item->height;
(sess[index]).width = tmp->item->width; (sess[index]).width = tmp->item->width;
(sess[index]).bpp = tmp->item->bpp; (sess[index]).bpp = tmp->item->bpp;
#warning FIXME: setting idle times and such /* #warning FIXME: setting idle times and such */
/*(sess[index]).connect_time.year = tmp->item->connect_time.year; /*(sess[index]).connect_time.year = tmp->item->connect_time.year;
(sess[index]).connect_time.month = tmp->item->connect_time.month; (sess[index]).connect_time.month = tmp->item->connect_time.month;
(sess[index]).connect_time.day = tmp->item->connect_time.day; (sess[index]).connect_time.day = tmp->item->connect_time.day;
@ -1203,8 +1075,6 @@ session_get_byuser(char *user, int *cnt, unsigned char flags)
tmp = tmp->next; tmp = tmp->next;
} }
/*THREAD-FIX release chain lock */
lock_chain_release();
(*cnt) = count; (*cnt) = count;
return sess; return sess;
} }

@ -110,15 +110,6 @@ session_start(int width, int height, int bpp, char* username, char* password,
int DEFAULT_CC int DEFAULT_CC
session_reconnect(int display, char* username); session_reconnect(int display, char* username);
/**
*
* @brief starts a session
* @return error
*
*/
int APP_CC
session_sync_start(void);
/** /**
* *
* @brief kills a session * @brief kills a session

@ -1,173 +0,0 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2013
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
* @file thread.c
* @brief thread stuff...
* @author Simone Fedele
*
*/
#include "sesman.h"
#include <errno.h>
#include <signal.h>
#include <pthread.h>
extern struct config_sesman *g_cfg; /* in sesman.c */
static pthread_t g_thread_sighandler;
//static pthread_t g_thread_updater;
/* a variable to pass the socket of s connection to a thread */
int g_thread_sck;
/******************************************************************************/
int DEFAULT_CC
thread_sighandler_start(void)
{
int ret;
sigset_t sigmask;
sigset_t oldmask;
sigset_t waitmask;
/* mask signals to be able to wait for them... */
sigfillset(&sigmask);
pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask);
/* unblock some signals... */
sigemptyset(&waitmask);
/* it is a good idea not to block SIGILL SIGSEGV */
/* SIGFPE -- see sigaction(2) NOTES */
sigaddset(&waitmask, SIGILL);
sigaddset(&waitmask, SIGSEGV);
sigaddset(&waitmask, SIGFPE);
pthread_sigmask(SIG_UNBLOCK, &waitmask, NULL);
log_message(LOG_LEVEL_INFO, "starting signal handling thread...");
ret = pthread_create(&g_thread_sighandler, NULL, sig_handler_thread, "");
pthread_detach(g_thread_sighandler);
if (ret == 0)
{
log_message(LOG_LEVEL_INFO, "signal handler thread started successfully");
return 0;
}
/* if something happened while starting a new thread... */
switch (ret)
{
case EINVAL:
log_message(LOG_LEVEL_ERROR, "invalid attributes for signal handling thread (creation returned EINVAL)");
break;
case EAGAIN:
log_message(LOG_LEVEL_ERROR, "not enough resources to start signal handling thread (creation returned EAGAIN)");
break;
case EPERM:
log_message(LOG_LEVEL_ERROR, "invalid permissions for signal handling thread (creation returned EPERM)");
break;
default:
log_message(LOG_LEVEL_ERROR, "unknown error starting signal handling thread");
}
return 1;
}
#ifdef JUST_TO_AVOID_COMPILER_ERRORS
/******************************************************************************/
int DEFAULT_CC
thread_session_update_start(void)
{
int ret;
//starts the session update thread
//that checks for idle time, destroys sessions, ecc...
#warning this thread should always request lock_fork before read or write
#warning (so we can Fork() In Peace)
ret = pthread_create(&g_thread_updater, NULL, , "");
pthread_detach(g_thread_updater);
if (ret == 0)
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "session update thread started successfully");
return 0;
}
/* if something happened while starting a new thread... */
switch (ret)
{
case EINVAL:
log_message(LOG_LEVEL_ERROR, "invalid attributes for session update thread (creation returned EINVAL)");
break;
case EAGAIN:
log_message(LOG_LEVEL_ERROR, "not enough resources to start session update thread (creation returned EAGAIN)");
break;
case EPERM:
log_message(LOG_LEVEL_ERROR, "invalid permissions for session update thread (creation returned EPERM)");
break;
default:
log_message(LOG_LEVEL_ERROR, "unknown error starting session update thread");
}
return 1;
}
#endif
/******************************************************************************/
int DEFAULT_CC
thread_scp_start(int skt)
{
int ret;
pthread_t th;
/* blocking the use of thread_skt */
lock_socket_acquire();
g_thread_sck = skt;
/* start a thread that processes a connection */
ret = pthread_create(&th, NULL, scp_process_start, "");
//ret = pthread_create(&th, NULL, scp_process_start, (void*) (&g_thread_sck));
pthread_detach(th);
if (ret == 0)
{
log_message(LOG_LEVEL_INFO, "scp thread on sck %d started successfully", skt);
return 0;
}
/* if something happened while starting a new thread... */
switch (ret)
{
case EINVAL:
log_message(LOG_LEVEL_ERROR, "invalid attributes for scp thread on sck %d (creation returned EINVAL)", skt);
break;
case EAGAIN:
log_message(LOG_LEVEL_ERROR, "not enough resources to start scp thread on sck %d (creation returned EAGAIN)", skt);
break;
case EPERM:
log_message(LOG_LEVEL_ERROR, "invalid permissions for scp thread on sck %d (creation returned EPERM)", skt);
break;
default:
log_message(LOG_LEVEL_ERROR, "unknown error starting scp thread on sck %d");
}
return 1;
}

@ -1,56 +0,0 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2013
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
* @file thread.h
* @brief thread stuff...
* @author Simone Fedele
*
*/
#ifndef THREAD_H
#define THREAD_H
/**
*
* @brief Starts the signal handling thread
* @retval 0 on success
* @retval 1 on error
*
*/
int DEFAULT_CC
thread_sighandler_start(void);
/**
*
* @brief Starts the session update thread
*
*/
int DEFAULT_CC
thread_session_update_start(void);
/**
*
* @brief Starts a thread to handle an incoming connection
*
*/
int DEFAULT_CC
thread_scp_start(int skt);
#endif
Loading…
Cancel
Save