* [PATCH] libuuid,uuidd: move read_all to include/readall.h
@ 2012-05-13 7:37 Petr Uzel
2012-05-14 9:46 ` Karel Zak
0 siblings, 1 reply; 3+ messages in thread
From: Petr Uzel @ 2012-05-13 7:37 UTC (permalink / raw)
To: util-linux
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
include/Makefile.am | 1 +
include/readall.h | 33 +++++++++++++++++++++++++++++++++
libuuid/src/gen_uuid.c | 26 +-------------------------
misc-utils/uuidd.c | 25 +------------------------
4 files changed, 36 insertions(+), 49 deletions(-)
create mode 100644 include/readall.h
diff --git a/include/Makefile.am b/include/Makefile.am
index f61cb04..6946e68 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -30,6 +30,7 @@ dist_noinst_HEADERS = \
pathnames.h \
procutils.h \
randutils.h \
+ readall.h \
rpmatch.h \
setproctitle.h \
strutils.h \
diff --git a/include/readall.h b/include/readall.h
new file mode 100644
index 0000000..96baaca
--- /dev/null
+++ b/include/readall.h
@@ -0,0 +1,33 @@
+#ifndef UTIL_LINUX_READALL_H
+#define UTIL_LINUX_READALL_H
+
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+static inline ssize_t read_all(int fd, char *buf, size_t count)
+{
+ ssize_t ret;
+ ssize_t c = 0;
+ int tries = 0;
+
+ memset(buf, 0, count);
+ while (count > 0) {
+ ret = read(fd, buf, count);
+ if (ret <= 0) {
+ if ((errno == EAGAIN || errno == EINTR || ret == 0) &&
+ (tries++ < 5))
+ continue;
+ return c ? c : -1;
+ }
+ if (ret > 0)
+ tries = 0;
+ count -= ret;
+ buf += ret;
+ c += ret;
+ }
+ return c;
+}
+
+
+#endif /* UTIL_LINUX_READALL_H */
diff --git a/libuuid/src/gen_uuid.c b/libuuid/src/gen_uuid.c
index 93d292a..7212692 100644
--- a/libuuid/src/gen_uuid.c
+++ b/libuuid/src/gen_uuid.c
@@ -90,6 +90,7 @@
#include "uuidP.h"
#include "uuidd.h"
#include "randutils.h"
+#include "readall.h"
#ifdef HAVE_TLS
#define THREAD_LOCAL static __thread
@@ -334,31 +335,6 @@ try_again:
}
#if defined(HAVE_UUIDD) && defined(HAVE_SYS_UN_H)
-/* used in get_uuid_via_daemon() only */
-static ssize_t read_all(int fd, char *buf, size_t count)
-{
- ssize_t ret;
- ssize_t c = 0;
- int tries = 0;
-
- memset(buf, 0, count);
- while (count > 0) {
- ret = read(fd, buf, count);
- if (ret <= 0) {
- if ((errno == EAGAIN || errno == EINTR || ret == 0) &&
- (tries++ < 5))
- continue;
- return c ? c : -1;
- }
- if (ret > 0)
- tries = 0;
- count -= ret;
- buf += ret;
- c += ret;
- }
- return c;
-}
-
/*
* Try using the uuidd daemon to generate the UUID
*
diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c
index eb1ef02..98c740b 100644
--- a/misc-utils/uuidd.c
+++ b/misc-utils/uuidd.c
@@ -34,6 +34,7 @@ extern int optind;
#include "uuid.h"
#include "uuidd.h"
#include "writeall.h"
+#include "readall.h"
#include "c.h"
#include "closestream.h"
@@ -101,30 +102,6 @@ static void create_daemon(void)
err(EXIT_FAILURE, "setreuid");
}
-static ssize_t read_all(int fd, char *buf, size_t count)
-{
- ssize_t ret;
- ssize_t c = 0;
- int tries = 0;
-
- memset(buf, 0, count);
- while (count > 0) {
- ret = read(fd, buf, count);
- if (ret <= 0) {
- if ((errno == EAGAIN || errno == EINTR || ret == 0) &&
- (tries++ < 5))
- continue;
- return c ? c : -1;
- }
- if (ret > 0)
- tries = 0;
- count -= ret;
- buf += ret;
- c += ret;
- }
- return c;
-}
-
static const char *cleanup_pidfile, *cleanup_socket;
static void terminate_intr(int signo CODE_ATTR((unused)))
--
1.7.7
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] libuuid,uuidd: move read_all to include/readall.h
2012-05-13 7:37 [PATCH] libuuid,uuidd: move read_all to include/readall.h Petr Uzel
@ 2012-05-14 9:46 ` Karel Zak
2012-05-14 9:53 ` Petr Uzel
0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2012-05-14 9:46 UTC (permalink / raw)
To: Petr Uzel; +Cc: util-linux
On Sun, May 13, 2012 at 09:37:56AM +0200, Petr Uzel wrote:
> include/Makefile.am | 1 +
> include/readall.h | 33 +++++++++++++++++++++++++++++++++
> libuuid/src/gen_uuid.c | 26 +-------------------------
> misc-utils/uuidd.c | 25 +------------------------
> 4 files changed, 36 insertions(+), 49 deletions(-)
> create mode 100644 include/readall.h
Good idea, but do we really need writeall.h and readall.h ? ;-) What
about to merge both files? (all-io.h ?)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libuuid,uuidd: move read_all to include/readall.h
2012-05-14 9:46 ` Karel Zak
@ 2012-05-14 9:53 ` Petr Uzel
0 siblings, 0 replies; 3+ messages in thread
From: Petr Uzel @ 2012-05-14 9:53 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
[-- Attachment #1: Type: text/plain, Size: 671 bytes --]
On Mon, May 14, 2012 at 11:46:01AM +0200, Karel Zak wrote:
> On Sun, May 13, 2012 at 09:37:56AM +0200, Petr Uzel wrote:
> > include/Makefile.am | 1 +
> > include/readall.h | 33 +++++++++++++++++++++++++++++++++
> > libuuid/src/gen_uuid.c | 26 +-------------------------
> > misc-utils/uuidd.c | 25 +------------------------
> > 4 files changed, 36 insertions(+), 49 deletions(-)
> > create mode 100644 include/readall.h
>
> Good idea, but do we really need writeall.h and readall.h ? ;-) What
> about to merge both files? (all-io.h ?)
Sounds good, I'll merge them.
Thanks,
Petr
--
Petr Uzel
IRC: ptr_uzl @ freenode
[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-05-14 9:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-13 7:37 [PATCH] libuuid,uuidd: move read_all to include/readall.h Petr Uzel
2012-05-14 9:46 ` Karel Zak
2012-05-14 9:53 ` Petr Uzel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox