[Spice-devel] [PATCH] [vd_agent] close the file handler if file_size = 0

2014-08-09 Thread Cody Chan
After dragging a zero-size file, then I open it in guest,
I get a warning message box which says:
 "the process cannot access the file because it is being used by another
process".
And I get to know the file is occupied by vdagent. Now we look back the
process:

a) When dragging a zero-size file, spice-gtk gets the name and size, then
sends
the message to vd_agent with VD_AGENT_FILE_XFER_START
b) vd_agent receives and parsers the message, then gets file name and size,
creates(open)
the file and gets the handler, at last, sends
VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA
c) spice-gtk receives the VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA message,
the sends data with VD_AGENT_FILE_XFER_DATA
d) vd_agent receives and writes data to the file opened
e) After finishing the writing, vd_agent closes the handler

But in step c, we take a look the code:
//spice-channel.c
>static void file_xfer_read_cb(...)
>{
>//...
>count = g_input_stream_read_finish(G_INPUT_STREAM(task->file_stream),
res, &error);
>if (count > 0) {
>task->read_bytes += count;
>file_xfer_queue(task, count);
>file_xfer_flush_async(channel, task->cancellable,
>  file_xfer_data_flushed_cb, task);
>task->pending = TRUE;
>} else if (error) {
>VDAgentFileXferStatusMessage msg = {
>.id = task->id,
>.result = VD_AGENT_FILE_XFER_STATUS_ERROR,
>};
>agent_msg_queue_many(task->channel, VD_AGENT_FILE_XFER_STATUS,
> &msg, sizeof(msg), NULL);
>spice_channel_wakeup(SPICE_CHANNEL(task->channel), FALSE);
>file_xfer_completed(task, error);
>}
>}

If count == 0, then it does nothing!
Then vd_agent will receive nothing after opening a file, and always occupy
the file.
Here we close the file if file_size = 0, even though it doesn't make sense
to send
a zero-size file.

​
---
 vdagent/file_xfer.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
index 34a9ee6..17d842e 100644
--- a/vdagent/file_xfer.cpp
+++ b/vdagent/file_xfer.cpp
@@ -89,6 +89,10 @@ void FileXfer::handle_start(VDAgentFileXferStartMessage*
start,
 vd_printf("failed creating %s %lu", file_path, GetLastError());
 return;
 }
+if (file_size == 0){
+CloseHandle(handle);
+return;
+}
 task = new FileXferTask(handle, file_size, file_path);
 _tasks[start->id] = task;
 status->result = VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA;
--
1.9.3

-- 
QSBDT0RFUiBGUk9NIFJJRVNUIE9GIENUU0VV
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH xf86-qxl] drm: fail gracefuly on monitor resize

2014-08-09 Thread Alon Levy
On 08/08/2014 08:35 PM, Marc-André Lureau wrote:
> If drmModeSetCrtc() failed, try to fallback to previous working
> configuration.

ACK

> 
> Related to:
> https://bugzilla.redhat.com/show_bug.cgi?id=1127552
> ---
>  src/qxl_drmmode.c | 11 +++
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/src/qxl_drmmode.c b/src/qxl_drmmode.c
> index f9eca5f..42347e6 100644
> --- a/src/qxl_drmmode.c
> +++ b/src/qxl_drmmode.c
> @@ -214,11 +214,13 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr 
> mode,
>   }
>   ret = drmModeSetCrtc(drmmode->fd, 
> drmmode_crtc->mode_crtc->crtc_id,
>fb_id, x, y, output_ids, output_count, 
> &kmode);
> - if (ret)
> + if (ret) {
>   xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
>  "failed to set mode: %s", strerror(-ret));
> - else
> + return FALSE;
> + } else {
>   ret = TRUE;
> + }
>  
>   if (crtc->scrn->pScreen)
>   xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen);
> @@ -825,8 +827,9 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int 
> height)
>   xf86CrtcPtr crtc = xf86_config->crtc[i];
>   if (!crtc->enabled)
>   continue;
> - drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation,
> -crtc->x, crtc->y);
> + if (!drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation,
> +crtc->x, crtc->y))
> +goto fail;
>   }
>  
>   {
> 

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel