Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2023-11-30 14:23:30 +0300
committerFelix Fietkau <nbd@nbd.name>2023-11-30 14:29:40 +0300
commit40acbe34632b8e4e860fe41bb14ab5d7d5c9cfe9 (patch)
tree5f89079b27bc2cc73cd97515eb9f2df2c1385459 /udebug-remote.c
parente84c000c4756ae3d0aa80b2c66ec43cf7fc416c4 (diff)
udebug: wait for response after buffer add/remove
Fixes a race condition where freeing a buffer and immediately re-allocating and adding it would fail to pass the file descriptor to udebugd Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'udebug-remote.c')
-rw-r--r--udebug-remote.c29
1 files changed, 2 insertions, 27 deletions
diff --git a/udebug-remote.c b/udebug-remote.c
index f13f633..0b797f9 100644
--- a/udebug-remote.c
+++ b/udebug-remote.c
@@ -17,31 +17,6 @@
*/
#include "udebug-priv.h"
-static struct udebug_client_msg *
-send_and_wait(struct udebug *ctx, struct udebug_client_msg *msg, int *rfd)
-{
- int type = msg->type;
- int fd = -1;
-
- udebug_send_msg(ctx, msg, NULL, -1);
-
- do {
- if (fd >= 0)
- close(fd);
- fd = -1;
- msg = __udebug_poll(ctx, &fd, true);
- } while (msg && msg->type != type);
- if (!msg)
- return NULL;
-
- if (rfd)
- *rfd = fd;
- else if (fd >= 0)
- close(fd);
-
- return msg;
-}
-
static int
udebug_remote_get_handle(struct udebug *ctx)
{
@@ -53,7 +28,7 @@ udebug_remote_get_handle(struct udebug *ctx)
if (ctx->poll_handle >= 0 || !udebug_is_connected(ctx))
return 0;
- msg = send_and_wait(ctx, &send_msg, NULL);
+ msg = udebug_send_and_wait(ctx, &send_msg, NULL);
if (!msg)
return -1;
@@ -82,7 +57,7 @@ int udebug_remote_buf_map(struct udebug *ctx, struct udebug_remote_buf *rb, uint
if (rb->buf.data || !udebug_is_connected(ctx))
return -1;
- msg = send_and_wait(ctx, &send_msg, &fd);
+ msg = udebug_send_and_wait(ctx, &send_msg, &fd);
if (!msg || fd < 0)
return -1;