added g_ to globals, added SIGINT, SIGKILL to shutdown signals, other minor changes

ulab-original
jsorg71 16 years ago
parent 12b2ea66fc
commit 23fe2e2259

@ -30,7 +30,7 @@
#include "sesman.h" #include "sesman.h"
extern int thread_sck; extern int g_thread_sck; /* in thread.c */
extern struct config_sesman g_cfg; extern struct config_sesman g_cfg;
/******************************************************************************/ /******************************************************************************/
@ -42,10 +42,10 @@ scp_process_start(void* sck)
/* making a local copy of the socket (it's on the stack) */ /* making a local copy of the socket (it's on the stack) */
/* probably this is just paranoia */ /* probably this is just paranoia */
scon.in_sck = thread_sck; scon.in_sck = g_thread_sck;
LOG_DBG(&(g_cfg.log), "started scp thread on socket %d", scon.in_sck); LOG_DBG(&(g_cfg.log), "started scp thread on socket %d", scon.in_sck);
/* unlocking thread_sck */ /* unlocking g_thread_sck */
lock_socket_release(); lock_socket_release();
make_stream(scon.in_s); make_stream(scon.in_s);

@ -32,7 +32,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; /* config.h */ struct config_sesman* g_cfg; /* config.h */
extern int thread_sck; extern int g_thread_sck; /* in thread.c */
/******************************************************************************/ /******************************************************************************/
/** /**
@ -66,7 +66,7 @@ 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(&(g_cfg->log), "new connection"); LOG_DBG(&(g_cfg->log), "new connection");
thread_sck=in_sck; g_thread_sck = in_sck;
//scp_process_start((void*)in_sck); //scp_process_start((void*)in_sck);
thread_scp_start(in_sck); thread_scp_start(in_sck);
@ -108,7 +108,8 @@ main(int argc, char** argv)
daemon = 1; daemon = 1;
} }
else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--nodaemon")) || else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--nodaemon")) ||
(0 == g_strcasecmp(argv[1], "-n")) ) ) (0 == g_strcasecmp(argv[1], "-n")) ||
(0 == g_strcasecmp(argv[1], "-ns"))))
{ {
/* starts sesman not daemonized */ /* starts sesman not daemonized */
g_printf("starting sesman in foregroud...\n"); g_printf("starting sesman in foregroud...\n");
@ -121,9 +122,9 @@ main(int argc, char** argv)
g_printf("sesman - xrdp session manager\n\n"); g_printf("sesman - xrdp session manager\n\n");
g_printf("usage: sesman [command]\n\n"); g_printf("usage: sesman [command]\n\n");
g_printf("command can be one of the following:\n"); g_printf("command can be one of the following:\n");
g_printf("-n, --nodaemon starts sesman in foregroun\n"); g_printf("-n, -ns, --nodaemon starts sesman in foreground\n");
g_printf("-k, --kill kills running sesman\n"); g_printf("-k, --kill kills running sesman\n");
g_printf("-h, --help shows this help\n"); g_printf("-h, --help shows this help\n");
g_printf("if no command is specified, sesman is started in background"); g_printf("if no command is specified, sesman is started in background");
g_exit(0); g_exit(0);
} }
@ -143,7 +144,7 @@ main(int argc, char** argv)
if (-1 == fd) if (-1 == fd)
{ {
g_printf("error opening pid file: %s\n", g_get_strerror()); g_printf("error opening pid file[%s]: %s\n", SESMAN_PID_FILE, g_get_strerror());
return 1; return 1;
} }
@ -212,7 +213,7 @@ main(int argc, char** argv)
g_printf("error on malloc. cannot start logging. quitting.\n"); g_printf("error on malloc. cannot start logging. quitting.\n");
break; break;
case LOG_ERROR_FILE_OPEN: case LOG_ERROR_FILE_OPEN:
g_printf("error opening log file. quitting.\n"); g_printf("error opening log file [%s]. quitting.\n", g_cfg->log.log_file);
break; break;
} }
g_exit(1); g_exit(1);
@ -257,21 +258,26 @@ main(int argc, char** argv)
*/ */
thread_sighandler_start(); thread_sighandler_start();
/* writing pid file */ if (daemon)
fd = g_file_open(SESMAN_PID_FILE);
if (-1 == fd)
{ {
log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "error opening pid file: %s", /* writing pid file */
g_get_strerror()); fd = g_file_open(SESMAN_PID_FILE);
log_end(&(g_cfg->log)); if (-1 == fd)
g_exit(1); {
log_message(&(g_cfg->log), LOG_LEVEL_ERROR,
"error opening pid file[%s]: %s",
SESMAN_PID_FILE, g_get_strerror());
log_end(&(g_cfg->log));
g_exit(1);
}
g_sprintf(pid_s, "%d", g_pid);
g_file_write(fd, pid_s, g_strlen(pid_s) + 1);
g_file_close(fd);
} }
g_sprintf(pid_s, "%d", g_pid);
g_file_write(fd, pid_s, g_strlen(pid_s) + 1);
g_file_close(fd);
/* start program main loop */ /* start program main loop */
log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "starting sesman with pid %d", g_pid); log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS,
"starting sesman with pid %d", g_pid);
/* make sure the /tmp/.X11-unix directory exist */ /* make sure the /tmp/.X11-unix directory exist */
if (!g_directory_exist("/tmp/.X11-unix")) if (!g_directory_exist("/tmp/.X11-unix"))

