Skip to content

Workaround for missing "display" var (removed from xserver) #362

@Luckylazuli

Description

@Luckylazuli

Hi, this is my first post in GitHub, so sorry if I do something wrong.

I noticed that on my openSUSE Distro xrdp had a major update and wasn't working anymore, since also, I build xserver devel from git.
I don't know exactly if this is a common issue or specific for my system. Anyhow, I also build xrdp and finally found out, that xorgxrdp was missing "display" for the Xorg. Building xorgxrdp caused the compile error as excepted.

So I edited the code of '/module/rdpClientCon.c' - I gave up to understand if "display" looking for a existing socket or whatever.

Instead I made a simple workaround by checking for a set and customizable 'CUSTOM_XORGXRDP_DISPLAY' env var, with a fallback to "display = 0" if not set. Maybe this helps, idk:

/******************************************************************************/
int
rdpClientConInit(rdpPtr dev)
{
    int i;
    char *ptext;
    char *endptr = NULL;
    const char *socket_dir;

    socket_dir = g_socket_dir();
    if (!g_directory_exist(socket_dir))
    {
        if (!g_create_dir(socket_dir))
        {
            if (!g_directory_exist(socket_dir))
            {
                LLOGLN(0, ("rdpClientConInit: g_create_dir(%s) failed", socket_dir));
                return 0;
            }
        }
        g_chmod_hex(socket_dir, 0x1777);
    }

// ------------------------------------------------------------------------------------------------------------
// 'display' member variable in 'opaque.h' of xserver removed, workaround by customizable environment variable
    const char *display = getenv("CUSTOM_XORGXRDP_DISPLAY");
    if (display == NULL) {
        LLOGLN(0, ("Env var 'CUSTOM_XORGXRDP_DISPLAY' not set, fallback to display '0'."));
        display = "0";
    }
// ------------------------------------------------------------------------------------------------------------

    errno = 0;
    i = (int)strtol(display, &endptr, 10);
    if (errno != 0 || display == endptr || *endptr != 0)
    {
        LLOGLN(0, ("rdpClientConInit: can not run at non-interger display"));
        return 0;
    }

    /* TODO: don't hardcode socket name */
    g_sprintf(dev->uds_data, "%s/xrdp_display_%s", socket_dir, display);
    if (dev->listen_sck == 0)
    {
        unlink(dev->uds_data);
        dev->listen_sck = g_sck_local_socket_stream();
        if (g_sck_local_bind(dev->listen_sck, dev->uds_data) != 0)
        {
            LLOGLN(0, ("rdpClientConInit: g_tcp_local_bind failed"));
            return 1;
        }
        g_sck_listen(dev->listen_sck);
        g_chmod_hex(dev->uds_data, 0x0660);
        rdpClientConAddEnabledDevice(dev->pScreen, dev->listen_sck);
    }

    /* disconnect socket */ /* TODO: don't hardcode socket name */
    g_sprintf(dev->disconnect_uds, "%s/xrdp_disconnect_display_%s", socket_dir, display);
    if (dev->disconnect_sck == 0)
    {
        unlink(dev->disconnect_uds);
        dev->disconnect_sck = g_sck_local_socket_dgram();
        if (g_sck_local_bind(dev->disconnect_sck, dev->disconnect_uds) != 0)
        {
            LLOGLN(0, ("rdpClientConInit: g_tcp_local_bind failed at %s:%d", __FILE__, __LINE__));
            return 1;
        }
        g_sck_listen(dev->disconnect_sck);
        g_chmod_hex(dev->disconnect_uds, 0x0660);
        rdpClientConAddEnabledDevice(dev->pScreen, dev->disconnect_sck);
    }

    /* disconnect idle */
    ptext = getenv("XRDP_SESMAN_MAX_IDLE_TIME");
    if (ptext != 0)
    {
        i = atoi(ptext);
        if (i > 0)
        {
            dev->idle_disconnect_timeout_s = i;
        }

    }
    LLOGLN(0, ("rdpClientConInit: disconnect idle session after [%d] sec",
               dev->idle_disconnect_timeout_s));

    /* kill disconnected */
    ptext = getenv("XRDP_SESMAN_MAX_DISC_TIME");
    if (ptext != 0)
    {
        i = atoi(ptext);
        if (i > 0)
        {
            dev->disconnect_timeout_s = atoi(ptext);
        }
    }
    ptext = getenv("XRDP_SESMAN_KILL_DISCONNECTED");
    if (ptext != 0)
    {
        i = atoi(ptext);
        if (i == 0)
        {
            dev->do_kill_disconnected = 0;
        }
        else
        {
            dev->do_kill_disconnected = 1;
        }
    }

    if (dev->do_kill_disconnected && (dev->disconnect_timeout_s < 60))
    {
        dev->disconnect_timeout_s = 60;
    }

    LLOGLN(0, ("rdpClientConInit: kill disconnected [%d] timeout [%d] sec",
               dev->do_kill_disconnected, dev->disconnect_timeout_s));


    return 0;
}

/******************************************************************************/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions