[PATCH] Fix / slightly simplify smbd/scavenger

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Oct 29 16:02:05 UTC 2015


Hi!

Review&push appreciated!

Thanks, Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de

Besuchen Sie uns vom 10.-11.11.15 auf der ISSE!
Information Security Solutions Europe Conference
Hotel Palace Berlin, 20%-Rabattcode: "ISSE15SP"

Meet us at Information Security Conference ISSE!
November 10th - 11th 2015 in Hotel Palace Berlin
For 20% discount take voucher code:  "ISSE15SP"
-------------- next part --------------
From b55dd641b12178a1922fb3ac5fad8fdcb59ff076 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 29 Oct 2015 14:27:32 +0100
Subject: [PATCH] smbd: Fix/simplify scavenger routines

Use read_data/write_data, "ofs" was not incremented

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/scavenger.c | 39 ++++++++++++---------------------------
 1 file changed, 12 insertions(+), 27 deletions(-)

diff --git a/source3/smbd/scavenger.c b/source3/smbd/scavenger.c
index 6171c29..df0e140 100644
--- a/source3/smbd/scavenger.c
+++ b/source3/smbd/scavenger.c
@@ -26,7 +26,7 @@
 #include "smbd/scavenger.h"
 #include "locking/proto.h"
 #include "lib/util/util_process.h"
-#include "lib/util/sys_rw.h"
+#include "lib/util/sys_rw_data.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_SCAVENGER
@@ -144,21 +144,13 @@ static int smbd_scavenger_server_id_destructor(struct server_id *id)
 
 static bool scavenger_say_hello(int fd, struct server_id self)
 {
-	const uint8_t *msg = (const uint8_t *)&self;
-	size_t remaining = sizeof(self);
-	size_t ofs = 0;
+	ssize_t ret;
 	struct server_id_buf tmp;
 
-	while (remaining > 0) {
-		ssize_t ret;
-
-		ret = sys_write(fd, msg + ofs, remaining);
-		if (ret == -1) {
-			DEBUG(2, ("Failed to write to pipe: %s\n",
-				  strerror(errno)));
-			return false;
-		}
-		remaining -= ret;
+	ret = write_data(fd, &self, sizeof(self));
+	if (ret == -1) {
+		DEBUG(2, ("Failed to write to pipe: %s\n", strerror(errno)));
+		return false;
 	}
 
 	DEBUG(4, ("scavenger_say_hello: self[%s]\n",
@@ -168,21 +160,14 @@ static bool scavenger_say_hello(int fd, struct server_id self)
 
 static bool scavenger_wait_hello(int fd, struct server_id *child)
 {
-	uint8_t *msg = (uint8_t *)child;
-	size_t remaining = sizeof(*child);
-	size_t ofs = 0;
 	struct server_id_buf tmp;
+	ssize_t ret;
 
-	while (remaining > 0) {
-		ssize_t ret;
-
-		ret = sys_read(fd, msg + ofs, remaining);
-		if (ret == -1) {
-			DEBUG(2, ("Failed to read from pipe: %s\n",
-				  strerror(errno)));
-			return false;
-		}
-		remaining -= ret;
+	ret = read_data(fd, child, sizeof(child));
+	if (ret == -1) {
+		DEBUG(2, ("Failed to read from pipe: %s\n",
+			  strerror(errno)));
+		return false;
 	}
 
 	DEBUG(4, ("scavenger_say_hello: child[%s]\n",
-- 
1.9.1



More information about the samba-technical mailing list