@ -123,6 +123,9 @@ sig_handler_thread(void* arg)
sigaddset(&waitmask, SIGHUP); sigaddset(&waitmask, SIGHUP);
sigaddset(&waitmask, SIGCHLD); sigaddset(&waitmask, SIGCHLD);
sigaddset(&waitmask, SIGTERM); sigaddset(&waitmask, SIGTERM);
sigaddset(&waitmask, SIGKILL);
sigaddset(&waitmask, SIGINT);
// sigaddset(&waitmask, SIGFPE); // sigaddset(&waitmask, SIGFPE);
// sigaddset(&waitmask, SIGILL); // sigaddset(&waitmask, SIGILL);
// sigaddset(&waitmask, SIGSEGV); // sigaddset(&waitmask, SIGSEGV);
@ -131,28 +134,32 @@ sig_handler_thread(void* arg)
{ {
LOG_DBG(&(g_cfg->log), "calling sigwait()",0); LOG_DBG(&(g_cfg->log), "calling sigwait()",0);
sigwait(&waitmask, &recv_signal); sigwait(&waitmask, &recv_signal);
switch (recv_signal) switch (recv_signal)
{ {
case SIGHUP: case SIGHUP:
//reload cfg //reload cfg
//we must stop & restart logging, or copy logging cfg!!!! //we must stop & restart logging, or copy logging cfg!!!!
LOG_DBG(&(g_cfg->log), "sesman received SIGHUP",0); LOG_DBG(&(g_cfg->log), "sesman received SIGHUP", 0);
//return 0; //return 0;
break; break;
case SIGCHLD: case SIGCHLD:
/* a session died */ /* a session died */
LOG_DBG(&(g_cfg->log), "sesman received SIGCHLD",0); LOG_DBG(&(g_cfg->log), "sesman received SIGCHLD", 0);
sig_sesman_session_end(SIGCHLD); sig_sesman_session_end(SIGCHLD);
break; break;
/*case SIGKILL; case SIGINT:
/ * we die * / /* we die */
LOG_DBG("sesman received SIGKILL",0); LOG_DBG(&(g_cfg->log), "sesman received SIGINT", 0);
sig_sesman_shutdown(recv_signal);
break;
case SIGKILL:
/* we die */
LOG_DBG(&(g_cfg->log), "sesman received SIGKILL", 0);
sig_sesman_shutdown(recv_signal); sig_sesman_shutdown(recv_signal);
break;*/ break;
case SIGTERM: case SIGTERM:
/* we die */ /* we die */
LOG_DBG(&(g_cfg->log), "sesman received SIGTERM",0); LOG_DBG(&(g_cfg->log), "sesman received SIGTERM", 0);
sig_sesman_shutdown(recv_signal); sig_sesman_shutdown(recv_signal);
break; break;
} }
@ -160,4 +167,3 @@ sig_handler_thread(void* arg)
return 0; return 0;
} }

@ -33,11 +33,11 @@
extern struct config_sesman g_cfg; extern struct config_sesman g_cfg;
static pthread_t thread_sighandler; static pthread_t g_thread_sighandler;
//static pthread_t thread_updater; //static pthread_t g_thread_updater;
/* a variable to pass the socket of s connection to a thread */ /* a variable to pass the socket of s connection to a thread */
int thread_sck; int g_thread_sck;
/******************************************************************************/ /******************************************************************************/
int DEFAULT_CC int DEFAULT_CC
@ -64,8 +64,8 @@ thread_sighandler_start(void)
log_message(&(g_cfg.log), LOG_LEVEL_INFO,"starting signal handling thread..."); log_message(&(g_cfg.log), LOG_LEVEL_INFO,"starting signal handling thread...");
ret = pthread_create(&thread_sighandler, NULL, sig_handler_thread, ""); ret = pthread_create(&g_thread_sighandler, NULL, sig_handler_thread, "");
pthread_detach(thread_sighandler); pthread_detach(g_thread_sighandler);
if (ret == 0) if (ret == 0)
{ {
@ -103,8 +103,8 @@ thread_session_update_start(void)
#warning this thread should always request lock_fork before read or write #warning this thread should always request lock_fork before read or write
#warning (so we can Fork() In Peace) #warning (so we can Fork() In Peace)
ret = pthread_create(&thread_updater, NULL, , ""); ret = pthread_create(&g_thread_updater, NULL, , "");
pthread_detach(thread_updater); pthread_detach(g_thread_updater);
if (ret==0) if (ret==0)
{ {
@ -141,11 +141,11 @@ thread_scp_start(int skt)
/* blocking the use of thread_skt */ /* blocking the use of thread_skt */
lock_socket_acquire(); lock_socket_acquire();
thread_sck=skt; g_thread_sck = skt;
/* start a thread that processes a connection */ /* start a thread that processes a connection */
ret = pthread_create(&th, NULL, scp_process_start, ""); ret = pthread_create(&th, NULL, scp_process_start, "");
//ret = pthread_create(&th, NULL, scp_process_start, (void*) (&thread_sck)); //ret = pthread_create(&th, NULL, scp_process_start, (void*) (&g_thread_sck));
pthread_detach(th); pthread_detach(th);
if (ret == 0) if (ret == 0)

Loading…
Cancel
Save