From 1d93fbc68e939448108fcf4e90ed383df5febe92 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 14 Aug 2025 20:20:02 +0200 Subject: [PATCH] randr: use X_SEND_REPLY_WITH_RPCBUF() macro Use the new X_SEND_REPLY_WITH_RPCBUF() macro for final reply write out Signed-off-by: Enrico Weigelt, metux IT consult --- randr/rrcrtc.c | 28 ++++------------------------ randr/rrmonitor.c | 8 +------- randr/rroutput.c | 10 +--------- randr/rrproperty.c | 19 ++----------------- randr/rrproviderproperty.c | 33 +++++++++++---------------------- 5 files changed, 19 insertions(+), 79 deletions(-) diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c index 764624ef1..c9ff42c19 100644 --- a/randr/rrcrtc.c +++ b/randr/rrcrtc.c @@ -1163,9 +1163,7 @@ ProcRRGetCrtcInfo(ClientPtr client) RRModePtr mode = crtc->mode; xRRGetCrtcInfoReply rep = { - .type = X_Reply, .status = RRSetConfigSuccess, - .sequenceNumber = client->sequence, .timestamp = pScrPriv->lastSetTime.milliseconds, .rotation = crtc->rotation, .rotations = crtc->rotations, @@ -1219,8 +1217,6 @@ ProcRRGetCrtcInfo(ClientPtr client) } } - rep.length = x_rpcbuf_wsize_units(&rpcbuf); - if (rpcbuf.error) return BadAlloc; @@ -1228,8 +1224,6 @@ ProcRRGetCrtcInfo(ClientPtr client) pScrPriv->rrCrtcGet(pScreen, crtc, &rep); if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); swapl(&rep.timestamp); swaps(&rep.x); swaps(&rep.y); @@ -1242,8 +1236,7 @@ ProcRRGetCrtcInfo(ClientPtr client) swaps(&rep.nPossibleOutput); } - WriteToClient(client, sizeof(xRRGetCrtcInfoReply), &rep); - WriteRpcbufToClient(client, &rpcbuf); + X_SEND_REPLY_WITH_RPCBUF(client, rep, rpcbuf); return Success; } @@ -1646,19 +1639,14 @@ ProcRRGetCrtcGamma(ClientPtr client) x_rpcbuf_write_CARD16s(&rpcbuf, crtc->gammaBlue, crtc->gammaSize); xRRGetCrtcGammaReply reply = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = x_rpcbuf_wsize_units(&rpcbuf), .size = crtc->gammaSize }; + if (client->swapped) { - swaps(&reply.sequenceNumber); - swapl(&reply.length); swaps(&reply.size); } - WriteToClient(client, sizeof(xRRGetCrtcGammaReply), &reply); - WriteRpcbufToClient(client, &rpcbuf); + X_SEND_REPLY_WITH_RPCBUF(client, reply, rpcbuf); return Success; } @@ -1744,8 +1732,6 @@ ProcRRGetCrtcTransform(ClientPtr client) x_rpcbuf_t rpcbuf = { .swapped = client->swapped, .err_clear = TRUE }; xRRGetCrtcTransformReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, .hasTransforms = crtc->transforms, }; @@ -1769,12 +1755,7 @@ ProcRRGetCrtcTransform(ClientPtr client) if (rpcbuf.error) return BadAlloc; - rep.length = bytes_to_int32(sizeof(xRRGetCrtcTransformReply) - sizeof(xGenericReply) - + rpcbuf.wpos); - if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); SwapLongs((CARD32 *) &rep.pendingTransform, bytes_to_int32(sizeof(xRenderTransform))); SwapLongs((CARD32 *) &rep.currentTransform, bytes_to_int32(sizeof(xRenderTransform))); swaps(&rep.pendingNbytesFilter); @@ -1783,8 +1764,7 @@ ProcRRGetCrtcTransform(ClientPtr client) swaps(&rep.currentNparamsFilter); } - WriteToClient(client, sizeof(xRRGetCrtcTransformReply), &rep); - WriteRpcbufToClient(client, &rpcbuf); + X_SEND_REPLY_WITH_RPCBUF(client, rep, rpcbuf); return Success; } diff --git a/randr/rrmonitor.c b/randr/rrmonitor.c index e9214da32..b7158b3b6 100644 --- a/randr/rrmonitor.c +++ b/randr/rrmonitor.c @@ -636,24 +636,18 @@ ProcRRGetMonitors(ClientPtr client) RRMonitorFreeList(monitors, nmonitors); xRRGetMonitorsReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, .timestamp = RRMonitorTimestamp(screen), .nmonitors = nmonitors, .noutputs = noutputs, - .length = x_rpcbuf_wsize_units(&rpcbuf), }; if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); swapl(&rep.timestamp); swapl(&rep.nmonitors); swapl(&rep.noutputs); } - WriteToClient(client, sizeof(xRRGetMonitorsReply), &rep); - WriteRpcbufToClient(client, &rpcbuf); + X_SEND_REPLY_WITH_RPCBUF(client, rep, rpcbuf); return Success; } diff --git a/randr/rroutput.c b/randr/rroutput.c index 249cb2cfd..4b783c154 100644 --- a/randr/rroutput.c +++ b/randr/rroutput.c @@ -460,10 +460,7 @@ ProcRRGetOutputInfo(ClientPtr client) pScrPriv = rrGetScrPriv(pScreen); xRRGetOutputInfoReply rep = { - .type = X_Reply, .status = RRSetConfigSuccess, - .sequenceNumber = client->sequence, - .length = bytes_to_int32(sizeof(xRRGetOutputInfoReply)-sizeof(xReply)), .timestamp = pScrPriv->lastSetTime.milliseconds, .nameLength = output->nameLength, }; @@ -500,11 +497,7 @@ ProcRRGetOutputInfo(ClientPtr client) x_rpcbuf_write_string_pad(&rpcbuf, output->name); /* indeed 0-terminated */ - rep.length += x_rpcbuf_wsize_units(&rpcbuf); - if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); swapl(&rep.timestamp); swapl(&rep.crtc); swapl(&rep.mmWidth); @@ -516,8 +509,7 @@ ProcRRGetOutputInfo(ClientPtr client) swaps(&rep.nameLength); } - WriteToClient(client, sizeof(xRRGetOutputInfoReply), &rep); - WriteRpcbufToClient(client, &rpcbuf); + X_SEND_REPLY_WITH_RPCBUF(client, rep, rpcbuf); return Success; } diff --git a/randr/rrproperty.c b/randr/rrproperty.c index 6bcbcf738..9018ab9b8 100644 --- a/randr/rrproperty.c +++ b/randr/rrproperty.c @@ -434,20 +434,14 @@ ProcRRListOutputProperties(ClientPtr client) return BadAlloc; xRRListOutputPropertiesReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = x_rpcbuf_wsize_units(&rpcbuf), .nAtoms = numProps }; if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); swaps(&rep.nAtoms); } - WriteToClient(client, sizeof(xRRListOutputPropertiesReply), &rep); - WriteRpcbufToClient(client, &rpcbuf); + X_SEND_REPLY_WITH_RPCBUF(client, rep, rpcbuf); return Success; } @@ -472,21 +466,12 @@ ProcRRQueryOutputProperty(ClientPtr client) return BadAlloc; xRRQueryOutputPropertyReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = x_rpcbuf_wsize_units(&rpcbuf), .pending = prop->is_pending, .range = prop->range, .immutable = prop->immutable }; - if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - } - - WriteToClient(client, sizeof(xRRQueryOutputPropertyReply), &rep); - WriteRpcbufToClient(client, &rpcbuf); + X_SEND_REPLY_WITH_RPCBUF(client, rep, rpcbuf); return Success; } diff --git a/randr/rrproviderproperty.c b/randr/rrproviderproperty.c index a53938c8f..58a5c9f05 100644 --- a/randr/rrproviderproperty.c +++ b/randr/rrproviderproperty.c @@ -531,10 +531,6 @@ ProcRRGetProviderProperty(ClientPtr client) RRPropertyValuePtr prop_value; unsigned long n, len, ind; RRProviderPtr provider; - xRRGetProviderPropertyReply reply = { - .type = X_Reply, - .sequenceNumber = client->sequence - }; REQUEST_SIZE_MATCH(xRRGetProviderPropertyReq); if (stuff->delete) @@ -559,13 +555,12 @@ ProcRRGetProviderProperty(ClientPtr client) if (prop->propertyName == stuff->property) break; - if (!prop) { - if (client->swapped) { - swaps(&reply.sequenceNumber); - } - WriteToClient(client, sizeof(xRRGetProviderPropertyReply), &reply); - return Success; - } + x_rpcbuf_t rpcbuf = { .swapped = client->swapped, .err_clear = TRUE }; + + xRRGetProviderPropertyReply reply = { 0 }; + + if (!prop) + goto sendout; if (prop->immutable && stuff->delete) return BadAccess; @@ -583,12 +578,11 @@ ProcRRGetProviderProperty(ClientPtr client) reply.format = prop_value->format; reply.propertyType = prop_value->type; if (client->swapped) { - swaps(&reply.sequenceNumber); swapl(&reply.propertyType); swapl(&reply.bytesAfter); } - WriteToClient(client, sizeof(xRRGetProviderPropertyReply), &reply); - return Success; + + goto sendout; } /* @@ -609,7 +603,6 @@ ProcRRGetProviderProperty(ClientPtr client) reply.bytesAfter = n - (ind + len); reply.format = prop_value->format; - reply.length = bytes_to_int32(len); if (prop_value->format) reply.nItems = len / (prop_value->format / 8); reply.propertyType = prop_value->type; @@ -627,15 +620,11 @@ ProcRRGetProviderProperty(ClientPtr client) } if (client->swapped) { - swaps(&reply.sequenceNumber); - swapl(&reply.length); swapl(&reply.propertyType); swapl(&reply.bytesAfter); swapl(&reply.nItems); } - x_rpcbuf_t rpcbuf = { .swapped = client->swapped, .err_clear = TRUE }; - if (len) { const char *dataptr = ((char*)prop_value->data) + ind; switch (prop_value->format) { @@ -654,12 +643,12 @@ ProcRRGetProviderProperty(ClientPtr client) if (rpcbuf.error) return BadAlloc; - WriteToClient(client, sizeof(reply), &reply); - WriteRpcbufToClient(client, &rpcbuf); - if (stuff->delete && (reply.bytesAfter == 0)) { /* delete the Property */ *prev = prop->next; RRDestroyProviderProperty(prop); } + +sendout: + X_SEND_REPLY_WITH_RPCBUF(client, reply, rpcbuf); return Success; }