Example #1
0
static int
read_lpj_common (guestfs_h *g, const char *func, struct command *cmd)
{
  int r;
  CLEANUP_FREE char *buf = NULL;

  guestfs___cmd_set_stdout_callback (cmd, read_all, &buf,
                                     CMD_STDOUT_FLAG_WHOLE_BUFFER);
  r = guestfs___cmd_run (cmd);
  if (r == -1)
    return -1;
  if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) {
    char status_string[80];

    debug (g, "%s: %s", func,
           guestfs___exit_status_to_string (r, "external command",
                                            status_string,
                                            sizeof status_string));
    return -1;
  }

  if (buf == NULL) {
    debug (g, "%s: callback not called", func);
    return -1;
  }

  if (strlen (buf) < 4 || sscanf (&buf[4], "%d", &r) != 1) {
    debug (g, "%s: invalid buffer returned by grep: %s", func, buf);
    return -1;
  }

  debug (g, "%s: calculated lpj=%d", func, r);

  return r;
}
Example #2
0
/* External command failed. */
void
guestfs___external_command_failed (guestfs_h *g, int status,
                                   const char *cmd_name, const char *extra)
{
  size_t len = 80 + strlen (cmd_name);
  char status_string[len];

  guestfs___exit_status_to_string (status, cmd_name, status_string, len);

  if (g->verbose) {
    if (!extra)
      error (g, _("%s, see debug messages above"), status_string);
    else
      error (g, _("%s: %s: %s, see debug messages above"),
             cmd_name, extra, status_string);
  }
  else {
    if (!extra)
      error (g, _(
"%s.\n"
"To see full error messages you may need to enable debugging.\n"
"See http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs"),
             status_string);
    else
      error (g, _(
"%s: %s: %s.\n"
"To see full error messages you may need to enable debugging.\n"
"See http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs"),
             cmd_name, extra, status_string);
  }
}