tdm-monitor: fix big message issue 36/147136/1
authorBoram Park <boram1288.park@samsung.com>
Thu, 31 Aug 2017 05:31:56 +0000 (14:31 +0900)
committerBoram Park <boram1288.park@samsung.com>
Fri, 1 Sep 2017 06:21:27 +0000 (15:21 +0900)
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
protocol/tdm.xml
src/tdm_macro.h
src/tdm_server.c
src/tdm_vblank.c

index fe69cce..cdfa1f7 100644 (file)
@@ -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)
index bd5ed89..47e6536 100644 (file)
@@ -8,10 +8,12 @@
       TDM uses the wayland protocol to communicate between tdm client and tdm server.
         </description>
 
-        <event name="debug_done">
+        <event name="debug_message">
             <arg name="message" type="string"/>
         </event>
 
+        <event name="debug_done" />
+
         <request name="debug">
             <arg name="options" type="string" summary="debug options"/>
         </request>
index 6da02b4..504315a 100644 (file)
@@ -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)
index bd9cd9f..b69926b 100644 (file)
@@ -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
index 0cff134..97deab5 100644 (file)
@@ -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",