[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 3/4] lib: Rename g->fd to console_sock and g->sock to daemon_sock.



From: "Richard W.M. Jones" <rjones redhat com>

This just renames the fields in the handle to more descriptive names.
There is no functional change.
---
 src/guestfs-internal.h |  4 +--
 src/handle.c           | 16 +++++------
 src/launch-appliance.c | 30 ++++++++++-----------
 src/launch-libvirt.c   | 32 +++++++++++-----------
 src/launch-unix.c      | 14 +++++-----
 src/proto.c            | 72 +++++++++++++++++++++++++-------------------------
 6 files changed, 84 insertions(+), 84 deletions(-)

diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 4c632e8..c63ea40 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -263,8 +263,8 @@ struct guestfs_h
   int unique;
 
   /*** Protocol. ***/
-  int fd;			/* Stdin/stdout of qemu. */
-  int sock;			/* Daemon communications socket. */
+  int console_sock;          /* Appliance console (for debug info). */
+  int daemon_sock;           /* Daemon communications socket. */
   int msg_next_serial;
 
 #if HAVE_FUSE
diff --git a/src/handle.c b/src/handle.c
index cefe385..47a2246 100644
--- a/src/handle.c
+++ b/src/handle.c
@@ -91,8 +91,8 @@ guestfs_create_flags (unsigned flags, ...)
 
   g->state = CONFIG;
 
-  g->fd = -1;
-  g->sock = -1;
+  g->console_sock = -1;
+  g->daemon_sock = -1;
 
   guestfs___init_error_handler (g);
   g->abort_cb = abort;
@@ -366,12 +366,12 @@ shutdown_backend (guestfs_h *g, int check_for_errors)
   }
 
   /* Close sockets. */
-  if (g->fd >= 0)
-    close (g->fd);
-  if (g->sock >= 0)
-    close (g->sock);
-  g->fd = -1;
-  g->sock = -1;
+  if (g->console_sock >= 0)
+    close (g->console_sock);
+  if (g->daemon_sock >= 0)
+    close (g->daemon_sock);
+  g->console_sock = -1;
+  g->daemon_sock = -1;
 
   if (g->attach_ops->shutdown (g, check_for_errors) == -1)
     ret = -1;
diff --git a/src/launch-appliance.c b/src/launch-appliance.c
index 30c139e..99bc541 100644
--- a/src/launch-appliance.c
+++ b/src/launch-appliance.c
@@ -210,13 +210,13 @@ launch_appliance (guestfs_h *g, const char *arg)
   snprintf (guestfsd_sock, sizeof guestfsd_sock, "%s/guestfsd.sock", g->tmpdir);
   unlink (guestfsd_sock);
 
