libgtop r2790 - branches/gnome-2-24/sysdeps/linux
- From: bdejean svn gnome org
- To: svn-commits-list gnome org
- Subject: libgtop r2790 - branches/gnome-2-24/sysdeps/linux
- Date: Mon, 12 Jan 2009 18:39:44 +0000 (UTC)
Author: bdejean
Date: Mon Jan 12 18:39:44 2009
New Revision: 2790
URL: http://svn.gnome.org/viewvc/libgtop?rev=2790&view=rev
Log:
Fixed read(2) usage.
Closes #468495.
Modified:
branches/gnome-2-24/sysdeps/linux/glibtop_private.c
Modified: branches/gnome-2-24/sysdeps/linux/glibtop_private.c
==============================================================================
--- branches/gnome-2-24/sysdeps/linux/glibtop_private.c (original)
+++ branches/gnome-2-24/sysdeps/linux/glibtop_private.c Mon Jan 12 18:39:44 2009
@@ -67,14 +67,18 @@
TRY_FILE_TO_BUFFER_READ = -2
};
+/*
+ * Doesn't handle bufsiz == 0
+ */
int try_file_to_buffer(char *buffer, size_t bufsiz, const char *format, ...)
{
char path[4096];
int fd;
- ssize_t len;
+ size_t len = 0;
+ ssize_t nread = 0;
va_list pa;
- if (bufsiz <= sizeof(char*))
+ if (G_UNLIKELY(bufsiz <= sizeof(char*)))
g_warning("Huhu, bufsiz of %lu looks bad", (gulong)bufsiz);
va_start(pa, format);
@@ -84,15 +88,31 @@
va_end(pa);
+ bufsiz--; /* reserve 1 for trailing NUL */
buffer [0] = '\0';
if((fd = open (path, O_RDONLY)) < 0)
return TRY_FILE_TO_BUFFER_OPEN;
- len = read (fd, buffer, bufsiz - 1);
+ while (len < bufsiz) {
+ nread = read (fd, buffer + len, bufsiz - len);
+
+ if (G_UNLIKELY(nread < 0)) {
+ if (errno == EINTR)
+ continue;
+ else
+ break;
+ }
+
+ len += nread;
+
+ if (nread == 0)
+ break;
+ }
+
close (fd);
- if (len < 0)
+ if (nread < 0)
return TRY_FILE_TO_BUFFER_READ;
buffer [len] = '\0';
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]