From 65b99a49dc4d5d4cf16ba880d3377196e96f1bc5 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Mon, 13 May 2013 09:59:32 +0200
Subject: [PATCH 2/3] usbredirserver/testclient: Error check fcntl calls
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
usbredirserver/usbredirserver.c | 14 +++++++++++---
usbredirtestclient/usbredirtestclient.c | 14 ++++++++++++--
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/usbredirserver/usbredirserver.c b/usbredirserver/usbredirserver.c
index c45a27c..d2765c6 100644
--- a/usbredirserver/usbredirserver.c
+++ b/usbredirserver/usbredirserver.c
@@ -189,7 +189,7 @@ static void quit_handler(int sig)
int main(int argc, char *argv[])
{
- int o, server_fd = -1;
+ int o, flags, server_fd = -1;
char *endptr, *delim;
int port = 4000;
int usbbus = -1;
@@ -307,8 +307,16 @@ int main(int argc, char *argv[])
break;
}
- fcntl(client_fd, F_SETFL,
- (long)fcntl(client_fd, F_GETFL) | O_NONBLOCK);
+ flags = fcntl(client_fd, F_GETFL);
+ if (flags == -1) {
+ perror("fcntl F_GETFL");
+ break;
+ }
+ flags = fcntl(client_fd, F_SETFL, flags | O_NONBLOCK);
+ if (flags == -1) {
+ perror("fcntl F_SETFL O_NONBLOCK");
+ break;
+ }
/* Try to find the specified usb device */
if (usbvendor != -1) {
diff --git a/usbredirtestclient/usbredirtestclient.c b/usbredirtestclient/usbredirtestclient.c
index a9123da..42b16dc 100644
--- a/usbredirtestclient/usbredirtestclient.c
+++ b/usbredirtestclient/usbredirtestclient.c
@@ -189,7 +189,7 @@ static void quit_handler(int sig)
int main(int argc, char *argv[])
{
- int o;
+ int o, flags;
char *endptr, *server;
struct addrinfo *r, *res, hints;
struct sigaction act;
@@ -265,7 +265,17 @@ int main(int argc, char *argv[])
exit(1);
}
- fcntl(client_fd, F_SETFL, (long)fcntl(client_fd, F_GETFL) | O_NONBLOCK);
+ flags = fcntl(client_fd, F_GETFL);
+ if (flags == -1) {
+ perror("fcntl F_GETFL");
+ exit(1);
+ }
+ flags = fcntl(client_fd, F_SETFL, flags | O_NONBLOCK);
+ if (flags == -1) {
+ perror("fcntl F_SETFL O_NONBLOCK");
+ exit(1);
+ }
+
parser = usbredirparser_create();
if (!parser) {
exit(1);
--
1.8.2.1