* [Qemu-devel] [PATCH 01/15] Introduce qemu_write_full() @ 2010-01-02 3:45 Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 02/15] posix-aio-compat.c: fix warning with _FORTIFY_SOURCE Kirill A. Shutemov 2010-01-02 10:34 ` [Qemu-devel] Re: [PATCH 01/15] Introduce qemu_write_full() Paolo Bonzini 0 siblings, 2 replies; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov A variant of write(2) which handles partial write. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- osdep.c | 27 +++++++++++++++++++++++++++ qemu-common.h | 2 ++ 2 files changed, 29 insertions(+), 0 deletions(-) diff --git a/osdep.c b/osdep.c index e4836e7..8ae48fe 100644 --- a/osdep.c +++ b/osdep.c @@ -243,6 +243,33 @@ int qemu_open(const char *name, int flags, ...) return ret; } +/* + * A variant of write(2) which handles partial write. + * + * Return the number of bytes transferred. + * Set errno if fewer than `count' bytes are written. + */ +size_t qemu_write_full(int fd, const void *buf, size_t count) +{ + ssize_t ret; + size_t total = 0; + + while (count) { + ret = write(fd, buf, count); + if (ret < 0) { + if (errno == EINTR) + continue; + break; + } + + count -= ret; + buf += ret; + total += ret; + } + + return total; +} + #ifndef _WIN32 /* * Creates a pipe with FD_CLOEXEC set on both file descriptors diff --git a/qemu-common.h b/qemu-common.h index 8630f8c..7231348 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -160,6 +160,8 @@ void qemu_mutex_lock_iothread(void); void qemu_mutex_unlock_iothread(void); int qemu_open(const char *name, int flags, ...); +size_t qemu_write_full(int fd, const void *buf, size_t count) + __attribute__ ((warn_unused_result)); void qemu_set_cloexec(int fd); #ifndef _WIN32 -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 02/15] posix-aio-compat.c: fix warning with _FORTIFY_SOURCE 2010-01-02 3:45 [Qemu-devel] [PATCH 01/15] Introduce qemu_write_full() Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 03/15] block/cow.c: fix warnings " Kirill A. Shutemov 2010-01-02 10:34 ` [Qemu-devel] Re: [PATCH 01/15] Introduce qemu_write_full() Paolo Bonzini 1 sibling, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov CC posix-aio-compat.o cc1: warnings being treated as errors posix-aio-compat.c: In function 'aio_signal_handler': posix-aio-compat.c:505: error: ignoring return value of 'write', declared with attribute warn_unused_result make: *** [posix-aio-compat.o] Error 1 Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- posix-aio-compat.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/posix-aio-compat.c b/posix-aio-compat.c index dc14f53..1272e84 100644 --- a/posix-aio-compat.c +++ b/posix-aio-compat.c @@ -501,8 +501,11 @@ static void aio_signal_handler(int signum) { if (posix_aio_state) { char byte = 0; + int ret; - write(posix_aio_state->wfd, &byte, sizeof(byte)); + ret = write(posix_aio_state->wfd, &byte, sizeof(byte)); + if (ret < 0 && (errno != EINTR && errno != EAGAIN)) + die("write()"); } qemu_service_io(); -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 03/15] block/cow.c: fix warnings with _FORTIFY_SOURCE 2010-01-02 3:45 ` [Qemu-devel] [PATCH 02/15] posix-aio-compat.c: fix warning with _FORTIFY_SOURCE Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 04/15] block/qcow.c: " Kirill A. Shutemov 0 siblings, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov CC block/cow.o cc1: warnings being treated as errors block/cow.c: In function 'cow_create': block/cow.c:251: error: ignoring return value of 'write', declared with attribute warn_unused_result block/cow.c:253: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result make: *** [block/cow.o] Error 1 Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- block/cow.c | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-) diff --git a/block/cow.c b/block/cow.c index a70854e..ba07b97 100644 --- a/block/cow.c +++ b/block/cow.c @@ -209,6 +209,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options) struct stat st; int64_t image_sectors = 0; const char *image_filename = NULL; + int ret; /* Read out options */ while (options && options->name) { @@ -248,11 +249,23 @@ static int cow_create(const char *filename, QEMUOptionParameter *options) } cow_header.sectorsize = cpu_to_be32(512); cow_header.size = cpu_to_be64(image_sectors * 512); - write(cow_fd, &cow_header, sizeof(cow_header)); + ret = qemu_write_full(cow_fd, &cow_header, sizeof(cow_header)); + if (ret != sizeof(cow_header)) { + ret = -errno; + goto exit; + } + /* resize to include at least all the bitmap */ - ftruncate(cow_fd, sizeof(cow_header) + ((image_sectors + 7) >> 3)); + ret = ftruncate(cow_fd, sizeof(cow_header) + ((image_sectors + 7) >> 3)); + if (ret) { + ret = -errno; + goto exit; + } + + ret = 0; +exit: close(cow_fd); - return 0; + return ret; } static void cow_flush(BlockDriverState *bs) -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 04/15] block/qcow.c: fix warnings with _FORTIFY_SOURCE 2010-01-02 3:45 ` [Qemu-devel] [PATCH 03/15] block/cow.c: fix warnings " Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 05/15] block/vmdk.o: " Kirill A. Shutemov 0 siblings, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov CC block/qcow.o cc1: warnings being treated as errors block/qcow.c: In function 'qcow_create': block/qcow.c:804: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow.c:806: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow.c:811: error: ignoring return value of 'write', declared with attribute warn_unused_result make: *** [block/qcow.o] Error 1 Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- block/qcow.c | 25 +++++++++++++++++++++---- 1 files changed, 21 insertions(+), 4 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 7fc85ae..28cc092 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -750,6 +750,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options) int64_t total_size = 0; const char *backing_file = NULL; int flags = 0; + int ret; /* Read out options */ while (options && options->name) { @@ -801,17 +802,33 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options) } /* write all the data */ - write(fd, &header, sizeof(header)); + ret = qemu_write_full(fd, &header, sizeof(header)); + if (ret != sizeof(header)) { + ret = -errno; + goto exit; + } + if (backing_file) { - write(fd, backing_file, backing_filename_len); + ret = qemu_write_full(fd, backing_file, backing_filename_len); + if (ret != backing_filename_len) { + ret = -errno; + goto exit; + } } lseek(fd, header_size, SEEK_SET); tmp = 0; for(i = 0;i < l1_size; i++) { - write(fd, &tmp, sizeof(tmp)); + ret = qemu_write_full(fd, &tmp, sizeof(tmp)); + if (ret != sizeof(tmp)) { + ret = -errno; + goto exit; + } } + + ret = 0; +exit: close(fd); - return 0; + return ret; } static int qcow_make_empty(BlockDriverState *bs) -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 05/15] block/vmdk.o: fix warnings with _FORTIFY_SOURCE 2010-01-02 3:45 ` [Qemu-devel] [PATCH 04/15] block/qcow.c: " Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 06/15] block/vvfat.c: " Kirill A. Shutemov 0 siblings, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov CC block/vmdk.o cc1: warnings being treated as errors block/vmdk.c: In function 'vmdk_snapshot_create': block/vmdk.c:236: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result block/vmdk.c: In function 'vmdk_create': block/vmdk.c:775: error: ignoring return value of 'write', declared with attribute warn_unused_result block/vmdk.c:776: error: ignoring return value of 'write', declared with attribute warn_unused_result block/vmdk.c:778: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result block/vmdk.c:784: error: ignoring return value of 'write', declared with attribute warn_unused_result block/vmdk.c:790: error: ignoring return value of 'write', declared with attribute warn_unused_result block/vmdk.c:807: error: ignoring return value of 'write', declared with attribute warn_unused_result make: *** [block/vmdk.o] Error 1 Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- block/vmdk.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 40 insertions(+), 10 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 4e48622..58fc04b 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -233,7 +233,8 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) memset(&header, 0, sizeof(header)); memcpy(&header,&hdr[4], sizeof(header)); // skip the VMDK4_MAGIC - ftruncate(snp_fd, header.grain_offset << 9); + if (ftruncate(snp_fd, header.grain_offset << 9)) + goto fail; /* the descriptor offset = 0x200 */ if (lseek(p_fd, 0x200, SEEK_SET) == -1) goto fail; @@ -716,6 +717,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options) int64_t total_size = 0; const char *backing_file = NULL; int flags = 0; + int ret; // Read out options while (options && options->name) { @@ -772,22 +774,44 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options) header.check_bytes[3] = 0xa; /* write all the data */ - write(fd, &magic, sizeof(magic)); - write(fd, &header, sizeof(header)); + ret = qemu_write_full(fd, &magic, sizeof(magic)); + if (ret != sizeof(magic)) { + ret = -errno; + goto exit; + } + ret = qemu_write_full(fd, &header, sizeof(header)); + if (ret != sizeof(header)) { + ret = -errno; + goto exit; + } - ftruncate(fd, header.grain_offset << 9); + ret = ftruncate(fd, header.grain_offset << 9); + if (ret < 0) { + ret = -errno; + goto exit; + } /* write grain directory */ lseek(fd, le64_to_cpu(header.rgd_offset) << 9, SEEK_SET); for (i = 0, tmp = header.rgd_offset + gd_size; - i < gt_count; i++, tmp += gt_size) - write(fd, &tmp, sizeof(tmp)); + i < gt_count; i++, tmp += gt_size) { + ret = qemu_write_full(fd, &tmp, sizeof(tmp)); + if (ret != sizeof(tmp)) { + ret = -errno; + goto exit; + } + } /* write backup grain directory */ lseek(fd, le64_to_cpu(header.gd_offset) << 9, SEEK_SET); for (i = 0, tmp = header.gd_offset + gd_size; - i < gt_count; i++, tmp += gt_size) - write(fd, &tmp, sizeof(tmp)); + i < gt_count; i++, tmp += gt_size) { + ret = qemu_write_full(fd, &tmp, sizeof(tmp)); + if (ret != sizeof(tmp)) { + ret = -errno; + goto exit; + } + } /* compose the descriptor */ real_filename = filename; @@ -804,10 +828,16 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options) /* write the descriptor */ lseek(fd, le64_to_cpu(header.desc_offset) << 9, SEEK_SET); - write(fd, desc, strlen(desc)); + ret = qemu_write_full(fd, desc, strlen(desc)); + if (ret != strlen(desc)) { + ret = -errno; + goto exit; + } + ret = 0; +exit: close(fd); - return 0; + return ret; } static void vmdk_close(BlockDriverState *bs) -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 06/15] block/vvfat.c: fix warnings with _FORTIFY_SOURCE 2010-01-02 3:45 ` [Qemu-devel] [PATCH 05/15] block/vmdk.o: " Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 07/15] block/qcow2.c: " Kirill A. Shutemov 0 siblings, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov CC block/vvfat.o cc1: warnings being treated as errors block/vvfat.c: In function 'commit_one_file': block/vvfat.c:2259: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result make: *** [block/vvfat.o] Error 1 CC block/vvfat.o In file included from /usr/include/stdio.h:912, from ./qemu-common.h:19, from block/vvfat.c:27: In function 'snprintf', inlined from 'init_directories' at block/vvfat.c:871, inlined from 'vvfat_open' at block/vvfat.c:1068: /usr/include/bits/stdio2.h:65: error: call to __builtin___snprintf_chk will always overflow destination buffer make: *** [block/vvfat.o] Error 1 Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- block/vvfat.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 063f731..8140dbc 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -868,7 +868,7 @@ static int init_directories(BDRVVVFATState* s, { direntry_t* entry=array_get_next(&(s->directory)); entry->attributes=0x28; /* archive | volume label */ - snprintf((char*)entry->name,11,"QEMU VVFAT"); + memcpy(entry->name, "QEMU VVFAT", 11); } /* Now build FAT, and write back information into directory */ @@ -2256,7 +2256,10 @@ static int commit_one_file(BDRVVVFATState* s, c = c1; } - ftruncate(fd, size); + if (ftruncate(fd, size)) { + perror("ftruncate()"); + abort(); + } close(fd); return commit_mappings(s, first_cluster, dir_index); -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 07/15] block/qcow2.c: fix warnings with _FORTIFY_SOURCE 2010-01-02 3:45 ` [Qemu-devel] [PATCH 06/15] block/vvfat.c: " Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 08/15] net/slirp.c: fix warning " Kirill A. Shutemov 0 siblings, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov CC block/qcow2.o cc1: warnings being treated as errors block/qcow2.c: In function 'qcow_create2': block/qcow2.c:829: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:838: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:839: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:841: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:844: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:849: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:852: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:855: error: ignoring return value of 'write', declared with attribute warn_unused_result make: *** [block/qcow2.o] Error 1 Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- block/qcow2.c | 55 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 45 insertions(+), 10 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 984264b..1874124 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -743,7 +743,7 @@ static int qcow_create2(const char *filename, int64_t total_size, uint64_t tmp, offset; QCowCreateState s1, *s = &s1; QCowExtension ext_bf = {0, 0}; - + int ret; memset(s, 0, sizeof(*s)); @@ -826,7 +826,11 @@ static int qcow_create2(const char *filename, int64_t total_size, ref_clusters * s->cluster_size); /* write all the data */ - write(fd, &header, sizeof(header)); + ret = qemu_write_full(fd, &header, sizeof(header)); + if (ret != sizeof(header)) { + ret = -errno; + goto exit; + } if (backing_file) { if (backing_format_len) { char zero[16]; @@ -835,25 +839,56 @@ static int qcow_create2(const char *filename, int64_t total_size, memset(zero, 0, sizeof(zero)); cpu_to_be32s(&ext_bf.magic); cpu_to_be32s(&ext_bf.len); - write(fd, &ext_bf, sizeof(ext_bf)); - write(fd, backing_format, backing_format_len); + ret = qemu_write_full(fd, &ext_bf, sizeof(ext_bf)); + if (ret != sizeof(ext_bf)) { + ret = -errno; + goto exit; + } + ret = qemu_write_full(fd, backing_format, backing_format_len); + if (ret != backing_format_len) { + ret = -errno; + goto exit; + } if (padding > 0) { - write(fd, zero, padding); + ret = qemu_write_full(fd, zero, padding); + if (ret != padding) { + ret = -errno; + goto exit; + } } } - write(fd, backing_file, backing_filename_len); + ret = qemu_write_full(fd, backing_file, backing_filename_len); + if (ret != backing_filename_len) { + ret = -errno; + goto exit; + } } lseek(fd, s->l1_table_offset, SEEK_SET); tmp = 0; for(i = 0;i < l1_size; i++) { - write(fd, &tmp, sizeof(tmp)); + ret = qemu_write_full(fd, &tmp, sizeof(tmp)); + if (ret != sizeof(tmp)) { + ret = -errno; + goto exit; + } } lseek(fd, s->refcount_table_offset, SEEK_SET); - write(fd, s->refcount_table, s->cluster_size); + ret = qemu_write_full(fd, s->refcount_table, s->cluster_size); + if (ret != s->cluster_size) { + ret = -errno; + goto exit; + } lseek(fd, s->refcount_block_offset, SEEK_SET); - write(fd, s->refcount_block, ref_clusters * s->cluster_size); + ret = qemu_write_full(fd, s->refcount_block, + ref_clusters * s->cluster_size); + if (ret != s->cluster_size) { + ret = -errno; + goto exit; + } + ret = 0; +exit: qemu_free(s->refcount_table); qemu_free(s->refcount_block); close(fd); @@ -867,7 +902,7 @@ static int qcow_create2(const char *filename, int64_t total_size, bdrv_close(bs); } - return 0; + return ret; } static int qcow_create(const char *filename, QEMUOptionParameter *options) -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 08/15] net/slirp.c: fix warning with _FORTIFY_SOURCE 2010-01-02 3:45 ` [Qemu-devel] [PATCH 07/15] block/qcow2.c: " Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 09/15] usb-linux.c: " Kirill A. Shutemov 0 siblings, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov CC net/slirp.o cc1: warnings being treated as errors net/slirp.c: In function 'slirp_smb_cleanup': net/slirp.c:470: error: ignoring return value of 'system', declared with attribute warn_unused_result make: *** [net/slirp.o] Error 1 Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- net/slirp.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 3f91c4b..ef7c8e4 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -464,10 +464,17 @@ int net_slirp_redir(const char *redir_str) static void slirp_smb_cleanup(SlirpState *s) { char cmd[128]; + int ret; if (s->smb_dir[0] != '\0') { snprintf(cmd, sizeof(cmd), "rm -rf %s", s->smb_dir); - system(cmd); + ret = system(cmd); + if (ret == -1) { + perror("system()"); + } else if (WEXITSTATUS(ret)) { + qemu_error("'%s' failed. Error code: %d\n", + cmd, WEXITSTATUS(ret)); + } s->smb_dir[0] = '\0'; } } -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 09/15] usb-linux.c: fix warning with _FORTIFY_SOURCE 2010-01-02 3:45 ` [Qemu-devel] [PATCH 08/15] net/slirp.c: fix warning " Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 10/15] vl.c: " Kirill A. Shutemov [not found] ` <m3zl4svci4.fsf@neno.neno> 0 siblings, 2 replies; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov CC usb-linux.o cc1: warnings being treated as errors usb-linux.c: In function 'usb_host_read_file': usb-linux.c:1204: error: ignoring return value of 'fgets', declared with attribute warn_unused_result make: *** [usb-linux.o] Error 1 Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- usb-linux.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/usb-linux.c b/usb-linux.c index 88728e9..8673474 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -1201,9 +1201,13 @@ static int usb_host_read_file(char *line, size_t line_size, const char *device_f device_file); f = fopen(filename, "r"); if (f) { - fgets(line, line_size, f); + if (fgets(line, line_size, f)) { + ret = 1; + } else { + ret = 0; + } + fclose(f); - ret = 1; #if 0 } else { if (mon) -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 10/15] vl.c: fix warning with _FORTIFY_SOURCE 2010-01-02 3:45 ` [Qemu-devel] [PATCH 09/15] usb-linux.c: " Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 11/15] monitor.c: fix warnings " Kirill A. Shutemov [not found] ` <m3zl4svci4.fsf@neno.neno> 1 sibling, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov CC i386-softmmu/vl.o cc1: warnings being treated as errors /usr/src/RPM/BUILD/qemu-0.11.92/vl.c: In function 'qemu_event_increment': /usr/src/RPM/BUILD/qemu-0.11.92/vl.c:3404: error: ignoring return value of 'write', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/vl.c: In function 'main': /usr/src/RPM/BUILD/qemu-0.11.92/vl.c:5774: error: ignoring return value of 'write', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/vl.c:6064: error: ignoring return value of 'chdir', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/vl.c:6083: error: ignoring return value of 'chdir', declared with attribute warn_unused_result make[1]: *** [vl.o] Error 1 Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- vl.c | 33 +++++++++++++++++++++------------ 1 files changed, 21 insertions(+), 12 deletions(-) diff --git a/vl.c b/vl.c index e881e45..7fcde35 100644 --- a/vl.c +++ b/vl.c @@ -3390,11 +3390,17 @@ static int io_thread_fd = -1; static void qemu_event_increment(void) { static const char byte = 0; + int ret; if (io_thread_fd == -1) return; - write(io_thread_fd, &byte, sizeof(byte)); + ret = write(io_thread_fd, &byte, sizeof(byte)); + if (ret < 0 && (errno != EINTR && errno != EAGAIN)) { + fprintf(stderr, "qemu_event_increment: write() filed: %s\n", + strerror(errno)); + exit (1); + } } static void qemu_event_read(void *opaque) @@ -5778,7 +5784,10 @@ int main(int argc, char **argv, char **envp) #ifndef _WIN32 if (daemonize) { uint8_t status = 1; - write(fds[1], &status, 1); + if (qemu_write_full(fds[1], &status, 1) != 1) { + perror("write()"); + exit(1); + } } else #endif fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno)); @@ -6065,18 +6074,15 @@ int main(int argc, char **argv, char **envp) #ifndef _WIN32 if (daemonize) { uint8_t status = 0; - ssize_t len; - again1: - len = write(fds[1], &status, 1); - if (len == -1 && (errno == EINTR)) - goto again1; - - if (len != 1) + if (qemu_write_full(fds[1], &status, 1) != 1) exit(1); - chdir("/"); - TFR(fd = qemu_open("/dev/null", O_RDWR)); + if (chdir("/")) { + perror("chdir()"); + exit(1); + } + TFR(fd = qemu_open("/dev/null", O_RDWR)); if (fd == -1) exit(1); } @@ -6094,7 +6100,10 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "chroot failed\n"); exit(1); } - chdir("/"); + if (chdir("/")) { + perror("chdir()"); + exit(1); + } } if (run_as) { -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 11/15] monitor.c: fix warnings with _FORTIFY_SOURCE 2010-01-02 3:45 ` [Qemu-devel] [PATCH 10/15] vl.c: " Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 12/15] linux-user/mmap.c: " Kirill A. Shutemov 0 siblings, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov CC i386-softmmu/monitor.o cc1: warnings being treated as errors /usr/src/RPM/BUILD/qemu-0.11.92/monitor.c: In function 'do_memory_save': /usr/src/RPM/BUILD/qemu-0.11.92/monitor.c:1318: error: ignoring return value of 'fwrite', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/monitor.c: In function 'do_physical_memory_save': /usr/src/RPM/BUILD/qemu-0.11.92/monitor.c:1345: error: ignoring return value of 'fwrite', declared with attribute warn_unused_result make[1]: *** [monitor.o] Error 1 Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- monitor.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/monitor.c b/monitor.c index c0dc48e..54c7323 100644 --- a/monitor.c +++ b/monitor.c @@ -1320,10 +1320,14 @@ static void do_memory_save(Monitor *mon, const QDict *qdict, QObject **ret_data) if (l > size) l = size; cpu_memory_rw_debug(env, addr, buf, l, 0); - fwrite(buf, 1, l, f); + if (fwrite(buf, 1, l, f) != l) { + monitor_printf(mon, "fwrite() failed\n"); + goto exit; + } addr += l; size -= l; } +exit: fclose(f); } @@ -1347,11 +1351,15 @@ static void do_physical_memory_save(Monitor *mon, const QDict *qdict, if (l > size) l = size; cpu_physical_memory_rw(addr, buf, l, 0); - fwrite(buf, 1, l, f); + if (fwrite(buf, 1, l, f) != l) { + monitor_printf(mon, "fwrite() failed\n"); + goto exit; + } fflush(f); addr += l; size -= l; } +exit: fclose(f); } -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 12/15] linux-user/mmap.c: fix warnings with _FORTIFY_SOURCE 2010-01-02 3:45 ` [Qemu-devel] [PATCH 11/15] monitor.c: fix warnings " Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 13/15] Enable _FORTIFY_SOURCE=2 Kirill A. Shutemov 0 siblings, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov CC i386-linux-user/mmap.o cc1: warnings being treated as errors /usr/src/RPM/BUILD/qemu-0.11.92/linux-user/mmap.c: In function 'mmap_frag': /usr/src/RPM/BUILD/qemu-0.11.92/linux-user/mmap.c:253: error: ignoring return value of 'pread', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/linux-user/mmap.c: In function 'target_mmap': /usr/src/RPM/BUILD/qemu-0.11.92/linux-user/mmap.c:477: error: ignoring return value of 'pread', declared with attribute warn_unused_result make[1]: *** [mmap.o] Error 1 Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> test --- linux-user/mmap.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 144fb7c..c1c7e48 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -250,7 +250,8 @@ static int mmap_frag(abi_ulong real_start, mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE); /* read the corresponding file data */ - pread(fd, g2h(start), end - start, offset); + if (pread(fd, g2h(start), end - start, offset) == -1) + return -1; /* put final protection */ if (prot_new != (prot1 | PROT_WRITE)) @@ -474,7 +475,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, -1, 0); if (retaddr == -1) goto fail; - pread(fd, g2h(start), len, offset); + if (pread(fd, g2h(start), len, offset) == -1) + goto fail; if (!(prot & PROT_WRITE)) { ret = target_mprotect(start, len, prot); if (ret != 0) { -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 13/15] Enable _FORTIFY_SOURCE=2 2010-01-02 3:45 ` [Qemu-devel] [PATCH 12/15] linux-user/mmap.c: " Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 14/15] Add -fstack-protector-all to CFLAGS Kirill A. Shutemov 0 siblings, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov _FORTIFY_SOURCE is a Glibc feature which adds memory and string function protection. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- configure | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/configure b/configure index 18aed43..0cdcdb3 100755 --- a/configure +++ b/configure @@ -97,7 +97,7 @@ CFLAGS="-g $CFLAGS" QEMU_CFLAGS="-Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS" QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS" -QEMU_CFLAGS="-U_FORTIFY_SOURCE $QEMU_CFLAGS" +QEMU_CFLAGS="-D_FORTIFY_SOURCE=2 $QEMU_CFLAGS" QEMU_CFLAGS="-I. -I\$(SRC_PATH) $QEMU_CFLAGS" LDFLAGS="-g $LDFLAGS" -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 14/15] Add -fstack-protector-all to CFLAGS 2010-01-02 3:45 ` [Qemu-devel] [PATCH 13/15] Enable _FORTIFY_SOURCE=2 Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 15/15] linux-user: fix return value of mmap_frag() Kirill A. Shutemov 0 siblings, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov -fstack-protector-all emit extra code to check for buffer overflows, such as stack smashing attacks. This is done by adding a guard variable to functions with vulnerable objects. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- configure | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/configure b/configure index 0cdcdb3..ec4175a 100755 --- a/configure +++ b/configure @@ -123,6 +123,14 @@ else exit 1 fi +# check -fstack-protector-all +cat > $TMPC << EOF +int foo(void) {char X[2]; return 3;} +EOF +if compile_object "$QEMU_CFLAGS" -fstack-protector-all; then + QEMU_CFLAGS="-fstack-protector-all $QEMU_CFLAGS" +fi + check_define() { cat > $TMPC <<EOF #if !defined($1) -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Qemu-devel] [PATCH 15/15] linux-user: fix return value of mmap_frag() 2010-01-02 3:45 ` [Qemu-devel] [PATCH 14/15] Add -fstack-protector-all to CFLAGS Kirill A. Shutemov @ 2010-01-02 3:45 ` Kirill A. Shutemov 0 siblings, 0 replies; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-02 3:45 UTC (permalink / raw) To: qemu-devel; +Cc: Kirill A. Shutemov mmap_frag() returns -1 on error and set errno. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- linux-user/mmap.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index c1c7e48..47bc339 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -242,8 +242,10 @@ static int mmap_frag(abi_ulong real_start, /* msync() won't work here, so we return an error if write is possible while it is a shared mapping */ if ((flags & MAP_TYPE) == MAP_SHARED && - (prot & PROT_WRITE)) - return -EINVAL; + (prot & PROT_WRITE)) { + errno = -EINVAL; + return -1; + } /* adjust protection to be able to read */ if (!(prot1 & PROT_WRITE)) -- 1.6.5.7 ^ permalink raw reply related [flat|nested] 18+ messages in thread
[parent not found: <m3zl4svci4.fsf@neno.neno>]
* [Qemu-devel] Re: [PATCH 09/15] usb-linux.c: fix warning with _FORTIFY_SOURCE [not found] ` <m3zl4svci4.fsf@neno.neno> @ 2010-01-05 16:07 ` Kirill A. Shutemov 2010-01-05 16:36 ` Michael S. Tsirkin 0 siblings, 1 reply; 18+ messages in thread From: Kirill A. Shutemov @ 2010-01-05 16:07 UTC (permalink / raw) To: Juan Quintela; +Cc: qemu-devel On Tue, Jan 5, 2010 at 4:42 PM, Juan Quintela <quintela@trasno.org> wrote: > "Kirill A. Shutemov" <kirill@shutemov.name> wrote: >> CC usb-linux.o >> cc1: warnings being treated as errors >> usb-linux.c: In function 'usb_host_read_file': >> usb-linux.c:1204: error: ignoring return value of 'fgets', declared with attribute warn_unused_result >> make: *** [usb-linux.o] Error 1 >> >> Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> >> --- >> usb-linux.c | 8 ++++++-- >> 1 files changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/usb-linux.c b/usb-linux.c >> index 88728e9..8673474 100644 >> --- a/usb-linux.c >> +++ b/usb-linux.c >> @@ -1201,9 +1201,13 @@ static int usb_host_read_file(char *line, size_t line_size, const char *device_f >> device_file); >> f = fopen(filename, "r"); >> if (f) { >> - fgets(line, line_size, f); >> + if (fgets(line, line_size, f)) { >> + ret = 1; >> + } else { >> + ret = 0; >> + } >> + > This if is equivalent to: > > ret = !!fgets(line, line_size, f); > > No need for the if at all :) It's not very readable. Probably better to use something like: ret = (fgets(line, line_size, f) != NULL); ^ permalink raw reply [flat|nested] 18+ messages in thread
* [Qemu-devel] Re: [PATCH 09/15] usb-linux.c: fix warning with _FORTIFY_SOURCE 2010-01-05 16:07 ` [Qemu-devel] Re: [PATCH 09/15] usb-linux.c: fix warning with _FORTIFY_SOURCE Kirill A. Shutemov @ 2010-01-05 16:36 ` Michael S. Tsirkin 0 siblings, 0 replies; 18+ messages in thread From: Michael S. Tsirkin @ 2010-01-05 16:36 UTC (permalink / raw) To: Kirill A. Shutemov; +Cc: Juan Quintela, qemu-devel On Tue, Jan 05, 2010 at 06:07:35PM +0200, Kirill A. Shutemov wrote: > On Tue, Jan 5, 2010 at 4:42 PM, Juan Quintela <quintela@trasno.org> wrote: > > "Kirill A. Shutemov" <kirill@shutemov.name> wrote: > >> CC usb-linux.o > >> cc1: warnings being treated as errors > >> usb-linux.c: In function 'usb_host_read_file': > >> usb-linux.c:1204: error: ignoring return value of 'fgets', declared with attribute warn_unused_result > >> make: *** [usb-linux.o] Error 1 > >> > >> Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> > >> --- > >> usb-linux.c | 8 ++++++-- > >> 1 files changed, 6 insertions(+), 2 deletions(-) > >> > >> diff --git a/usb-linux.c b/usb-linux.c > >> index 88728e9..8673474 100644 > >> --- a/usb-linux.c > >> +++ b/usb-linux.c > >> @@ -1201,9 +1201,13 @@ static int usb_host_read_file(char *line, size_t line_size, const char *device_f > >> device_file); > >> f = fopen(filename, "r"); > >> if (f) { > >> - fgets(line, line_size, f); > >> + if (fgets(line, line_size, f)) { > >> + ret = 1; > >> + } else { > >> + ret = 0; > >> + } > >> + > > This if is equivalent to: > > > > ret = !!fgets(line, line_size, f); > > > > No need for the if at all :) > > It's not very readable. > Probably better to use something like: > > ret = (fgets(line, line_size, f) != NULL); > Might be matter of taste. E.g. I think !! is more readable than != NULL. And () around != are not needed. It's better to make code brief IMO, a lof of boilerplate hides bugs. Nothing to get hung about though. -- MST ^ permalink raw reply [flat|nested] 18+ messages in thread
* [Qemu-devel] Re: [PATCH 01/15] Introduce qemu_write_full() 2010-01-02 3:45 [Qemu-devel] [PATCH 01/15] Introduce qemu_write_full() Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 02/15] posix-aio-compat.c: fix warning with _FORTIFY_SOURCE Kirill A. Shutemov @ 2010-01-02 10:34 ` Paolo Bonzini 1 sibling, 0 replies; 18+ messages in thread From: Paolo Bonzini @ 2010-01-02 10:34 UTC (permalink / raw) To: Kirill A. Shutemov; +Cc: qemu-devel On 01/02/2010 04:45 AM, Kirill A. Shutemov wrote: > A variant of write(2) which handles partial write. Next time please add a cover letter 00/15 to explain what you changed, and a v3 (or v4?) marker in the subjects. Thanks for this work though! Paolo ^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2010-01-05 16:39 UTC | newest] Thread overview: 18+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-01-02 3:45 [Qemu-devel] [PATCH 01/15] Introduce qemu_write_full() Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 02/15] posix-aio-compat.c: fix warning with _FORTIFY_SOURCE Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 03/15] block/cow.c: fix warnings " Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 04/15] block/qcow.c: " Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 05/15] block/vmdk.o: " Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 06/15] block/vvfat.c: " Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 07/15] block/qcow2.c: " Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 08/15] net/slirp.c: fix warning " Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 09/15] usb-linux.c: " Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 10/15] vl.c: " Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 11/15] monitor.c: fix warnings " Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 12/15] linux-user/mmap.c: " Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 13/15] Enable _FORTIFY_SOURCE=2 Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 14/15] Add -fstack-protector-all to CFLAGS Kirill A. Shutemov 2010-01-02 3:45 ` [Qemu-devel] [PATCH 15/15] linux-user: fix return value of mmap_frag() Kirill A. Shutemov [not found] ` <m3zl4svci4.fsf@neno.neno> 2010-01-05 16:07 ` [Qemu-devel] Re: [PATCH 09/15] usb-linux.c: fix warning with _FORTIFY_SOURCE Kirill A. Shutemov 2010-01-05 16:36 ` Michael S. Tsirkin 2010-01-02 10:34 ` [Qemu-devel] Re: [PATCH 01/15] Introduce qemu_write_full() Paolo Bonzini
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).