summaryrefslogtreecommitdiff
path: root/libmultipath/uxsock.c
diff options
context:
space:
mode:
authorroot <root@xa-s05.(none)>2005-09-18 00:47:51 +0200
committerroot <root@xa-s05.(none)>2005-09-18 00:47:51 +0200
commit2f20866ae9c4e670d4bb4fc8a6bce54f6062e74d (patch)
tree8befb0f35a09888b00ec067a45ff03f2929b88b2 /libmultipath/uxsock.c
parentace8219c5ade30ee2b8bb38fd29be9d8798cc5a8 (diff)
downloadmultipath-tools-2f20866ae9c4e670d4bb4fc8a6bce54f6062e74d.tar.gz
multipath-tools-2f20866ae9c4e670d4bb4fc8a6bce54f6062e74d.tar.bz2
multipath-tools-2f20866ae9c4e670d4bb4fc8a6bce54f6062e74d.zip
[libmultipath] unix socket read/write loops fix
Those can tight loop. Do finer checks with errno.h to avoid that. From Alasdair Kergon, Redhat.
Diffstat (limited to 'libmultipath/uxsock.c')
-rw-r--r--libmultipath/uxsock.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/libmultipath/uxsock.c b/libmultipath/uxsock.c
index c21f58f..3f2f8e2 100644
--- a/libmultipath/uxsock.c
+++ b/libmultipath/uxsock.c
@@ -8,6 +8,7 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/poll.h>
+#include <errno.h>
#include "memory.h"
#include "uxsock.h"
@@ -70,14 +71,21 @@ int ux_socket_listen(const char *name)
}
/*
- * keep writing until its all sent
+ * keep writing until it's all sent
*/
-int write_all(int fd, const void *buf, size_t len)
+size_t write_all(int fd, const void *buf, size_t len)
{
size_t total = 0;
+
while (len) {
- int n = write(fd, buf, len);
- if (n <= 0) return total;
+ ssize_t n = write(fd, buf, len);
+ if (n < 0) {
+ if ((errno == EINTR) || (errno == EAGAIN))
+ continue;
+ return total;
+ }
+ if (!n)
+ return total;
buf = n + (char *)buf;
len -= n;
total += n;
@@ -88,12 +96,19 @@ int write_all(int fd, const void *buf, size_t len)
/*
* keep reading until its all read
*/
-int read_all(int fd, void *buf, size_t len)
+size_t read_all(int fd, void *buf, size_t len)
{
size_t total = 0;
+
while (len) {
- int n = read(fd, buf, len);
- if (n <= 0) return total;
+ ssize_t n = read(fd, buf, len);
+ if (n < 0) {
+ if ((errno == EINTR) || (errno == EAGAIN))
+ continue;
+ return total;
+ }
+ if (!n)
+ return total;
buf = n + (char *)buf;
len -= n;
total += n;