Skip to content

Commit

Permalink
Add shared memory file to rediscover sessions neutrinolabs#800
Browse files Browse the repository at this point in the history
Allow xrdp-sesman to discover sessions still running that were created
by a previous xrdp-sesman process.

Implement this using a file-backed shared mmap region, visible to both
the daemon and session instances of xrdp-sesman.  Add a heartbeat
timestamp updated by the session instance so that the daemon instance
can infer whether the sessions in the mmap region are current or stale.

The shared memory can also be used to pass other data between daemon and
session instances, for example the session's idle time.

Add locking around access to g_sessions and the mmap region.  This is a
PTHREAD_PROCESS_SHARED lock which protects shared memory used by
separate processes.  Defining DEBUG_SESSION_LOCK enables logging to help
debug locking bugs.

Notes:

1. The number of sessions is limited by the size of the array in shared
memory, SESMAN_SHAREDMEM_MAX_SESSIONS.  This could be made dynamic
instead by growing the file and the mmap region.

2. If sesshm_try_open_existing_shm() finds a shm file but it looks
wrong, it creates a new one.  Perhaps it should instead exit with an
error?

3. In sesshm_thread() if the session xrdp-sesman notices that it has
been removed from the daemon's list it exits.  It should kill the X
server and/or window manager first.

4. This doesn't yet update idle times.  I need to work out how to get
this information from the X server.

5. This uses an array of sessions in the mmap region so the linked list
g_sessions might be redundant now.

6. Defining DONT_USE_SHM will let xrdp-sesman run without creating or
trying to use the mmap file.  This could be removed in the future.

7. I think the locking fixes an theorised bug where a session can be
removed from the g_sessions linked list in session_kill() (called from
the signal handler) at the same time as a session is added in
session_start_fork().
  • Loading branch information
ben-cohen committed Jul 16, 2017
1 parent aaa40ed commit 64ef843
Show file tree
Hide file tree
Showing 4 changed files with 690 additions and 8 deletions.
7 changes: 7 additions & 0 deletions sesman/sesman.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ main(int argc, char **argv)
g_file_close(fd);
}

if (session_init_shared())
log_message(LOG_LEVEL_ERROR,
"error opening session shm file[%s]: %s",
SESMAN_SHAREDMEM_FILENAME, g_get_strerror());


/* start program main loop */
log_message(LOG_LEVEL_INFO,
"starting xrdp-sesman with pid %d", g_pid);
Expand Down Expand Up @@ -441,6 +447,7 @@ main(int argc, char **argv)
{
g_file_delete(pid_file);
}
session_close_shared();

g_delete_wait_obj(g_term_event);

Expand Down
Loading

0 comments on commit 64ef843

Please sign in to comment.