Liyi Meng 2a77f5f3e8 chansrv: Rewrite ibus unicode input around a private main loop
Replace the shared-global-context design with one where chansrv's
thread never touches libibus directly. All IBus objects (bus, engine,
factory, component) are now owned exclusively by a private
GMainContext/GMainLoop created inside the IBus thread; chansrv hands
off unicode codepoints through a thread-safe GAsyncQueue and wakes the
loop, instead of calling ibus_engine_commit_text() from the wrong
thread or relying on ibus_main()/ibus_quit(), which turned out to
operate on a single loop shared by the whole process rather than one
per connection.

Fixes along the way, found by testing against a live ibus-daemon and
a real focused GTK app rather than just reading the diff:

- xrdp_engine_enable()/disable() now take a real reference on g_engine
  (g_object_ref/unref) instead of caching a bare pointer. The old code
  unreffed g_engine on teardown without ever having reffed it - IBusEngine
  derives from GInitiallyUnowned, so that was releasing a reference it
  never owned.
- A custom GSource drains the unicode queue, gated on the engine
  actually existing (engine creation is async once XrdpIme is
  selected), so a character queued before the engine is ready isn't
  lost - it commits as soon as the "enable" signal fires, instead of
  racing a one-shot commit against that async setup.
- ibus_engine_commit_text() releases its IBusText argument itself
  (it's floating, documented behavior for that specific call) - an
  earlier draft of this rewrite added an extra g_object_unref() after
  it, which would have been a double-release.
- bus (and anything else that opens a GDBusConnection) must be created
  after the private GMainContext is pushed as thread-default, not
  before - otherwise its async I/O silently binds to the global
  default context, which nothing here iterates, and signals like
  "disconnected" simply never fire.
- xrdp_input_unicode_init() now blocks on a condvar until the IBus
  thread actually signals ready (or exits), instead of returning
  immediately and hoping the engine shows up in time.
- unicode_init()/destroy() no longer touch bus/g_engine from chansrv's
  own thread while the IBus thread may still be running against them;
  destroy() schedules real teardown on the IBus thread and joins it via
  a condvar before returning.

Known limitation, confirmed empirically rather than assumed: this does
NOT make reconnect-after-daemon-restart (#3230) actually work.
ibus_bus_new() returns a process-wide singleton in this libibus
version - two calls in the same process with no disconnect involved
return the identical pointer - so once its connection dies, every
later call just hands back the same dead object; ibus_bus_is_connected()
on it stays permanently false, confirmed not to be a transient state
via repeated retries with delay. The "disconnected" handler still
tears the thread down cleanly so a later xrdp_input_unicode_init()
fails fast instead of hanging or operating on stale state, but a real
fix would mean bypassing IBusBus for a raw GDBusConnection to
ibus-daemon, which isn't justified given how rarely the daemon
actually restarts mid-session.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-17 22:10:23 +00:00
2026-08-17 08:58:29 +00:00
2026-04-06 10:29:17 -07:00
2025-05-06 11:30:36 +01:00
2024-02-21 09:24:48 +00:00
2025-05-21 11:34:34 +01:00
2026-07-02 17:33:45 +09:00
2023-06-23 15:12:51 +01:00
2025-11-25 15:43:38 +01:00
2025-02-27 15:04:11 +00:00
2026-01-30 18:54:57 -08:00
2026-04-17 12:23:17 +01:00
2026-04-17 12:23:17 +01:00
2026-04-17 12:23:17 +01:00
2022-03-16 10:16:39 +09:00
2024-05-01 09:26:58 +01:00

Build Status Gitter Apache-License

Latest Version

xrdp - an open source RDP server

Overview

xrdp provides a graphical login to remote machines using Microsoft Remote Desktop Protocol (RDP). xrdp accepts connections from a variety of RDP clients:

  • FreeRDP
  • rdesktop
  • KRDC
  • NeutrinoRDP
  • Windows MSTSC (Microsoft Terminal Services Client, aka mstsc.exe)
  • Microsoft Remote Desktop (found on Microsoft Store, which is distinct from MSTSC)

Many of these work on some or all of Windows, Mac OS, iOS, and/or Android.

RDP transport is encrypted using TLS by default.

demo

Features

Remote Desktop Access

  • Connect to a Linux desktop using RDP from anywhere (requires xorgxrdp Xorg module)
  • Reconnect to an existing session
  • Session resizing (both on-connect and on-the-fly)
  • RDP/VNC proxy (connect to another RDP/VNC server via xrdp)

Access to Remote Resources

Supported Platforms

xrdp primarily targets GNU/Linux operating system. x86 (including x86-64) and ARM processors are most mature architecture to run xrdp on. See also Platform Support Tier.

Some components such as xorgxrdp and RemoteFX codec have special optimization for x86 using SIMD instructions. So running xrdp on x86 processors will get fully accelerated experience.

Quick Start

Most Linux distributions should distribute the latest release of xrdp in their repository. You would need xrdp and xorgxrdp packages for the best experience. It is recommended that xrdp depends on xorgxrdp, so it should be sufficient to install xrdp. If xorgxrdp is not provided, use Xvnc server.

xrdp listens on 3389/tcp. Make sure your firewall accepts connection to 3389/tcp from where you want to access.

Ubuntu / Debian

apt install xrdp

Fedora, RHEL and derivatives

If you're not running Fedora, make sure to enable EPEL packages first.

dnf install epel-release

(All systems) Install xrdp with:-

dnf install xrdp

Compiling

See also https://github.com/neutrinolabs/xrdp/wiki#building-from-sources

Prerequisites

To compile xrdp from the packaged sources, you need basic build tools - a compiler (gcc or clang) and the make program. Additionally, you would need openssl-devel, pam-devel, libX11-devel, libXfixes-devel, libXrandr-devel. More additional software would be needed depending on your configuration.

To compile xrdp from a checked out git repository, you would additionally need autoconf, automake, libtool and pkg-config.

Get the source and build it

If compiling from the packaged source, unpack the tarball and change to the resulting directory.

If compiling from a checked out repository, please make sure you've got the submodules cloned too (use git clone --recursive https://github.com/neutrinolabs/xrdp)

Then run following commands to compile and install xrdp:

./bootstrap
./configure
make
sudo make install

If you want to use audio redirection, you need to build and install additional pulseaudio modules. The build instructions can be found at wiki.

Directory Structure

xrdp
├── common ······ common code
├── docs ········ documentation
├── fontutils ··· font handling utilities
├── genkeymap ··· keymap generator
├── instfiles ··· installable data file
├── keygen ······ xrdp RSA key pair generator
├── libpainter ·· painter library
├── librfxcodec · RFX codec library
├── libxrdp ····· core RDP protocol implementation
├── m4 ·········· Autoconf macros
├── mc ·········· media center module
├── neutrinordp · RDP client module for proxying RDP connections using NeutrinoRDP
├── pkgconfig ··· pkg-config configuration
├── scripts ····· build scripts
├┬─ sesman ······ session manager for xrdp
|├── chansrv ···· channel server for xrdp
|├── libsesman ·· Code common to sesman and its related executables
|└── tools ······ session management tools for sys admins
├── tests ······· tests for the code
├┬─ tools ······· tools
|└┬─ devel ······ development tools
| ├── gtcp_proxy  GTK app that forwards TCP connections to a remote host
| └── tcp_proxy · CLI app that forwards TCP connections to a remote host
├── vnc ········· VNC client module for xrdp
├── vrplayer ···· QT player redirecting video/audio to clients over xrdpvr channel
├── xrdp ········ main server code
├── xrdpapi ····· virtual channel API
├── xrdpvr ······ API for playing media over RDP
└── xup ········· xorgxrdp client module
S
Description
No description provided
Readme 17 MiB
Languages
C 96.3%
M4 1.2%
Shell 1%
C++ 0.8%
Makefile 0.6%