[Pkg-libvirt-commits] [libguestfs] 103/266: p2v: Rewrite /proc/cmdline reading code to use getline.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:41:47 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit 93c7842367fc5c99147b0ff4ab64dc52a476c7b8
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Thu Aug 14 16:58:22 2014 +0100

    p2v: Rewrite /proc/cmdline reading code to use getline.
---
 p2v/main.c | 46 +++++++++-------------------------------------
 1 file changed, 9 insertions(+), 37 deletions(-)

diff --git a/p2v/main.c b/p2v/main.c
index ebb18fc..c07ed86 100644
--- a/p2v/main.c
+++ b/p2v/main.c
@@ -489,48 +489,20 @@ find_all_interfaces (void)
 static char *
 read_cmdline (void)
 {
-  int fd;
-  size_t len = 0;
-  ssize_t n;
-  char buf[256];
-  char *r = NULL, *newr;
-
-  fd = open ("/proc/cmdline", O_RDONLY|O_CLOEXEC);
-  if (fd == -1) {
+  CLEANUP_FCLOSE FILE *fp = NULL;
+  char *ret = NULL;
+  size_t len;
+
+  fp = fopen ("/proc/cmdline", "re");
+  if (fp == NULL) {
     perror ("/proc/cmdline");
     return NULL;
   }
 
-  for (;;) {
-    n = read (fd, buf, sizeof buf);
-    if (n == -1) {
-      perror ("read");
-      free (r);
-      close (fd);
-      return NULL;
-    }
-    if (n == 0)
-      break;
-    newr = realloc (r, len + n + 1); /* + 1 is for terminating NUL */
-    if (newr == NULL) {
-      perror ("realloc");
-      free (r);
-      close (fd);
-      return NULL;
-    }
-    r = newr;
-    memcpy (&r[len], buf, n);
-    len += n;
-  }
-
-  if (r)
-    r[len] = '\0';
-
-  if (close (fd) == -1) {
-    perror ("close");
-    free (r);
+  if (getline (&ret, &len, fp) == -1) {
+    perror ("getline");
     return NULL;
   }
 
-  return r;
+  return ret;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list