-  g->sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
-  if (g->sock == -1) {
+  g->daemon_sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
+  if (g->daemon_sock == -1) {
     perrorf (g, "socket");
     goto cleanup0;
   }
 
-  if (fcntl (g->sock, F_SETFL, O_NONBLOCK) == -1) {
+  if (fcntl (g->daemon_sock, F_SETFL, O_NONBLOCK) == -1) {
     perrorf (g, "fcntl");
     goto cleanup0;
   }
@@ -225,12 +225,12 @@ launch_appliance (guestfs_h *g, const char *arg)
   strncpy (addr.sun_path, guestfsd_sock, UNIX_PATH_MAX);
   addr.sun_path[UNIX_PATH_MAX-1] = '\0';
 
-  if (bind (g->sock, &addr, sizeof addr) == -1) {
+  if (bind (g->daemon_sock, &addr, sizeof addr) == -1) {
     perrorf (g, "bind");
     goto cleanup0;
   }
 
-  if (listen (g->sock, 1) == -1) {
+  if (listen (g->daemon_sock, 1) == -1) {
     perrorf (g, "listen");
     goto cleanup0;
   }
@@ -611,7 +611,7 @@ launch_appliance (guestfs_h *g, const char *arg)
       goto cleanup1;
     }
 
-    g->fd = sv[0];		/* stdin of child */
+    g->console_sock = sv[0];    /* stdin of child */
     sv[0] = -1;
   }
 
@@ -632,15 +632,15 @@ launch_appliance (guestfs_h *g, const char *arg)
    */
 
   /* Close the listening socket. */
-  if (close (g->sock) != 0) {
+  if (close (g->daemon_sock) != 0) {
     perrorf (g, "close: listening socket");
     close (r);
-    g->sock = -1;
+    g->daemon_sock = -1;
     goto cleanup1;
   }
-  g->sock = r; /* This is the accepted data socket. */
+  g->daemon_sock = r; /* This is the accepted data socket. */
 
-  if (fcntl (g->sock, F_SETFL, O_NONBLOCK) == -1) {
+  if (fcntl (g->daemon_sock, F_SETFL, O_NONBLOCK) == -1) {
     perrorf (g, "fcntl");
     goto cleanup1;
   }
@@ -686,16 +686,16 @@ launch_appliance (guestfs_h *g, const char *arg)
   if (g->app.recoverypid > 0) kill (g->app.recoverypid, 9);
   if (g->app.pid > 0) waitpid (g->app.pid, NULL, 0);
   if (g->app.recoverypid > 0) waitpid (g->app.recoverypid, NULL, 0);
-  if (g->fd >= 0) close (g->fd);
-  g->fd = -1;
+  if (g->console_sock >= 0) close (g->console_sock);
+  g->console_sock = -1;
   g->app.pid = 0;
   g->app.recoverypid = 0;
   memset (&g->launch_t, 0, sizeof g->launch_t);
 
  cleanup0:
-  if (g->sock >= 0) {
-    close (g->sock);
-    g->sock = -1;
+  if (g->daemon_sock >= 0) {
+    close (g->daemon_sock);
+    g->daemon_sock = -1;
   }
   g->state = CONFIG;
   return -1;
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index caad5d4..d771392 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -258,13 +258,13 @@ launch_libvirt (guestfs_h *g, const char *libvirt_uri)
 
   set_socket_create_context (g);
 
-  g->sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
-  if (g->sock == -1) {
+  g->daemon_sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
+  if (g->daemon_sock == -1) {
     perrorf (g, "socket");
     goto cleanup;
   }
 
-  if (fcntl (g->sock, F_SETFL, O_NONBLOCK) == -1) {
+  if (fcntl (g->daemon_sock, F_SETFL, O_NONBLOCK) == -1) {
     perrorf (g, "fcntl");
     goto cleanup;
   }
@@ -272,12 +272,12 @@ launch_libvirt (guestfs_h *g, const char *libvirt_uri)
   addr.sun_family = AF_UNIX;
   memcpy (addr.sun_path, params.guestfsd_sock, UNIX_PATH_MAX);
 
-  if (bind (g->sock, &addr, sizeof addr) == -1) {
+  if (bind (g->daemon_sock, &addr, sizeof addr) == -1) {
     perrorf (g, "bind");
     goto cleanup;
   }
 
-  if (listen (g->sock, 1) == -1) {
+  if (listen (g->daemon_sock, 1) == -1) {
     perrorf (g, "listen");
     goto cleanup;
   }
@@ -399,7 +399,7 @@ launch_libvirt (guestfs_h *g, const char *libvirt_uri)
     goto cleanup;
   }
   console = -1;
-  g->fd = r;                /* This is the accepted console socket. */
+  g->console_sock = r;      /* This is the accepted console socket. */
 
   /* Wait for libvirt domain to start and to connect back to us via
    * virtio-serial and send the GUESTFS_LAUNCH_FLAG message.
@@ -416,15 +416,15 @@ launch_libvirt (guestfs_h *g, const char *libvirt_uri)
    */
 
   /* Close the listening socket. */
-  if (close (g->sock) == -1) {
+  if (close (g->daemon_sock) == -1) {
     perrorf (g, "close: listening socket");
     close (r);
-    g->sock = -1;
+    g->daemon_sock = -1;
     goto cleanup;
   }
-  g->sock = r; /* This is the accepted data socket. */
+  g->daemon_sock = r; /* This is the accepted data socket. */
 
-  if (fcntl (g->sock, F_SETFL, O_NONBLOCK) == -1) {
+  if (fcntl (g->daemon_sock, F_SETFL, O_NONBLOCK) == -1) {
     perrorf (g, "fcntl");
     goto cleanup;
   }
@@ -475,13 +475,13 @@ launch_libvirt (guestfs_h *g, const char *libvirt_uri)
 
   if (console >= 0)
     close (console);
-  if (g->fd >= 0) {
-    close (g->fd);
-    g->fd = -1;
+  if (g->console_sock >= 0) {
+    close (g->console_sock);
+    g->console_sock = -1;
   }
-  if (g->sock >= 0) {
-    close (g->sock);
-    g->sock = -1;
+  if (g->daemon_sock >= 0) {
+    close (g->daemon_sock);
+    g->daemon_sock = -1;
   }
 
   if (dom) {
diff --git a/src/launch-unix.c b/src/launch-unix.c
index a7a3ae2..69de2f7 100644
--- a/src/launch-unix.c
+++ b/src/launch-unix.c
@@ -49,13 +49,13 @@ launch_unix (guestfs_h *g, const char *sockpath)
   /* Set this to nothing so we don't try to read from a random file
    * descriptor.
    */
-  g->fd = -1;
+  g->console_sock = -1;
 
   if (g->verbose)
     guestfs___print_timestamped_message (g, "connecting to %s", sockpath);
 
-  g->sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
-  if (g->sock == -1) {
+  g->daemon_sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
+  if (g->daemon_sock == -1) {
     perrorf (g, "socket");
     return -1;
   }
@@ -66,12 +66,12 @@ launch_unix (guestfs_h *g, const char *sockpath)
 
   g->state = LAUNCHING;
 
-  if (connect (g->sock, &addr, sizeof addr) == -1) {
+  if (connect (g->daemon_sock, &addr, sizeof addr) == -1) {
     perrorf (g, "bind");
     goto cleanup;
   }
 
-  if (fcntl (g->sock, F_SETFL, O_NONBLOCK) == -1) {
+  if (fcntl (g->daemon_sock, F_SETFL, O_NONBLOCK) == -1) {
     perrorf (g, "fcntl");
     goto cleanup;
   }
@@ -97,14 +97,14 @@ launch_unix (guestfs_h *g, const char *sockpath)
   return 0;
 
  cleanup:
-  close (g->sock);
+  close (g->daemon_sock);
   return -1;
 }
 
 static int
 shutdown_unix (guestfs_h *g, int check_for_errors)
 {
-  /* Merely closing g->sock is sufficient and that is already done
+  /* Merely closing g->daemon_sock is sufficient and that is already done
    * in the calling code.
    */
   return 0;
diff --git a/src/proto.c b/src/proto.c
index 57cb609..569b805 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -161,10 +161,10 @@ child_cleanup (guestfs_h *g)
   debug (g, "child_cleanup: %p: child process died", g);
 
   g->attach_ops->shutdown (g, 0);
-  if (g->fd >= 0) close (g->fd);
-  close (g->sock);
-  g->fd = -1;
-  g->sock = -1;
+  if (g->console_sock >= 0) close (g->console_sock);
+  close (g->daemon_sock);
+  g->console_sock = -1;
+  g->daemon_sock = -1;
   memset (&g->launch_t, 0, sizeof g->launch_t);
   guestfs___free_drives (g);
   g->state = CONFIG;
@@ -383,12 +383,12 @@ send_to_daemon (guestfs_h *g, const void *v_buf, size_t n)
   FD_ZERO (&rset);
   FD_ZERO (&wset);
 
-  if (g->fd >= 0)               /* Read qemu stdout for log messages & EOF. */
-    FD_SET (g->fd, &rset);
-  FD_SET (g->sock, &rset);      /* Read socket for cancellation & EOF. */
-  FD_SET (g->sock, &wset);      /* Write to socket to send the data. */
+  if (g->console_sock >= 0) /* Read qemu stdout for log messages & EOF. */
+    FD_SET (g->console_sock, &rset);
+  FD_SET (g->daemon_sock, &rset); /* Read socket for cancellation & EOF. */
+  FD_SET (g->daemon_sock, &wset); /* Write to socket to send the data. */
 
-  int max_fd = MAX (g->sock, g->fd);
+  int max_fd = MAX (g->daemon_sock, g->console_sock);
 
   while (n > 0) {
     rset2 = rset;
@@ -401,12 +401,12 @@ send_to_daemon (guestfs_h *g, const void *v_buf, size_t n)
       return -1;
     }
 
-    if (g->fd >= 0 && FD_ISSET (g->fd, &rset2)) {
-      if (read_log_message_or_eof (g, g->fd, 0) == -1)
+    if (g->console_sock >= 0 && FD_ISSET (g->console_sock, &rset2)) {
+      if (read_log_message_or_eof (g, g->console_sock, 0) == -1)
         return -1;
     }
-    if (FD_ISSET (g->sock, &rset2)) {
-      r = check_for_daemon_cancellation_or_eof (g, g->sock);
+    if (FD_ISSET (g->daemon_sock, &rset2)) {
+      r = check_for_daemon_cancellation_or_eof (g, g->daemon_sock);
       if (r == -1)
 	return r;
       if (r == -2) {
@@ -414,15 +414,15 @@ send_to_daemon (guestfs_h *g, const void *v_buf, size_t n)
 	 * synchronization we must write out the remainder of the
 	 * write buffer before we return (RHBZ#576879).
 	 */
-	if (xwrite (g->sock, buf, n) == -1) {
+	if (xwrite (g->daemon_sock, buf, n) == -1) {
 	  perrorf (g, "write");
 	  return -1;
 	}
 	return -2; /* cancelled */
       }
     }
-    if (FD_ISSET (g->sock, &wset2)) {
-      r = write (g->sock, buf, n);
+    if (FD_ISSET (g->daemon_sock, &wset2)) {
+      r = write (g->daemon_sock, buf, n);
       if (r == -1) {
         if (errno == EINTR || errno == EAGAIN)
           continue;
@@ -507,18 +507,18 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
    * socket connection just before this function is called, so just
    * return an error if this happens.
    */
-  if (g->sock == -1) {
+  if (g->daemon_sock == -1) {
     unexpected_closed_connection_from_daemon_error (g);
     return -1;
   }
 
   FD_ZERO (&rset);
 
-  if (g->fd >= 0)               /* Read qemu stdout for log messages & EOF. */
-    FD_SET (g->fd, &rset);
-  FD_SET (g->sock, &rset);      /* Read socket for data & EOF. */
+  if (g->console_sock >= 0) /* Read qemu stdout for log messages & EOF. */
+    FD_SET (g->console_sock, &rset);
+  FD_SET (g->daemon_sock, &rset); /* Read socket for data & EOF. */
 
-  max_fd = MAX (g->sock, g->fd);
+  max_fd = MAX (g->daemon_sock, g->console_sock);
 
   *size_rtn = 0;
   *buf_rtn = NULL;
@@ -546,16 +546,16 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
       return -1;
     }
 
-    if (g->fd >= 0 && FD_ISSET (g->fd, &rset2)) {
-      if (read_log_message_or_eof (g, g->fd, 0) == -1) {
+    if (g->console_sock >= 0 && FD_ISSET (g->console_sock, &rset2)) {
+      if (read_log_message_or_eof (g, g->console_sock, 0) == -1) {
         free (*buf_rtn);
         *buf_rtn = NULL;
         return -1;
       }
     }
-    if (FD_ISSET (g->sock, &rset2)) {
+    if (FD_ISSET (g->daemon_sock, &rset2)) {
       if (nr < 0) {    /* Have we read the message length word yet? */
-        r = read (g->sock, lenbuf+nr+4, -nr);
+        r = read (g->daemon_sock, lenbuf+nr+4, -nr);
         if (r == -1) {
           if (errno == EINTR || errno == EAGAIN)
             continue;
@@ -623,7 +623,7 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
       size_t sizetoread = message_size - nr;
       if (sizetoread > BUFSIZ) sizetoread = BUFSIZ;
 
-      r = read (g->sock, (char *) (*buf_rtn) + nr, sizetoread);
+      r = read (g->daemon_sock, (char *) (*buf_rtn) + nr, sizetoread);
       if (r == -1) {
         if (errno == EINTR || errno == EAGAIN)
           continue;
@@ -712,7 +712,7 @@ guestfs___recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
   return 0;
 }
 
-/* This is very much like recv_from_daemon above, but g->sock is
+/* This is very much like recv_from_daemon above, but g->daemon_sock is
  * a listening socket and we are accepting a new connection on
  * that socket instead of reading anything.  Returns the newly
  * accepted socket.
@@ -726,11 +726,11 @@ guestfs___accept_from_daemon (guestfs_h *g)
 
   FD_ZERO (&rset);
 
-  if (g->fd >= 0)               /* Read qemu stdout for log messages & EOF. */
-    FD_SET (g->fd, &rset);
-  FD_SET (g->sock, &rset);      /* Read socket for accept. */
+  if (g->console_sock >= 0) /* Read qemu stdout for log messages & EOF. */
+    FD_SET (g->console_sock, &rset);
+  FD_SET (g->daemon_sock, &rset); /* Read socket for accept. */
 
-  int max_fd = MAX (g->sock, g->fd);
+  int max_fd = MAX (g->daemon_sock, g->console_sock);
   int sock = -1;
 
   while (sock == -1) {
@@ -758,12 +758,12 @@ guestfs___accept_from_daemon (guestfs_h *g)
       return -1;
     }
 
-    if (g->fd >= 0 && FD_ISSET (g->fd, &rset2)) {
-      if (read_log_message_or_eof (g, g->fd, 1) == -1)
+    if (g->console_sock >= 0 && FD_ISSET (g->console_sock, &rset2)) {
+      if (read_log_message_or_eof (g, g->console_sock, 1) == -1)
         return -1;
     }
-    if (FD_ISSET (g->sock, &rset2)) {
-      sock = accept4 (g->sock, NULL, NULL, SOCK_CLOEXEC);
+    if (FD_ISSET (g->daemon_sock, &rset2)) {
+      sock = accept4 (g->daemon_sock, NULL, NULL, SOCK_CLOEXEC);
       if (sock == -1) {
         if (errno == EINTR || errno == EAGAIN)
           continue;
@@ -1154,7 +1154,7 @@ guestfs___recv_file (guestfs_h *g, const char *filename)
   xdr_uint32_t (&xdr, &flag);
   xdr_destroy (&xdr);
 
-  if (xwrite (g->sock, fbuf, sizeof fbuf) == -1) {
+  if (xwrite (g->daemon_sock, fbuf, sizeof fbuf) == -1) {
     perrorf (g, _("write to daemon socket"));
     return -1;
   }
-- 
1.8.1.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]