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

[Libguestfs] [nbdkit PATCH 09/10] tests: Avoid -Wshadow warnings



In test-layers, declaring a variable 'log' technically conflicts with
POSIX's rule that <math.h> reserves log(), even if we don't use
math.h.  Picking a different name shuts up the compiler.

In test-exit-with-parent, the use of 'pid' for the grandchild process
collides with the (unused) global 'pid' from test.h; but when you
realize that the use of 'nbdpid' in the child process does not collide
with its use in the monitor process, we don't need an extra
declaration.

In web-server, the only caller of xpread passed global 'fd' to a
shadowed name; just rely on the global instead.

Signed-off-by: Eric Blake <eblake redhat com>
---
 tests/test-exit-with-parent.c | 14 ++++++--------
 tests/test-layers.c           | 20 ++++++++++----------
 tests/web-server.c            |  6 +++---
 3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/tests/test-exit-with-parent.c b/tests/test-exit-with-parent.c
index 2bb5d8f5..9c98db44 100644
--- a/tests/test-exit-with-parent.c
+++ b/tests/test-exit-with-parent.c
@@ -92,10 +92,8 @@ run_test (void)
    */
   cpid = fork ();
   if (cpid == 0) {              /* child process */
-    pid_t pid;
-
-    pid = fork ();
-    if (pid == 0) {             /* exec nbdkit process */
+    nbdpid = fork ();
+    if (nbdpid == 0) {             /* exec nbdkit process */
       const char *argv[] = {
         "nbdkit", "-U", "-", "-P", pidpath, "-f", "--exit-with-parent",
         "example1",
@@ -109,20 +107,20 @@ run_test (void)

     /* Wait for the pidfile to turn up, which indicates that nbdkit has
      * started up successfully and is ready to serve requests.  However
-     * if 'pid' exits in this time it indicates a failure to start up.
+     * if 'nbdpid' exits in this time it indicates a failure to start up.
      * Also there is a timeout in case nbdkit hangs.
      */
     for (i = 0; i < NBDKIT_START_TIMEOUT; ++i) {
-      if (waitpid (pid, NULL, WNOHANG) == pid)
+      if (waitpid (nbdpid, NULL, WNOHANG) == nbdpid)
         goto early_exit;

-      if (kill (pid, 0) == -1) {
+      if (kill (nbdpid, 0) == -1) {
         if (errno == ESRCH) {
         early_exit:
           fprintf (stderr,
                    "%s FAILED: nbdkit exited before starting to serve files\n",
                    program_name);
-          pid = 0;
+          nbdpid = 0;
           exit (EXIT_FAILURE);
         }
         perror ("kill");
diff --git a/tests/test-layers.c b/tests/test-layers.c
index a7184d72..4d0167eb 100644
--- a/tests/test-layers.c
+++ b/tests/test-layers.c
@@ -615,7 +615,7 @@ main (int argc, char *argv[])
 }

 /* The log from nbdkit is captured in a separate thread. */
-static char *log = NULL;
+static char *log_buf = NULL;
 static size_t log_len = 0;
 static pthread_mutex_t log_lock = PTHREAD_MUTEX_INITIALIZER;

@@ -631,15 +631,15 @@ start_log_capture (void *arg)
       ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&log_lock);
       if (allocated <= log_len) {
         allocated += 4096;
-        log = realloc (log, allocated);
-        if (log == NULL) {
+        log_buf = realloc (log_buf, allocated);
+        if (log_buf == NULL) {
           perror ("log: realloc");
           exit (EXIT_FAILURE);
         }
       }
     }

-    r = read (fd, &log[log_len], allocated-log_len);
+    r = read (fd, &log_buf[log_len], allocated-log_len);
     if (r == -1) {
       perror ("log: read");
       exit (EXIT_FAILURE);
@@ -648,7 +648,7 @@ start_log_capture (void *arg)
       break;

     /* Dump the log as we receive it to stderr, for debugging. */
-    if (write (2, &log[log_len], r) == -1)
+    if (write (2, &log_buf[log_len], r) == -1)
       perror ("log: write");

     ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&log_lock);
@@ -679,7 +679,7 @@ static void
 log_verify_seen (const char *msg)
 {
   ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&log_lock);
-  if (memmem (log, log_len, msg, strlen (msg)) == NULL)
+  if (memmem (log_buf, log_len, msg, strlen (msg)) == NULL)
     no_message_error (msg);
 }

@@ -703,13 +703,13 @@ log_verify_seen_in_order (const char *msg, ...)

   ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&log_lock);

-  prev = memmem (log, log_len, msg, strlen (msg));
+  prev = memmem (log_buf, log_len, msg, strlen (msg));
   if (prev == NULL) no_message_error (msg);
   prev_msg = msg;

   va_start (args, msg);
   while ((curr_msg = va_arg (args, char *)) != NULL) {
-    curr = memmem (log, log_len, curr_msg, strlen (curr_msg));
+    curr = memmem (log_buf, log_len, curr_msg, strlen (curr_msg));
     if (curr == NULL) no_message_error (curr_msg);
     if (prev > curr) messages_out_of_order (prev_msg, curr_msg);
     prev_msg = curr_msg;
@@ -722,7 +722,7 @@ static void
 log_free (void)
 {
   ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&log_lock);
-  free (log);
-  log = NULL;
+  free (log_buf);
+  log_buf = NULL;
   log_len = 0;
 }
diff --git a/tests/web-server.c b/tests/web-server.c
index 83f90881..f27ee70d 100644
--- a/tests/web-server.c
+++ b/tests/web-server.c
@@ -66,7 +66,7 @@ static void *start_web_server (void *arg);
 static void handle_requests (int s);
 static void handle_request (int s, bool headers_only);
 static void xwrite (int s, const char *buf, size_t len);
-static void xpread (int fd, char *buf, size_t count, off_t offset);
+static void xpread (char *buf, size_t count, off_t offset);

 static void
 cleanup (void)
@@ -281,7 +281,7 @@ handle_request (int s, bool headers_only)
     exit (EXIT_FAILURE);
   }

-  xpread (fd, data, length, offset);
+  xpread (data, length, offset);
   xwrite (s, data, length);

   free (data);
@@ -304,7 +304,7 @@ xwrite (int s, const char *buf, size_t len)
 }

 static void
-xpread (int fd, char *buf, size_t count, off_t offset)
+xpread (char *buf, size_t count, off_t offset)
 {
   ssize_t r;

-- 
2.21.0


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