From: Matthew Daley <mattjd@gmail.com>
To: xen-devel@lists.xen.org
Cc: Ian Campbell <ian.campbell@citrix.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Matthew Daley <mattjd@gmail.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Daniel De Graaf <dgdegra@tycho.nsa.gov>
Subject: [PATCH v2] libvchan: tidy up usages of fcntl in select-type sample application
Date: Thu, 31 Oct 2013 16:44:53 +1300 [thread overview]
Message-ID: <1383191093-15751-1-git-send-email-mattjd@gmail.com> (raw)
In-Reply-To: <1383119525-26033-26-git-send-email-mattjd@gmail.com>
Namely, don't overwrite all the other flags when twiddling O_NONBLOCK,
and add basic error handling.
Coverity-ID: 1055041
Signed-off-by: Matthew Daley <mattjd@gmail.com>
---
v2: Adjust other fcntl usage further down as well. Use F_GETFL to modify
only the O_NONBLOCK flag. Both suggested by Daniel De Graaf.
Improve commit message.
tools/libvchan/node-select.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/tools/libvchan/node-select.c b/tools/libvchan/node-select.c
index 6c6c19e..acd9bae 100644
--- a/tools/libvchan/node-select.c
+++ b/tools/libvchan/node-select.c
@@ -90,6 +90,7 @@ int main(int argc, char **argv)
{
int ret;
int libxenvchan_fd;
+ int flags;
if (argc < 4 || argv[3][0] != '/')
usage(argv);
if (!strcmp(argv[1], "server")) {
@@ -105,8 +106,13 @@ int main(int argc, char **argv)
exit(1);
}
- fcntl(0, F_SETFL, O_NONBLOCK);
- fcntl(1, F_SETFL, O_NONBLOCK);
+ if ((flags = fcntl(0, F_GETFL)) == -1 ||
+ fcntl(0, F_SETFL, flags | O_NONBLOCK) == -1 ||
+ (flags = fcntl(1, F_GETFL)) == -1 ||
+ fcntl(1, F_SETFL, flags | O_NONBLOCK) == -1) {
+ perror("fcntl");
+ exit(1);
+ }
libxenvchan_fd = libxenvchan_fd_for_select(ctrl);
for (;;) {
@@ -153,7 +159,11 @@ int main(int argc, char **argv)
stdout_wr();
}
if (!libxenvchan_is_open(ctrl)) {
- fcntl(1, F_SETFL, 0);
+ if ((flags = fcntl(1, F_GETFL)) == -1 ||
+ fcntl(1, F_SETFL, flags & ~O_NONBLOCK) == -1) {
+ perror("fcntl");
+ exit(1);
+ }
while (outsiz)
stdout_wr();
return 0;
--
1.7.10.4
next prev parent reply other threads:[~2013-10-31 3:44 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-30 7:51 Fixes for various minor Coverity issues, volume 3 Matthew Daley
2013-10-30 7:51 ` [PATCH 01/29] libxc: check for xc_domain_get_guest_width failure and pass it down Matthew Daley
2013-10-31 21:03 ` Ian Campbell
2013-11-01 0:24 ` [PATCH v2] " Matthew Daley
2013-11-01 13:12 ` Ian Campbell
2013-11-02 22:57 ` [PATCH v3] libxc: check for various libxc failures and pass them down Matthew Daley
2013-11-02 23:08 ` [PATCH v4] " Matthew Daley
2013-11-04 17:31 ` Ian Campbell
2013-11-05 4:58 ` Matthew Daley
2013-11-05 10:10 ` Ian Campbell
2013-10-30 7:51 ` [PATCH 02/29] libxc: fix retrieval of and remove pointless check on gzip size Matthew Daley
2013-10-30 10:50 ` Andrew Cooper
2013-10-30 22:08 ` Matthew Daley
2013-10-31 2:58 ` [PATCH v2] " Matthew Daley
2013-10-31 10:22 ` Andrew Cooper
2013-10-31 22:07 ` Ian Campbell
2013-10-30 7:51 ` [PATCH 03/29] libxc: fix memory leak in move_l3_below_4G error handling Matthew Daley
2013-10-30 7:51 ` [PATCH 04/29] libxc: don't ignore fd read failures when restoring a domain Matthew Daley
2013-10-30 7:51 ` [PATCH 05/29] libxc: tidy up loop construct in write_compressed Matthew Daley
2013-10-30 7:51 ` [PATCH 06/29] libxc: don't read uninitialized size value in xc_read_image Matthew Daley
2013-10-31 21:22 ` Ian Campbell
2013-10-31 22:12 ` Matthew Daley
2013-10-31 22:26 ` Ian Campbell
2013-10-30 7:51 ` [PATCH 07/29] libxc: remove pointless null pointer check in xc_interface_open_common Matthew Daley
2013-10-30 7:51 ` [PATCH 08/29] libxc: check for xc_domain_get_guest_width failure in xc_domain_resume_any Matthew Daley
2013-10-30 7:51 ` [PATCH 09/29] libxc: check for xc_vcpu_setcontext " Matthew Daley
2013-10-31 21:56 ` Ian Campbell
2013-11-01 0:27 ` [PATCH v2] " Matthew Daley
2013-11-01 13:26 ` Ian Campbell
2013-11-01 16:34 ` [PATCH 09/29] " Ian Jackson
2013-11-04 10:29 ` Ian Campbell
2013-10-30 7:51 ` [PATCH 10/29] libxc: initalize stdio loggers' progress_last_percent values to 0 Matthew Daley
2013-10-30 7:51 ` [PATCH 11/29] libxc: remove null pointer checks in xc_pm_get_{c, p}xstat Matthew Daley
2013-10-30 7:51 ` [PATCH 12/29] libxl: check for transaction abortion failure in libxl_set_memory_target Matthew Daley
2013-10-30 7:51 ` [PATCH 13/29] libxl: check for xc_domain_max_vcpus failure in libxl__build_pre Matthew Daley
2013-10-31 21:29 ` Ian Campbell
2013-11-01 0:29 ` [PATCH v2] " Matthew Daley
2013-11-01 13:27 ` Ian Campbell
2013-10-30 7:51 ` [PATCH 14/29] libxl: don't leak xs_read results in libxl__device_nic_from_xs_be Matthew Daley
2013-10-30 8:58 ` Roger Pau Monné
2013-10-30 9:51 ` Matthew Daley
2013-10-31 21:31 ` Ian Campbell
2013-10-30 7:51 ` [PATCH 15/29] libxl: correct file open success check in libxl__device_pci_reset Matthew Daley
2013-10-30 7:51 ` [PATCH 16/29] libxl: check for xc_domain_shutdown failure in libxl__domain_suspend_common_callback Matthew Daley
2013-10-31 21:36 ` Ian Campbell
2013-11-01 0:30 ` [PATCH v2] " Matthew Daley
2013-11-01 13:27 ` Ian Campbell
2013-10-30 7:51 ` [PATCH 17/29] libxl: don't leak memory in libxl__poller_get failure case Matthew Daley
2013-10-30 7:51 ` [PATCH 18/29] libxl: only close fds which successfully opened in libxl__spawn_local_dm Matthew Daley
2013-10-30 7:51 ` [PATCH 19/29] xl: libxl_list_vm returns a pointer, not a handle Matthew Daley
2013-10-30 7:51 ` [PATCH 20/29] xl: check for restore file open failure in create_domain Matthew Daley
2013-10-30 7:51 ` [PATCH 21/29] xl: remove needless infinite-loop construct " Matthew Daley
2013-10-30 7:51 ` [PATCH 22/29] xl: correct references to long-removed function in error messages Matthew Daley
2013-10-30 7:51 ` [PATCH 23/29] docs: make `xl vcpu-list` example use verbatim formatting Matthew Daley
2013-10-30 10:53 ` Matthew Daley
2013-10-31 3:02 ` [PATCH v2] docs: make `xl vm-list` " Matthew Daley
2013-10-30 7:52 ` [PATCH 24/29] libvchan: handle libxc evtchn failures properly in init functions Matthew Daley
2013-10-30 10:12 ` Matthew Daley
2013-10-30 14:52 ` Daniel De Graaf
2013-10-30 22:07 ` Matthew Daley
2013-10-30 22:17 ` Matthew Daley
2013-10-31 3:41 ` [PATCH v2] " Matthew Daley
2013-10-30 7:52 ` [PATCH 25/29] libvchan: check for fcntl failures in select-type sample application Matthew Daley
2013-10-30 17:06 ` Daniel De Graaf
2013-10-30 17:13 ` Andrew Cooper
2013-10-30 22:04 ` Matthew Daley
2013-10-31 3:44 ` Matthew Daley [this message]
2013-10-31 21:47 ` [PATCH v2] libvchan: tidy up usages of fcntl " Ian Campbell
2013-11-01 0:33 ` [PATCH v3] " Matthew Daley
2013-11-01 13:28 ` Ian Campbell
2013-11-01 14:11 ` Daniel De Graaf
2013-11-04 17:51 ` Ian Campbell
2013-10-30 7:52 ` [PATCH 26/29] xenctx: only alloc symbol if we are inserting it into the symbol table Matthew Daley
2013-10-30 8:59 ` Jan Beulich
2013-10-30 7:52 ` [PATCH 27/29] xenctx: correct error check when opening libxc Matthew Daley
2013-10-30 12:48 ` George Dunlap
2013-10-30 7:52 ` [PATCH 28/29] xentrace: don't try to close null libxc handle in disable_tbufs Matthew Daley
2013-10-30 12:47 ` George Dunlap
2013-10-30 7:52 ` [PATCH 29/29] xentrace: undeadify invalid option argument handling Matthew Daley
2013-10-30 12:47 ` George Dunlap
2013-10-31 12:28 ` Fixes for various minor Coverity issues, volume 3 Andrew Cooper
2013-10-31 21:55 ` Matthew Daley
2013-10-31 22:10 ` Ian Campbell
2013-11-01 2:08 ` Matthew Daley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1383191093-15751-1-git-send-email-mattjd@gmail.com \
--to=mattjd@gmail.com \
--cc=andrew.cooper3@citrix.com \
--cc=dgdegra@tycho.nsa.gov \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).