From cc83dac60da6c4960a9e740ac5a74cde8197b685 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Thu, 31 Aug 2017 14:31:56 +0900 Subject: [PATCH] tdm-monitor: fix big message issue Wayland has the 4096 message size restriction. So if tdm debug message is bigger than that, the message will be devided. Change-Id: I3ba57801bb149c489577ad1adff2c8befc69e69f --- client/tdm_monitor.c | 32 ++++++++++++++++++++++++++------ protocol/tdm.xml | 4 +++- src/tdm_macro.h | 4 ++++ src/tdm_server.c | 27 +++++++++++++++++++++++---- src/tdm_vblank.c | 10 ++++++---- 5 files changed, 62 insertions(+), 15 deletions(-) diff --git a/client/tdm_monitor.c b/client/tdm_monitor.c index fe69cce..cdfa1f7 100644 --- a/client/tdm_monitor.c +++ b/client/tdm_monitor.c @@ -54,20 +54,36 @@ typedef struct _tdm_monitor_info { struct wl_display *display; struct wl_registry *registry; struct wl_tdm *tdm; + + struct { + int done; + char message[TDM_SERVER_REPLY_MSG_LEN]; + char *m; + int len; + int *l; + } debug; } tdm_monitor_info; static tdm_monitor_info td_info; -static int done; static void -_tdm_monitor_cb_debug_done(void *data, struct wl_tdm *wl_tdm, const char *message) +_tdm_monitor_cb_debug_message(void *data, struct wl_tdm *wl_tdm, const char *message) { - printf("%s", message); + tdm_monitor_info *info = data; + TDM_SNPRINTF(info->debug.m, info->debug.l, "%s", message); +} - done = 1; +static void +_tdm_monitor_cb_debug_done(void *data, struct wl_tdm *wl_tdm) +{ + tdm_monitor_info *info = data; + info->debug.done = 1; + *(info->debug.m) = '\0'; + printf("%s", info->debug.message); } static const struct wl_tdm_listener tdm_monitor_listener = { + _tdm_monitor_cb_debug_message, _tdm_monitor_cb_debug_done, }; @@ -137,11 +153,15 @@ main(int argc, char ** argv) for (i = 0; i < argc; i++) TDM_SNPRINTF(str_buf, len_buf, "%s ", argv[i]); - done = 0; + info->debug.done = 0; + info->debug.message[0] = '\0'; + info->debug.len = sizeof(info->debug.message); + info->debug.m = info->debug.message; + info->debug.l = &info->debug.len; wl_tdm_debug(info->tdm, options); - while (!done && ret >= 0) + while (!info->debug.done && ret >= 0) ret = wl_display_dispatch(info->display); if (info->tdm) diff --git a/protocol/tdm.xml b/protocol/tdm.xml index bd5ed89..47e6536 100644 --- a/protocol/tdm.xml +++ b/protocol/tdm.xml @@ -8,10 +8,12 @@ TDM uses the wayland protocol to communicate between tdm client and tdm server. - + + + diff --git a/src/tdm_macro.h b/src/tdm_macro.h index 6da02b4..504315a 100644 --- a/src/tdm_macro.h +++ b/src/tdm_macro.h @@ -49,6 +49,7 @@ extern "C" { #endif #define TDM_SERVER_REPLY_MSG_LEN 8192 +#define TDM_DEBUG_REPLY_MSG_LEN 2048 #undef EXTERN #undef DEPRECATED @@ -138,6 +139,9 @@ extern "C" { #define TDM_NOT_DEFINED_VALUE (-1) #define TDM_FRONT_VALUE(n) (((n) > 0) ? (n) : TDM_NOT_DEFINED_VALUE) +#define TDM_MAX(x, y) (((x) > (y)) ? (x) : (y)) +#define TDM_MIN(x, y) (((x) < (y)) ? (x) : (y)) + #define TDM_TIME(sec, usec) ((double)(sec) + ((double)(usec)) / 1000000.0) #define TDM_TIME_SEC(time) ((unsigned int)(time)) #define TDM_TIME_USEC(time) (unsigned int)(((time) - (unsigned int)(time)) * 1000000.0) diff --git a/src/tdm_server.c b/src/tdm_server.c index bd9cd9f..b69926b 100644 --- a/src/tdm_server.c +++ b/src/tdm_server.c @@ -546,19 +546,38 @@ _tdm_server_cb_debug(struct wl_client *client, struct wl_resource *resource, con tdm_private_server *private_server = wl_resource_get_user_data(resource); tdm_private_loop *private_loop = private_server->private_loop; char message[TDM_SERVER_REPLY_MSG_LEN]; - int size = sizeof(message); + char *m; + int len = sizeof(message), size; uid_t uid; wl_client_get_credentials(client, NULL, &uid, NULL); if (uid != 0) { - snprintf(message, size, "tdm-monitor: SHOULD be a superuser.\n"); + snprintf(message, len, "tdm-monitor: SHOULD be a superuser.\n"); TDM_ERR("%s", message); } else { - tdm_monitor_server_command(private_loop->dpy, options, message, &size); + tdm_monitor_server_command(private_loop->dpy, options, message, &len); } - wl_tdm_send_debug_done(resource, message); + size = sizeof(message) - len; + m = message; + + wl_client_flush(wl_resource_get_client(resource)); + + while (size > 0) { + char buffer[TDM_DEBUG_REPLY_MSG_LEN]; + int copylen = TDM_MIN(size, sizeof(buffer) - 1); + + strncpy(buffer, m, copylen); + m += copylen; + size -= copylen; + + buffer[copylen] = '\0'; + + wl_tdm_send_debug_message(resource, buffer); + } + + wl_tdm_send_debug_done(resource); } static void diff --git a/src/tdm_vblank.c b/src/tdm_vblank.c index 0cff134..97deab5 100644 --- a/src/tdm_vblank.c +++ b/src/tdm_vblank.c @@ -1196,13 +1196,15 @@ tdm_vblank_get_vblank_list_information(tdm_display *dpy, char *reply, int *len) pthread_mutex_lock(&valid_list_lock); LIST_FOR_EACH_ENTRY(v, &valid_vblank_list, valid_link) { - struct wl_client *client = wl_resource_get_client(v->resource); const char *proc_name = NULL; pid_t pid = 0; - if (client) { - wl_client_get_credentials(client, &pid, NULL, NULL); - proc_name = tdm_server_get_client_name(pid); + if (v->resource) { + struct wl_client *client = wl_resource_get_client(v->resource); + if (client) { + wl_client_get_credentials(client, &pid, NULL, NULL); + proc_name = tdm_server_get_client_name(pid); + } } TDM_SNPRINTF(reply, len, "%-12s %u %u %d %u %s (pid: %u)\n", -- 2.7.4