[Spice-devel,v2,02/11] server/red_worker: dump_bitmap: add surface_id to the bitmap file name

Submitted by Yonit Halperin on April 17, 2012, 10:12 a.m.

Details

Message ID 1334657556-5083-2-git-send-email-yhalperi@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Yonit Halperin April 17, 2012, 10:12 a.m.
Also replaced sprintf with snprintf
---
 server/red_worker.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/red_worker.c b/server/red_worker.c
index 5350195..99a8948 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -1014,7 +1014,7 @@  static void cursor_channel_client_release_item_after_push(CursorChannelClient *c
 static void red_wait_pipe_item_sent(RedChannelClient *rcc, PipeItem *item);
 
 #ifdef DUMP_BITMAP
-static void dump_bitmap(RedWorker *worker, SpiceBitmap *bitmap, uint32_t group_id);
+static void dump_bitmap(RedWorker *worker, SpiceBitmap *bitmap, uint32_t group_id, int surface_id);
 #endif
 
 /*
@@ -6368,7 +6368,9 @@  static FillBitsType fill_bits(DisplayChannelClient *dcc, SpiceMarshaller *m,
     case SPICE_IMAGE_TYPE_BITMAP: {
         SpiceBitmap *bitmap = &image.u.bitmap;
 #ifdef DUMP_BITMAP
-        dump_bitmap(display_channel->common.worker, &simage->u.bitmap, drawable->group_id);
+        dump_bitmap(display_channel->common.worker, &simage->u.bitmap,
+                    drawable->group_id,
+                    drawable->surface_id);
 #endif
         /* Images must be added to the cache only after they are compressed
            in order to prevent starvation in the client between pixmap_cache and
@@ -11235,12 +11237,12 @@  static void dump_line(FILE *f, uint8_t* line, uint16_t n_pixel_bits, int width,
 }
 
 #define RAM_PATH "/tmp/tmpfs"
-
-static void dump_bitmap(RedWorker *worker, SpiceBitmap *bitmap, uint32_t group_id)
+#define DUMP_BITMAP_FILE_NAME_LEN 200
+static void dump_bitmap(RedWorker *worker, SpiceBitmap *bitmap, uint32_t group_id, int surface_id)
 {
     static uint32_t file_id = 0;
+    static char file_str[DUMP_BITMAP_FILE_NAME_LEN];
 
-    char file_str[200];
     int rgb = TRUE;
     uint16_t n_pixel_bits;
     SpicePalette *plt = NULL;
@@ -11303,7 +11305,7 @@  static void dump_bitmap(RedWorker *worker, SpiceBitmap *bitmap, uint32_t group_i
     file_size = bitmap_data_offset + (bitmap->y * row_size);
 
     id = ++file_id;
-    sprintf(file_str, "%s/%u.bmp", RAM_PATH, id);
+    sprintf(file_str, DUMP_BITMAP_FILE_NAME_LEN, "%s/%u-%d.bmp", RAM_PATH, id, surface_id);
 
     f = fopen(file_str, "wb");
     if (!f) {

Comments

On 04/17/2012 01:12 PM, Yonit Halperin wrote:
> Also replaced sprintf with snprintf
> ---
>   server/red_worker.c |   14 ++++++++------
>   1 files changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/server/red_worker.c b/server/red_worker.c
> index 5350195..99a8948 100644
> --- a/server/red_worker.c
> +++ b/server/red_worker.c
> @@ -1014,7 +1014,7 @@ static void cursor_channel_client_release_item_after_push(CursorChannelClient *c
>   static void red_wait_pipe_item_sent(RedChannelClient *rcc, PipeItem *item);
>
>   #ifdef DUMP_BITMAP
> -static void dump_bitmap(RedWorker *worker, SpiceBitmap *bitmap, uint32_t group_id);
> +static void dump_bitmap(RedWorker *worker, SpiceBitmap *bitmap, uint32_t group_id, int surface_id);
>   #endif
>
>   /*
> @@ -6368,7 +6368,9 @@ static FillBitsType fill_bits(DisplayChannelClient *dcc, SpiceMarshaller *m,
>       case SPICE_IMAGE_TYPE_BITMAP: {
>           SpiceBitmap *bitmap =&image.u.bitmap;
>   #ifdef DUMP_BITMAP
> -        dump_bitmap(display_channel->common.worker,&simage->u.bitmap, drawable->group_id);
> +        dump_bitmap(display_channel->common.worker,&simage->u.bitmap,
> +                    drawable->group_id,
> +                    drawable->surface_id);
>   #endif
>           /* Images must be added to the cache only after they are compressed
>              in order to prevent starvation in the client between pixmap_cache and
> @@ -11235,12 +11237,12 @@ static void dump_line(FILE *f, uint8_t* line, uint16_t n_pixel_bits, int width,
>   }
>
>   #define RAM_PATH "/tmp/tmpfs"
> -
> -static void dump_bitmap(RedWorker *worker, SpiceBitmap *bitmap, uint32_t group_id)
> +#define DUMP_BITMAP_FILE_NAME_LEN 200
> +static void dump_bitmap(RedWorker *worker, SpiceBitmap *bitmap, uint32_t group_id, int surface_id)
>   {
>       static uint32_t file_id = 0;
> +    static char file_str[DUMP_BITMAP_FILE_NAME_LEN];
>
> -    char file_str[200];
>       int rgb = TRUE;
>       uint16_t n_pixel_bits;
>       SpicePalette *plt = NULL;
> @@ -11303,7 +11305,7 @@ static void dump_bitmap(RedWorker *worker, SpiceBitmap *bitmap, uint32_t group_i
>       file_size = bitmap_data_offset + (bitmap->y * row_size);
>
>       id = ++file_id;
> -    sprintf(file_str, "%s/%u.bmp", RAM_PATH, id);
> +    sprintf(file_str, DUMP_BITMAP_FILE_NAME_LEN, "%s/%u-%d.bmp", RAM_PATH, id, surface_id);
oops, forgot to s/sprintf/snprintf (and to recompile with DUMP_BITMAP...)

Yonit.
>
>       f = fopen(file_str, "wb");
>       if (!f) {