From patchwork Wed Aug 29 19:53:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 180760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0E9BD2C0116 for ; Thu, 30 Aug 2012 06:13:12 +1000 (EST) Received: from localhost ([::1]:59286 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6oK5-00076L-Ef for incoming@patchwork.ozlabs.org; Wed, 29 Aug 2012 15:53:09 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6oJW-0005Ya-Q3 for qemu-devel@nongnu.org; Wed, 29 Aug 2012 15:52:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T6oJV-0004LG-AQ for qemu-devel@nongnu.org; Wed, 29 Aug 2012 15:52:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64670) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6oJV-0004L5-2Q for qemu-devel@nongnu.org; Wed, 29 Aug 2012 15:52:33 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7TJqWKA012555 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 29 Aug 2012 15:52:32 -0400 Received: from localhost (ovpn-113-104.phx2.redhat.com [10.3.113.104]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q7TJqVVV009352; Wed, 29 Aug 2012 15:52:31 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 29 Aug 2012 16:53:01 -0300 Message-Id: <1346269986-13539-5-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1346269986-13539-1-git-send-email-lcapitulino@redhat.com> References: <1346269986-13539-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: alevy@redhat.com Subject: [Qemu-devel] [PATCH 4/9] vga: ppm_save(): add error handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Luiz Capitulino --- hw/blizzard.c | 2 +- hw/qxl.c | 2 +- hw/vga.c | 32 +++++++++++++++++++++++++------- hw/vga_int.h | 3 ++- hw/vmware_vga.c | 2 +- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/hw/blizzard.c b/hw/blizzard.c index a2b9053..d1c9d81 100644 --- a/hw/blizzard.c +++ b/hw/blizzard.c @@ -939,7 +939,7 @@ static void blizzard_screen_dump(void *opaque, const char *filename, blizzard_update_display(opaque); if (s && ds_get_data(s->state)) - ppm_save(filename, s->state->surface); + ppm_save(filename, s->state->surface, errp); } #define DEPTH 8 diff --git a/hw/qxl.c b/hw/qxl.c index 46a929d..bae5758 100644 --- a/hw/qxl.c +++ b/hw/qxl.c @@ -1605,7 +1605,7 @@ static void qxl_hw_screen_dump(void *opaque, const char *filename, bool cswitch, case QXL_MODE_COMPAT: case QXL_MODE_NATIVE: qxl_render_update(qxl); - ppm_save(filename, qxl->ssd.ds->surface); + ppm_save(filename, qxl->ssd.ds->surface, errp); break; case QXL_MODE_VGA: vga->screen_dump(vga, filename, cswitch, errp); diff --git a/hw/vga.c b/hw/vga.c index dd703cf..80299ea 100644 --- a/hw/vga.c +++ b/hw/vga.c @@ -2390,7 +2390,7 @@ void vga_init_vbe(VGACommonState *s, MemoryRegion *system_memory) /********************************************************/ /* vga screen dump */ -int ppm_save(const char *filename, struct DisplaySurface *ds) +void ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp) { FILE *f; uint8_t *d, *d1; @@ -2402,10 +2402,16 @@ int ppm_save(const char *filename, struct DisplaySurface *ds) trace_ppm_save(filename, ds); f = fopen(filename, "wb"); - if (!f) - return -1; - fprintf(f, "P6\n%d %d\n%d\n", - ds->width, ds->height, 255); + if (!f) { + error_setg(errp, "failed to open file '%s': %s", filename, + strerror(errno)); + return; + } + ret = fprintf(f, "P6\n%d %d\n%d\n", ds->width, ds->height, 255); + if (ret < 0) { + linebuf = NULL; + goto write_err; + } linebuf = g_malloc(ds->width * 3); d1 = ds->data; for(y = 0; y < ds->height; y++) { @@ -2426,12 +2432,24 @@ int ppm_save(const char *filename, struct DisplaySurface *ds) d += ds->pf.bytes_per_pixel; } d1 += ds->linesize; + clearerr(f); ret = fwrite(linebuf, 1, pbuf - linebuf, f); (void)ret; + if (ferror(f)) { + goto write_err; + } } + +out: g_free(linebuf); fclose(f); - return 0; + return; + +write_err: + error_setg(errp, "failed to write to file '%s': %s", filename, + strerror(errno)); + unlink(filename); + goto out; } /* save the vga display in a PPM image even if no display is @@ -2445,5 +2463,5 @@ static void vga_screen_dump(void *opaque, const char *filename, bool cswitch, vga_invalidate_display(s); } vga_hw_update(); - ppm_save(filename, s->ds->surface); + ppm_save(filename, s->ds->surface, errp); } diff --git a/hw/vga_int.h b/hw/vga_int.h index 8938093..330a32f 100644 --- a/hw/vga_int.h +++ b/hw/vga_int.h @@ -23,6 +23,7 @@ */ #include +#include "error.h" #include "memory.h" #define ST01_V_RETRACE 0x08 @@ -204,7 +205,7 @@ void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val); uint32_t vga_mem_readb(VGACommonState *s, target_phys_addr_t addr); void vga_mem_writeb(VGACommonState *s, target_phys_addr_t addr, uint32_t val); void vga_invalidate_scanlines(VGACommonState *s, int y1, int y2); -int ppm_save(const char *filename, struct DisplaySurface *ds); +void ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp); int vga_ioport_invalid(VGACommonState *s, uint32_t addr); void vga_init_vbe(VGACommonState *s, MemoryRegion *address_space); diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c index 29750e1..b68e883 100644 --- a/hw/vmware_vga.c +++ b/hw/vmware_vga.c @@ -1015,7 +1015,7 @@ static void vmsvga_screen_dump(void *opaque, const char *filename, bool cswitch, if (s->depth == 32) { DisplaySurface *ds = qemu_create_displaysurface_from(s->width, s->height, 32, ds_get_linesize(s->vga.ds), s->vga.vram_ptr); - ppm_save(filename, ds); + ppm_save(filename, ds, errp); g_free(ds); } }