From 13f97cbc84c5fcc92cc7a82e79ddcb84d85c61ff Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 16 Feb 2020 00:01:38 +0100 Subject: Client.c: add clientInfoString to client privates This is a string that contains the address, the index, the PID and the process name of the client. The string can be used in debugging messages to identify the client. --- nx-X11/programs/Xserver/hw/nxagent/Client.c | 47 +++++++++++++++++++++++++++++ nx-X11/programs/Xserver/hw/nxagent/Client.h | 5 ++- 2 files changed, 51 insertions(+), 1 deletion(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Client.c b/nx-X11/programs/Xserver/hw/nxagent/Client.c index 9b0f2c5e6..83554e573 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Client.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Client.c @@ -112,6 +112,14 @@ int nxagentClientPrivateIndex; int nxagentShadowCounter = 0; +/* + * For the serverclient the ClientStateCallback will not be called on + * shutdown resulting in memory allocated during initClientPrivates can + * not be freed automatically. So instead of allocating some memory we + * create a static string for the serverclient. + */ +static char *serverclientInfoString = "[0] (serverclient)"; + /* * called whenever the client state changes. See dixstruct.h for a * list of known states. @@ -182,6 +190,42 @@ static void initClientPrivates(ClientPtr client) nxagentClientPriv(client) -> clientBytes = 0; #endif nxagentClientPriv(client) -> clientHint = UNKNOWN; + nxagentClientPriv(client) -> clientInfoString = NULL; + + char *s = NULL; + int size = 0; + + if (client->index == 0) + { + s = serverclientInfoString; + } + else + { +#ifdef CLIENTIDS + size = asprintf(&s, "[%d] (addr [%p] PID [%d] Cmd [%s])", + client->index, (void *)client, + GetClientPid(client), + GetClientCmdName(client)); +#else + size = asprintf(&s, "[%d] (addr [%p])", + client->index, (void *)client); +#endif + } + + if (size != -1) + { + #ifdef DEBUG + fprintf(stderr, "%s: clientInfoString: \"%s\"\n", __func__, s); + #endif + + nxagentClientPriv(client) -> clientInfoString = s; + } + else + { + #ifdef DEBUG + fprintf(stderr, "%s: could not alloc clientInfoString\n", __func__); + #endif + } } } @@ -198,6 +242,9 @@ static void freeClientPrivates(ClientPtr client) nxagentClientPriv(client) -> clientBytes = 0; #endif nxagentClientPriv(client) -> clientHint = UNKNOWN; + + if (client->index != 0) + SAFE_free(nxagentClientPriv(client) -> clientInfoString); } } diff --git a/nx-X11/programs/Xserver/hw/nxagent/Client.h b/nx-X11/programs/Xserver/hw/nxagent/Client.h index 38a02aed1..a3e6e3cf3 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Client.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Client.h @@ -49,7 +49,7 @@ typedef struct _PrivClientRec int clientState; long clientBytes; enum ClientHint clientHint; - + char *clientInfoString; } PrivClientRec; extern int nxagentClientPrivateIndex; @@ -75,6 +75,9 @@ extern void nxagentClientStateCallback(CallbackListPtr *callbacks, void *data, v #define nxagentClientIsDialog(pClient) \ (nxagentClientHint(pClient) == NXCLIENT_DIALOG) +#define nxagentClientInfoString(pClient) \ + (nxagentClientPriv(pClient) -> clientInfoString) + /* * The actual reason why the client is sleeping. */ -- cgit v1.2.3