Add --reload option to sesman
Adds a --reload switch to sesman and plumbs this in to systemctl reload xrdp-sesman.service
This commit is contained in:
@@ -3043,6 +3043,18 @@ g_sigterm(int pid)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* does not work in win32 */
|
||||||
|
int
|
||||||
|
g_sighup(int pid)
|
||||||
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
return kill(pid, SIGHUP);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* returns 0 if ok */
|
/* returns 0 if ok */
|
||||||
/* the caller is responsible to free the buffs */
|
/* the caller is responsible to free the buffs */
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ char *g_getenv(const char *name);
|
|||||||
int g_exit(int exit_code);
|
int g_exit(int exit_code);
|
||||||
int g_getpid(void);
|
int g_getpid(void);
|
||||||
int g_sigterm(int pid);
|
int g_sigterm(int pid);
|
||||||
|
int g_sighup(int pid);
|
||||||
int g_getuser_info(const char *username, int *gid, int *uid, char **shell,
|
int g_getuser_info(const char *username, int *gid, int *uid, char **shell,
|
||||||
char **dir, char **gecos);
|
char **dir, char **gecos);
|
||||||
int g_getgroup_info(const char *groupname, int *gid);
|
int g_getgroup_info(const char *groupname, int *gid);
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ xrdp\-sesman \- \fBxrdp\fR(8) session manager
|
|||||||
\-\-kill
|
\-\-kill
|
||||||
.br
|
.br
|
||||||
.B xrdp\-sesman
|
.B xrdp\-sesman
|
||||||
|
\-\-reload
|
||||||
|
.br
|
||||||
|
.B xrdp\-sesman
|
||||||
\-\-help
|
\-\-help
|
||||||
.br
|
.br
|
||||||
.B xrdp\-sesman
|
.B xrdp\-sesman
|
||||||
@@ -25,6 +28,9 @@ It manages user sessions by authenticating the user and starting the appropriate
|
|||||||
\fB\-k\fR, \fB\-\-kill\fR
|
\fB\-k\fR, \fB\-\-kill\fR
|
||||||
Kills running \fBxrdp\-sesman\fR daemon.
|
Kills running \fBxrdp\-sesman\fR daemon.
|
||||||
.TP
|
.TP
|
||||||
|
\fB\-r\fR, \fB\-\-reload\fR
|
||||||
|
Reloads running \fBxrdp\-sesman\fR daemon.
|
||||||
|
.TP
|
||||||
\fB\-h\fR, \fB\-\-help\fR
|
\fB\-h\fR, \fB\-\-help\fR
|
||||||
Output help information and exit.
|
Output help information and exit.
|
||||||
.TP
|
.TP
|
||||||
@@ -48,6 +54,11 @@ If you use this option, be aware that you will have to have a
|
|||||||
the system (notably \fBxrdp(8)\fR and \fBxrdp\-chansrv(8)\fR) will want
|
the system (notably \fBxrdp(8)\fR and \fBxrdp\-chansrv(8)\fR) will want
|
||||||
to read it.
|
to read it.
|
||||||
.RE
|
.RE
|
||||||
|
.SH "SIGNALS"
|
||||||
|
.TP
|
||||||
|
\fBSIGHUP\fR
|
||||||
|
Causes \fBxrdp\-sesman\fR to reload its configuration. Needed if you're
|
||||||
|
not running \fBxrdp\-sesman\fR as a daemon.
|
||||||
.SH "FILES"
|
.SH "FILES"
|
||||||
@sbindir@/xrdp\-sesman
|
@sbindir@/xrdp\-sesman
|
||||||
.br
|
.br
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ EnvironmentFile=-@sysconfdir@/sysconfig/xrdp
|
|||||||
EnvironmentFile=-@sysconfdir@/default/xrdp
|
EnvironmentFile=-@sysconfdir@/default/xrdp
|
||||||
ExecStart=@sbindir@/xrdp-sesman $SESMAN_OPTIONS
|
ExecStart=@sbindir@/xrdp-sesman $SESMAN_OPTIONS
|
||||||
ExecStop=@sbindir@/xrdp-sesman $SESMAN_OPTIONS --kill
|
ExecStop=@sbindir@/xrdp-sesman $SESMAN_OPTIONS --kill
|
||||||
|
ExecReload=@sbindir@/xrdp-sesman $SESMAN_OPTIONS --reload
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
+77
-38
@@ -46,10 +46,20 @@
|
|||||||
*/
|
*/
|
||||||
#define MAX_SHORT_LIVED_CONNECTIONS 16
|
#define MAX_SHORT_LIVED_CONNECTIONS 16
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the mode of operation of the program
|
||||||
|
*/
|
||||||
|
enum sesman_mode
|
||||||
|
{
|
||||||
|
SSM_NORMAL = 0,
|
||||||
|
SSM_KILL_DAEMON,
|
||||||
|
SSM_RELOAD_DAEMON
|
||||||
|
};
|
||||||
|
|
||||||
struct sesman_startup_params
|
struct sesman_startup_params
|
||||||
{
|
{
|
||||||
const char *sesman_ini;
|
const char *sesman_ini;
|
||||||
int kill;
|
enum sesman_mode mode;
|
||||||
int no_daemon;
|
int no_daemon;
|
||||||
int help;
|
int help;
|
||||||
int version;
|
int version;
|
||||||
@@ -158,6 +168,8 @@ sesman_process_params(int argc, char **argv,
|
|||||||
const char *option;
|
const char *option;
|
||||||
const char *value;
|
const char *value;
|
||||||
|
|
||||||
|
startup_params->mode = SSM_NORMAL;
|
||||||
|
|
||||||
index = 1;
|
index = 1;
|
||||||
|
|
||||||
while (index < argc)
|
while (index < argc)
|
||||||
@@ -179,7 +191,11 @@ sesman_process_params(int argc, char **argv,
|
|||||||
}
|
}
|
||||||
else if (nocase_matches(option, "-kill", "--kill", "-k", NULL))
|
else if (nocase_matches(option, "-kill", "--kill", "-k", NULL))
|
||||||
{
|
{
|
||||||
startup_params->kill = 1;
|
startup_params->mode = SSM_KILL_DAEMON;
|
||||||
|
}
|
||||||
|
else if (nocase_matches(option, "-reload", "--reload", "-r", NULL))
|
||||||
|
{
|
||||||
|
startup_params->mode = SSM_RELOAD_DAEMON;
|
||||||
}
|
}
|
||||||
else if (nocase_matches(option, "-nodaemon", "--nodaemon", "-n",
|
else if (nocase_matches(option, "-nodaemon", "--nodaemon", "-n",
|
||||||
"-nd", "--nd", "-ns", "--ns", NULL))
|
"-nd", "--nd", "-ns", "--ns", NULL))
|
||||||
@@ -594,6 +610,7 @@ print_help(void)
|
|||||||
{
|
{
|
||||||
g_printf("Usage: xrdp-sesman [options]\n");
|
g_printf("Usage: xrdp-sesman [options]\n");
|
||||||
g_printf(" -k, --kill shut down xrdp-sesman\n");
|
g_printf(" -k, --kill shut down xrdp-sesman\n");
|
||||||
|
g_printf(" -r, --reload reload xrdp-sesman\n");
|
||||||
g_printf(" -h, --help show help\n");
|
g_printf(" -h, --help show help\n");
|
||||||
g_printf(" -v, --version show version\n");
|
g_printf(" -v, --version show version\n");
|
||||||
g_printf(" -n, --nodaemon don't fork into background\n");
|
g_printf(" -n, --nodaemon don't fork into background\n");
|
||||||
@@ -603,57 +620,44 @@ print_help(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
/**
|
||||||
|
* Reads the PID file
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
kill_running_sesman(const char *pid_file)
|
read_pid_file(const char *pid_file, int *pid)
|
||||||
{
|
{
|
||||||
int error;
|
int rv = 1;
|
||||||
int fd;
|
int fd;
|
||||||
int pid;
|
|
||||||
char pid_s[32] = {0};
|
|
||||||
|
|
||||||
/* check if sesman is running */
|
/* check if sesman is running */
|
||||||
if (!g_file_exist(pid_file))
|
if (!g_file_exist(pid_file))
|
||||||
{
|
{
|
||||||
g_printf("sesman is not running (pid file not found - %s)\n", pid_file);
|
g_printf("sesman is not running (pid file not found - %s)\n", pid_file);
|
||||||
g_deinit();
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
else if ((fd = g_file_open(pid_file)) < 0)
|
||||||
fd = g_file_open(pid_file);
|
|
||||||
|
|
||||||
if (-1 == fd)
|
|
||||||
{
|
{
|
||||||
g_printf("error opening pid file[%s]: %s\n", pid_file, g_get_strerror());
|
g_printf("error opening pid file[%s]: %s\n", pid_file, g_get_strerror());
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = g_file_read(fd, pid_s, sizeof(pid_s) - 1);
|
|
||||||
|
|
||||||
if (-1 == error)
|
|
||||||
{
|
|
||||||
g_printf("error reading pid file: %s\n", g_get_strerror());
|
|
||||||
g_file_close(fd);
|
|
||||||
g_deinit();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_file_close(fd);
|
|
||||||
pid = g_atoi(pid_s);
|
|
||||||
|
|
||||||
error = g_sigterm(pid);
|
|
||||||
|
|
||||||
if (0 != error)
|
|
||||||
{
|
|
||||||
g_printf("error killing sesman: %s\n", g_get_strerror());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_file_delete(pid_file);
|
char pid_s[32] = {0};
|
||||||
|
int error = g_file_read(fd, pid_s, sizeof(pid_s) - 1);
|
||||||
|
g_file_close(fd);
|
||||||
|
|
||||||
|
if (error < 0)
|
||||||
|
{
|
||||||
|
g_printf("error reading pid file: %s\n", g_get_strerror());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*pid = g_atoi(pid_s);
|
||||||
|
rv = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_deinit();
|
return rv;
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
@@ -699,9 +703,44 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (startup_params.kill)
|
if (startup_params.mode == SSM_KILL_DAEMON)
|
||||||
{
|
{
|
||||||
g_exit(kill_running_sesman(pid_file));
|
int pid;
|
||||||
|
int error = 1;
|
||||||
|
if (read_pid_file(pid_file, &pid) == 0)
|
||||||
|
{
|
||||||
|
if (g_sigterm(pid) != 0)
|
||||||
|
{
|
||||||
|
g_printf("error killing sesman: %s\n", g_get_strerror());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* File is no longer required */
|
||||||
|
g_file_delete(pid_file);
|
||||||
|
error = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_deinit();
|
||||||
|
g_exit(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startup_params.mode == SSM_RELOAD_DAEMON)
|
||||||
|
{
|
||||||
|
int pid;
|
||||||
|
int error = 1;
|
||||||
|
if (read_pid_file(pid_file, &pid) == 0)
|
||||||
|
{
|
||||||
|
if (g_sighup(pid) != 0)
|
||||||
|
{
|
||||||
|
g_printf("error reloading sesman: %s\n", g_get_strerror());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_deinit();
|
||||||
|
g_exit(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_file_exist(pid_file))
|
if (g_file_exist(pid_file))
|
||||||
|
|||||||
Reference in New Issue
Block a user