CLI for access to HQoS queue statistics
[vpp.git] / vlib-api / vlibapi / api_shared.c
index 18b189e..511f693 100644 (file)
@@ -774,12 +774,14 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
   if (fstat (fd, &statb) < 0)
     {
       vlib_cli_output (vm, "Couldn't stat %s\n", filename);
+      close (fd);
       return;
     }
 
   if (!(statb.st_mode & S_IFREG) || (statb.st_size < sizeof (*hp)))
     {
       vlib_cli_output (vm, "File not plausible: %s\n", filename);
+      close (fd);
       return;
     }
 
@@ -814,6 +816,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
     {
       vlib_cli_output (vm, "Range (%d, %d) outside file range (0, %d)\n",
                       first_index, last_index, nitems - 1);
+      munmap (hp, file_size);
       return;
     }
   if (hp->wrapped)
@@ -844,6 +847,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
       if (!cfgp)
        {
          vlib_cli_output (vm, "Ugh: msg id %d no trace config\n", msg_id);
+         munmap (hp, file_size);
          return;
        }
       size = cfgp->size;
@@ -869,6 +873,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
       if (!cfgp)
        {
          vlib_cli_output (vm, "Ugh: msg id %d no trace config\n", msg_id);
+         munmap (hp, file_size);
          return;
        }
       size = cfgp->size;
@@ -891,6 +896,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
              || (am->msg_endian_handlers[msg_id] == 0))
            {
              vlib_cli_output (vm, "Ugh: msg id %d no endian swap\n", msg_id);
+             munmap (hp, file_size);
              return;
            }
          endian_fp = am->msg_endian_handlers[msg_id];
@@ -1080,8 +1086,22 @@ api_trace_command_fn (vlib_main_t * vm,
            }
          rv = vl_msg_api_trace_save (am, which, fp);
          fclose (fp);
-         if (rv < 0)
-           vlib_cli_output (vm, "ERROR: %d", rv);
+         if (rv == -1)
+           vlib_cli_output (vm, "API Trace data not present\n");
+         else if (rv == -2)
+           vlib_cli_output (vm, "File for writing is closed\n");
+         else if (rv == -10)
+           vlib_cli_output (vm, "Error while writing header to file\n");
+         else if (rv == -11)
+           vlib_cli_output (vm, "Error while writing trace to file\n");
+         else if (rv == -12)
+           vlib_cli_output (vm,
+                            "Error while writing end of buffer trace to file\n");
+         else if (rv == -13)
+           vlib_cli_output (vm,
+                            "Error while writing start of buffer trace to file\n");
+         else if (rv < 0)
+           vlib_cli_output (vm, "Unkown error while saving: %d", rv);
          else
            vlib_cli_output (vm, "API trace saved to %s\n", chroot_filename);
          vec_free (chroot_filename);