summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorilsimo <ilsimo>2005-11-13 22:06:49 +0000
committerilsimo <ilsimo>2005-11-13 22:06:49 +0000
commit9ac351a4cb72ad1ceaf8c57cc05dfc9067145ca0 (patch)
tree3c5a0a665b3c760ea0f1500fc49f88a0fc1dd206
parent3cdf8bdcee7d1ccbe270f919e416478ba1ca88d2 (diff)
downloadxrdp-proprietary-9ac351a4cb72ad1ceaf8c57cc05dfc9067145ca0.tar.gz
xrdp-proprietary-9ac351a4cb72ad1ceaf8c57cc05dfc9067145ca0.zip
added --nodaemon and --kill options
added pid file generation improved some code documentation
-rw-r--r--sesman/config.h42
-rw-r--r--sesman/env.c11
-rw-r--r--sesman/env.h34
-rw-r--r--sesman/sesman.c193
-rw-r--r--sesman/sig.c23
-rw-r--r--sesman/sig.h27
-rw-r--r--sesman/tcp.c11
-rw-r--r--sesman/tcp.h27
8 files changed, 267 insertions, 101 deletions
diff --git a/sesman/config.h b/sesman/config.h
index af7b798f..0feba75d 100644
--- a/sesman/config.h
+++ b/sesman/config.h
@@ -26,6 +26,12 @@
#include "list.h"
#include "log.h"
+/**
+ *
+ * @def SESMAN_CFG_FILE
+ * @brief Configuration file path
+ *
+ */
#define SESMAN_CFG_FILE "./sesman.ini"
#define SESMAN_CFG_GLOBALS "Globals"
@@ -40,18 +46,48 @@
#define SESMAN_CFG_LOG_ENABLE_SYSLOG "EnableSyslog"
#define SESMAN_CFG_LOG_SYSLOG_LEVEL "SyslogLevel"
+/**
+ *
+ * @struct config_sesman
+ * @brief \t struct that contains \t sesman configuration
+ *
+ * This \t struct contains all of \t sesman configuration parameters\n
+ * Every parameter in \t [globals] is a member of this struct, other
+ * sections options are embedded in this \t struct as member structures
+ *
+ */
struct config_sesman
{
+ /**
+ * @var listen_port
+ * @brief Listening port
+ */
char listen_port[16];
+ /**
+ * @var enable_user_wm
+ * @brief Flag that enables user specific wm
+ */
int enable_user_wm;
+ /**
+ * @var default_wm
+ * @brief Default window manager
+ */
char default_wm[32];
+ /**
+ * @var user_wm
+ * @brief Default window manager
+ */
char user_wm[32];
+ /**
+ * @var log
+ * @brief Log configuration \t struct
+ */
struct log_config log;
};
/**
*
- * Reads sesman configuration
+ * @brief Reads sesman configuration
*
* @param cfg pointer to configuration object to be replaced
*
@@ -63,7 +99,7 @@ config_read(struct config_sesman* cfg);
/**
*
- * Reads sesman configuration
+ * @brief Reads sesman [global] configuration section
*
* @param cfg pointer to configuration object to be replaced
*
@@ -75,7 +111,7 @@ config_read_globals(int file, struct config_sesman* cf, struct list* param_n, st
/**
*
- * Reads sesman configuration
+ * @brief Reads sesman [logging] configuration section
*
* @param cfg pointer to configuration object to be replaced
*
diff --git a/sesman/env.c b/sesman/env.c
index 1049d6a5..453591a6 100644
--- a/sesman/env.c
+++ b/sesman/env.c
@@ -18,11 +18,16 @@
session manager
linux only
-
- enc.c: user environment handling code
-
*/
+/**
+ *
+ * @file env.c
+ * @brief User environment handling code
+ * @author Jay Sorg
+ *
+ */
+
#include "sesman.h"
extern unsigned char g_fixedkey[8];
diff --git a/sesman/env.h b/sesman/env.h
index d53045c7..be8c0a4e 100644
--- a/sesman/env.h
+++ b/sesman/env.h
@@ -18,19 +18,43 @@
session manager
linux only
-
- env.h: user environment handling code declarations
-
*/
+/**
+ *
+ * @file env.h
+ * @brief User environment handling code declarations
+ * @author Jay Sorg
+ *
+ */
+
#ifndef ENV_H
#define ENV_H
-/******************************************************************************/
+/**
+ *
+ * @brief Creates vnc password file
+ *
+ * @param filename VNC password file name
+ * @param password The password to be encrypte
+ *
+ * @return 0 on success, 1 on error
+ *
+ */
int DEFAULT_CC
env_check_password_file(char* filename, char* password);
-/******************************************************************************/
+/**
+ *
+ * @brief Sets user environment ($PATH, $HOME, $UID, and others)
+ *
+ * @param username Username
+ * @param passwd_file VNC password file
+ * @param display The session display
+ *
+ * @return 0 on success, g_getuser_info() error codes on error
+ *
+ */
int DEFAULT_CC
env_set_user(char* username, char* passwd_file, int display);
diff --git a/sesman/sesman.c b/sesman/sesman.c
index e6bcf295..f1648116 100644
--- a/sesman/sesman.c
+++ b/sesman/sesman.c
@@ -22,7 +22,14 @@
*/
#include "sesman.h"
+
#include <stdio.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <string.h>
+#include <errno.h>
+
+#define SESMAN_PID_FILE "/usr/local/xrdp/sesman.pid"
int g_sck;
int g_pid;
@@ -54,9 +61,14 @@ cterm(int s)
}
}
-/******************************************************************************/
-int DEFAULT_CC
-main(int argc, char** argv)
+/**
+ *
+ *
+ * Starts sesman main loop
+ *
+ */
+static void DEFAULT_CC
+sesman_main_loop()
{
int in_sck;
int code;
@@ -75,52 +87,6 @@ main(int argc, char** argv)
struct session_item* s_item;
long data;
- if (0 != config_read(&g_cfg))
- {
- g_printf("error reading config. quitting.\n\r");
- return 1;
- }
-
- error = log_start(g_cfg.log.program_name, g_cfg.log.log_file, g_cfg.log.log_level,
- g_cfg.log.enable_syslog, g_cfg.log.syslog_level);
-
- if (error != LOG_STARTUP_OK)
- {
- switch (error)
- {
- case LOG_ERROR_MALLOC:
- g_printf("error on malloc. cannot start logging. quitting.\n\r");
- case LOG_ERROR_FILE_OPEN:
- g_printf("error opening log file. quitting.\n\r");
- }
- return 1;
- }
-
- /* start of daemonizing code */
- g_pid = g_fork();
-
- if (0!=g_pid)
- {
- g_exit(0);
- }
-
- g_file_close(0);
- g_file_close(1);
- g_file_close(2);
-
- g_file_open("/dev/null");
- g_file_open("/dev/null");
- g_file_open("/dev/null");
- /* end of daemonizing code */
-
- g_memset(&g_session_items, 0, sizeof(g_session_items));
- g_pid = g_getpid();
- g_signal(1, sig_sesman_reload_cfg); /* SIGHUP */
- g_signal(2, sig_sesman_shutdown); /* SIGINT */
- g_signal(9, sig_sesman_shutdown); /* SIGKILL */
- g_signal(15, sig_sesman_shutdown); /* SIGTERM */
- g_signal_child_stop(cterm); /* SIGCHLD */
-
/*main program loop*/
make_stream(in_s);
init_stream(in_s, 8192);
@@ -222,6 +188,135 @@ main(int argc, char** argv)
g_tcp_close(g_sck);
free_stream(in_s);
free_stream(out_s);
+}
+
+/******************************************************************************/
+int DEFAULT_CC
+main(int argc, char** argv)
+{
+ int fd;
+ int error;
+ int daemon=1;
+ int pid;
+ char pid_s[8];
+
+ if (1==argc)
+ {
+ /* no options on command line. normal startup */
+ g_printf("starting sesman...\n");
+ daemon=1;
+ }
+ else if ( (2==argc) && ( (0 == g_strncasecmp(argv[1],"--nodaemon",11)) || (0 == g_strncasecmp(argv[1],"-n",11)) ) )
+ {
+ /* starts sesman not daemonized */
+ g_printf("starting sesman in foregroud...\n");
+ daemon=0;
+ }
+ else if ( (2==argc) && ( (0 == g_strncasecmp(argv[1],"--help",7)) || (0 == g_strncasecmp(argv[1],"-h",2)) ) )
+ {
+ /* help screen */
+ g_printf("...\n");
+ }
+ else if ( (2==argc) && ( (0 == g_strncasecmp(argv[1],"--kill",11)) || (0 == g_strncasecmp(argv[1],"-k",11)) ) )
+ {
+ /* killing running sesman */
+ fd = g_file_open(SESMAN_PID_FILE);
+
+ if (-1 == fd)
+ {
+ g_printf("error opening pid file: %s\n", strerror(errno));
+ return 1;
+ }
+ error = g_file_read(fd, pid_s, 7);
+ sscanf(pid_s, "%i", &pid);
+
+ error = g_sigterm(pid);
+ if (0 != error)
+ {
+ g_printf("error killing sesman: %s\n", strerror(errno));
+ }
+
+ g_exit(error);
+ }
+ else
+ {
+ /* there's something strange on the command line */
+ g_printf("sesman - xrdp session manager\n");
+ g_printf("usage: sesman [ --nodaemon | --kill ]\n");
+ g_exit(1);
+ }
+
+ /* reading config */
+ if (0 != config_read(&g_cfg))
+ {
+ g_printf("error reading config: %s\nquitting.\n", strerror(errno));
+ g_exit(1);
+ }
+
+ /* starting logging subsystem */
+ error = log_start(g_cfg.log.program_name, g_cfg.log.log_file, g_cfg.log.log_level,
+ g_cfg.log.enable_syslog, g_cfg.log.syslog_level);
+
+ if (error != LOG_STARTUP_OK)
+ {
+ switch (error)
+ {
+ case LOG_ERROR_MALLOC:
+ g_printf("error on malloc. cannot start logging. quitting.\n");
+ case LOG_ERROR_FILE_OPEN:
+ g_printf("error opening log file. quitting.\n");
+ }
+ g_exit(1);
+ }
+
+ if (daemon)
+ {
+ /* start of daemonizing code */
+ g_pid = g_fork();
+
+ if (0!=g_pid)
+ {
+ g_exit(0);
+ }
+
+ g_file_close(0);
+ g_file_close(1);
+ g_file_close(2);
+
+ g_file_open("/dev/null");
+ g_file_open("/dev/null");
+ g_file_open("/dev/null");
+ }
+
+ /* signal handling */
+ g_memset(&g_session_items, 0, sizeof(g_session_items));
+ g_pid = g_getpid();
+ g_signal(1, sig_sesman_reload_cfg); /* SIGHUP */
+ g_signal(2, sig_sesman_shutdown); /* SIGINT */
+ g_signal(9, sig_sesman_shutdown); /* SIGKILL */
+ g_signal(15, sig_sesman_shutdown); /* SIGTERM */
+ g_signal_child_stop(cterm); /* SIGCHLD */
+
+ /* writing pid file */
+ fd = g_file_open(SESMAN_PID_FILE);
+ if (-1 == fd)
+ {
+ log_message(LOG_LEVEL_ERROR, "error opening pid file: %s", strerror(errno));
+ log_end();
+ 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);
+
+ /* start program main loop */
+ log_message(LOG_LEVEL_ALWAYS, "starting sesman with pid %d", g_pid);
+
+ sesman_main_loop();
+
+ log_end();
+
return 0;
}
+
diff --git a/sesman/sig.c b/sesman/sig.c
index cfc101c1..18492568 100644
--- a/sesman/sig.c
+++ b/sesman/sig.c
@@ -18,14 +18,13 @@
session manager
linux only
-
- sig.c: signal handling code
-
*/
/**
*
- * @file: signal handling functions
+ * @file sig.c
+ * @brief signal handling functions
+ * @author Jay Sorg, Simone Fedele
*
*/
@@ -35,13 +34,7 @@ extern int g_sck;
extern int g_pid;
extern struct config_sesman g_cfg;
-/**
- *
- * Shuts down sesman
- *
- * @param sig The received signal
- *
- */
+/******************************************************************************/
void DEFAULT_CC
sig_sesman_shutdown(int sig)
{
@@ -58,13 +51,7 @@ sig_sesman_shutdown(int sig)
g_tcp_close(g_sck);
}
-/**
- *
- * Reloads sesman config
- *
- * @param sig The received signal
- *
- */
+/******************************************************************************/
void DEFAULT_CC
sig_sesman_reload_cfg(int sig)
{
diff --git a/sesman/sig.h b/sesman/sig.h
index 81687437..07e2e6dd 100644
--- a/sesman/sig.h
+++ b/sesman/sig.h
@@ -18,19 +18,36 @@
session manager
linux only
-
- sig.h: signal handling code declarations
-
*/
+/**
+ *
+ * @file sig.h
+ * @brief Signal handling function declarations
+ * @author Jay Sorg, Simone Fedele
+ *
+ */
+
#ifndef SIG_H
#define SIG_H
-/******************************************************************************/
+/**
+ *
+ * @brief Shutdown signal code
+ *
+ * @param sig The received signal
+ *
+ */
void DEFAULT_CC
sig_sesman_shutdown(int sig);
-/******************************************************************************/
+/**
+ *
+ * @brief SIGHUP handling code
+ *
+ * @param sig The received signal
+ *
+ */
void DEFAULT_CC
sig_sesman_reload_cfg(int sig);
diff --git a/sesman/tcp.c b/sesman/tcp.c
index 2bfa84c2..54bbacea 100644
--- a/sesman/tcp.c
+++ b/sesman/tcp.c
@@ -18,11 +18,16 @@
session manager
linux only
-
- tcp.c: tcp stream funcions
-
*/
+/**
+ *
+ * @file tcp.c
+ * @brief Tcp stream funcions
+ * @author Jay Sorg
+ *
+ */
+
#include "sesman.h"
/*****************************************************************************/
diff --git a/sesman/tcp.h b/sesman/tcp.h
index 130c18a7..dfb6d6d1 100644
--- a/sesman/tcp.h
+++ b/sesman/tcp.h
@@ -18,14 +18,13 @@
session manager
linux only
-
- tcp.h: tcp stream functions declarations
-
*/
/**
*
- * @file tcp stream functions
+ * @file tcp.h
+ * @brief Tcp stream functions declarations
+ * @author Jay Sorg
*
*/
@@ -34,31 +33,29 @@
/**
*
- * force receiving data from tcp stream
+ * @brief Force receiving data from tcp stream
*
- * @param sck the socket to read from
- * @param data buffer
- * @param len buffer size
+ * @param sck The socket to read from
+ * @param data Data buffer
+ * @param len Data buffer size
*
- * @return 0: ok, 1: error
+ * @return 0 on success, 1 on error
*
*/
-
int DEFAULT_CC
tcp_force_recv(int sck, char* data, int len);
/**
*
- * force sending data to tcp stream
+ * @brief Force sending data to tcp stream
*
* @param sck the socket to write to
- * @param data buffer
- * @param len buffer size
+ * @param data Data buffer
+ * @param len Data buffer size
*
- * @return 0: ok, 1: error
+ * @return 0 on success, 1 on error
*
*/
-
int DEFAULT_CC
tcp_force_send(int sck, char* data, int len);