diff options
author | Amit Shah <amit.shah@redhat.com> | 2010-04-01 14:55:46 +0530 |
---|---|---|
committer | Amit Shah <amit.shah@redhat.com> | 2010-04-06 20:00:32 +0530 |
commit | 873d4e83413cbd1be336c7157d28f763f8e7208e (patch) | |
tree | 8287840055b975299ff58e0ee6b40f7086417a4f | |
parent | 3e99892230d186252a7adedefa31d7e0d844a9cf (diff) | |
download | test-virtserial-873d4e83413cbd1be336c7157d28f763f8e7208e.tar.gz test-virtserial-873d4e83413cbd1be336c7157d28f763f8e7208e.tar.xz test-virtserial-873d4e83413cbd1be336c7157d28f763f8e7208e.zip |
guest, test-virtserial: Fix fcntl usage
While setting or clearing the O_NONBLOCK flag for file descriptors, we
were trampling on the other flags.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
-rw-r--r-- | auto-virtserial-guest.c | 10 | ||||
-rw-r--r-- | test-virtserial.c | 9 |
2 files changed, 15 insertions, 4 deletions
diff --git a/auto-virtserial-guest.c b/auto-virtserial-guest.c index ce64ebc..6776874 100644 --- a/auto-virtserial-guest.c +++ b/auto-virtserial-guest.c @@ -142,9 +142,15 @@ static int set_port_nonblocking(int val) { int ret, flags; - flags = 0; + flags = fcntl(g_fd, F_GETFL); + if (flags == -1) + return -errno; + if (val) - flags = O_NONBLOCK; + flags |= O_NONBLOCK; + else + flags &= ~O_NONBLOCK; + ret = fcntl(g_fd, F_SETFL, flags); if (ret == -1) return -errno; diff --git a/test-virtserial.c b/test-virtserial.c index 58562ba..a3beeb1 100644 --- a/test-virtserial.c +++ b/test-virtserial.c @@ -266,9 +266,14 @@ start: goto out; break; case 'b': - flags = O_NONBLOCK; + flags = fcntl(fd, F_GETFL); + if (flags < 0) + perror("ERR: fcntl getfl"); + if (!is_blocking) - flags = ~O_NONBLOCK; + flags &= ~O_NONBLOCK; + else + flags |= O_NONBLOCK; ret = fcntl(fd, F_SETFL, flags); if (!ret) is_blocking = !is_blocking; |