Example #1
0
int printDarwinInfo(FILE *out, int indent, const MachineDarwinInfo *ptr) {
    static const char* state_names[MAX_STATE] = {
        "total",
        "idle",
        "running",
        "sleeping",
        "waiting",
        "stopped",
        "zombie",
        "other"
    };

    /* <ram .../> tag */
    fprintf(out, "%*s<ram total=\"%"PRIu64"\" avail=\"%"PRIu64"\" active=\"%"PRIu64"\" inactive=\"%"PRIu64"\" wired=\"%"PRIu64"\"/>\n",
            indent, "",
            ptr->ram_total / 1024,
            ptr->ram_avail / 1024,
            ptr->ram_active / 1024,
            ptr->ram_inactive / 1024,
            ptr->ram_wired / 1024);

    /* <swap .../> tag */
    fprintf(out, "%*s<swap total=\"%"PRIu64"\" avail=\"%"PRIu64"\" used=\"%"PRIu64"\"/>\n", indent, "",
            ptr->swap_total / 1024,
            ptr->swap_avail / 1024,
            ptr->swap_used / 1024);

    /* <boot> element */
    fprintf(out, "%*s<boot>%s</boot>\n", indent, "",
            fmtisodate(ptr->boottime.tv_sec, ptr->boottime.tv_usec));

    /* <cpu> element */
    fprintf(out, "%*s<cpu count=\"%hu\" speed=\"%lu\" vendor=\"%s\">%s</cpu>\n",
            indent, "", ptr->cpu_count, ptr->megahertz, ptr->vendor_id, ptr->model_name);

    /* loadavg data */
    fprintf(out, "%*s<load min1=\"%.2f\" min5=\"%.2f\" min15=\"%.2f\"/>\n",
            indent, "", ptr->load[0], ptr->load[1], ptr->load[2]);

    /* <proc> element */
    fprintf(out, "%*s<proc", indent, "");
    for (DarwinState s = STATE_TOTAL; s < MAX_STATE; ++s) {
        if (ptr->pid_state[s]) {
            fprintf(out, " %s=\"%u\"", state_names[s], ptr->pid_state[s]);
        }
    }
    fprintf(out, "/>\n");

    return 0;
}
Example #2
0
int startBasicMachine(FILE *out, int indent, const char* tag,
                      const MachineBasicInfo* machine) {
    /* purpose: start format the information into the given stream as XML.
     * paramtr: out (IO): the stream
     *          indent (IN): indentation level
     *          tag (IN): name to use for element tags.
     *          machine (IN): basic machine structure info to print.
     * returns: 0 if no error
     */
    /* sanity check */
    if (machine == NULL) {
        return 0;
    }

    /* <machine> open tag */
    fprintf(out, "%*s<%s page-size=\"%lu\">\n", indent-2, "", tag,
            machine->pagesize);

    /* <stamp> */
    fprintf(out, "%*s<stamp>%s</stamp>\n", indent, "",
            fmtisodate(machine->stamp.tv_sec,
                       machine->stamp.tv_usec));

    /* <uname> */
    fprintf(out, "%*s<uname", indent, "");
    fprintf(out, " system=\"%s\"", machine->uname.sysname);
    fprintf(out, " nodename=\"%s\"", machine->uname.nodename);
    fprintf(out, " release=\"%s\"", machine->uname.release);
    fprintf(out, " machine=\"%s\"", machine->uname.machine);
    fprintf(out, ">%s</uname>\n", machine->uname.version);

    /* <"provider"> grouping tag */
    fprintf(out, "%*s<%s>\n", indent, "", machine->provider);

    return 0;
}
Example #3
0
int
printXMLJobInfo(FILE *out, int indent, const char* tag, 
                const JobInfo* job)
/* purpose: format the job information into the given stream as XML.
 * paramtr: out (IO): the stream
 *          indent (IN): indentation level
 *          tag (IN): name to use for element tags.
 *          job (IN): job info to print.
 * returns: number of characters put into buffer (buffer length)
 */
{
  int status;        /* $#@! broken Debian headers */

  /* sanity check */
  if (!job->isValid) return 0;

  /* start tag with indentation */
  fprintf(out, "%*s<%s start=\"%s\"", indent, "", tag,
          fmtisodate(isLocal, isExtended, job->start.tv_sec,
                     job->start.tv_usec));
  fprintf(out, " duration=\"%.3f\"",
          doubletime(job->finish) - doubletime(job->start));

  /* optional attribute: application process id */
  if (job->child != 0)
    fprintf(out, " pid=\"%d\"", job->child);

  /* finalize open tag of element */
  fprintf(out, ">\n");

  /* <usage> */
  printXMLUseInfo(out, indent+2, "usage", &job->use);

  /* <status>: open tag */
  fprintf(out, "%*s<status raw=\"%d\">", indent+2, "", job->status);

  /* <status>: cases of completion */
  status = (int) job->status;        /* $#@! broken Debian headers */
  if (job->status < 0) {
    /* <failure> */
    fprintf(out, "<failure error=\"%d\">%s%s</failure>", job->saverr,
            job->prefix && job->prefix[0] ? job->prefix : "",
            strerror(job->saverr));
  } else if (WIFEXITED(status)) {
    fprintf(out, "<regular exitcode=\"%d\"/>", WEXITSTATUS(status));
  } else if (WIFSIGNALED(status)) {
    /* result = 128 + WTERMSIG(status); */
    fprintf(out, "<signalled signal=\"%u\"", WTERMSIG(status));
#ifdef WCOREDUMP
    fprintf(out, " corefile=\"%s\"", WCOREDUMP(status) ? "true" : "false");
#endif
    fprintf(out, ">%s</signalled>",
#if defined(CYGWINNT50) || defined(CYGWINNT51)
             "unknown"
#else
             sys_siglist[WTERMSIG(status)]
#endif
    );
  } else if (WIFSTOPPED(status)) {
    fprintf(out, "<suspended signal=\"%u\">%s</suspended>", WSTOPSIG(status),
#if defined(CYGWINNT50) || defined(CYGWINNT51)
             "unknown"
#else
             sys_siglist[WSTOPSIG(status)]
#endif
    );
  } /* FIXME: else? */
  fprintf(out, "</status>\n");

  /* <executable> */
  printXMLStatInfo(out, indent+2, "statcall", NULL, &job->executable);

#ifdef WITH_NEW_ARGS
  /* alternative 1: new-style <argument-vector> */
  fprintf(out, "%*s<argument-vector", indent+2, "");
  if (job->argc == 1) {
    /* empty element */
    fprintf(out, "/>\n");
  } else {
    /* content are the CLI args */
    int i;

    fprintf(out, ">\n");
    for (i=1; i<job->argc; ++i) {
      fprintf(out, "%*s<arg nr=\"%d\">", indent+4, "", i);
      xmlquote(out, job->argv[i], strlen(job->argv[i]));
      fprintf(out, "</arg>\n");
    }

    /* end tag */
    fprintf(out, "%*s</argument-vector>\n", indent+2, "");
  }
#else
  /* alternative 2: old-stlye <arguments> */
  fprintf(out, "%*s<arguments", indent+2, "");
  if (job->argc == 1) {
    /* empty element */
    fprintf(out, "/>\n");
  } else {
    /* content are the CLI args */
    int i = 1;

    fprintf(out, ">");
    while (i < job->argc) {
      xmlquote(out, job->argv[i], strlen(job->argv[i]));
      if (++i < job->argc) fprintf(out, " ");
    }

    /* end tag */
    fprintf(out, "</arguments>\n");
  }
#endif /* WITH_NEW_ARGS */

  /* <proc>s */
  printXMLProcInfo(out, indent+2, job->children);

  /* finalize close tag of outmost element */
  fprintf(out, "%*s</%s>\n", indent, "", tag);

  return 0;
}
Example #4
0
int printLinuxInfo(FILE *out, int indent, const MachineLinuxInfo *ptr) {
    static const char* state_names[MAX_STATE] = {
        "running",
        "sleeping",
        "waiting",
        "stopped",
        "zombie",
        "other"
    };

    char b[4][32];

    /* <ram .../> tag */
    fprintf(out, "%*s<ram total=\"%s\" free=\"%s\" shared=\"%s\" buffer=\"%s\"/>\n",
            indent, "",
            sizer(b[0], 32, sizeof(ptr->ram_total), &(ptr->ram_total)),
            sizer(b[1], 32, sizeof(ptr->ram_free), &(ptr->ram_free)),
            sizer(b[2], 32, sizeof(ptr->ram_total), &(ptr->ram_shared)),
            sizer(b[3], 32, sizeof(ptr->ram_free), &(ptr->ram_buffer)));

    /* <swap .../> tag */
    fprintf(out, "%*s<swap total=\"%s\" free=\"%s\"/>\n", indent, "",
            sizer(b[0], 32, sizeof(ptr->swap_total), &(ptr->swap_total)),
            sizer(b[1], 32, sizeof(ptr->swap_free), &(ptr->swap_free)));

    /* <boot> element */
    fprintf(out, "%*s<boot idle=\"%.3f\">%s</boot>\n", indent, "",
            ptr->idletime,
            fmtisodate(ptr->boottime.tv_sec, ptr->boottime.tv_usec));

    /* <cpu> element */
    fprintf(out, "%*s<cpu count=\"%hu\" speed=\"%lu\" vendor=\"%s\">%s</cpu>\n",
            indent, "", ptr->cpu_count, ptr->megahertz, ptr->vendor_id,
            ptr->model_name);

    /* <load> element */
    fprintf(out, "%*s<load min1=\"%.2f\" min5=\"%.2f\" min15=\"%.2f\"/>\n",
            indent, "", ptr->load[0], ptr->load[1], ptr->load[2]);

    if (ptr->procs.total && ptr->tasks.total) {
        /* <procs> element */
        fprintf(out, "%*s<procs total=\"%u\"", indent, "", ptr->procs.total);
        for (LinuxState s=S_RUNNING; s<=S_OTHER; ++s) {
            if (ptr->procs.state[s]) {
                fprintf(out, " %s=\"%hu\"", state_names[s], ptr->procs.state[s]);
            }
        }
        fprintf(out, " vmsize=\"%s\" rss=\"%s\"/>\n",
                sizer(b[0], 32, sizeof(ptr->procs.size), &ptr->procs.size),
                sizer(b[1], 32, sizeof(ptr->procs.rss), &ptr->procs.rss));

        /* <task> element */
        fprintf(out, "%*s<task total=\"%u\"", indent, "", ptr->tasks.total);
        for (LinuxState s=S_RUNNING; s<=S_OTHER; ++s) {
            if (ptr->tasks.state[s]) {
                fprintf(out, " %s=\"%hu\"", state_names[s], ptr->tasks.state[s]);
            }
        }

        /* vmsize and rss do not make sense for threads b/c they share memory */

        fprintf(out, "/>\n");
    }

    return 0;
}
Example #5
0
int printYAMLJobInfo(FILE *out, int indent, const char* tag, const JobInfo* job) {
    /* purpose: format the job information into the given stream as YAML.
     * paramtr: out (IO): the stream
     *          indent (IN): indentation level
     *          tag (IN): name to use for element tags.
     *          job (IN): job info to print.
     * returns: number of characters put into buffer (buffer length)
     */

    /* sanity check */
    if (!job->isValid) {
        return 0;
    }

    /* start tag with indentation */
    fprintf(out, "%*s%s:\n", indent, "", tag);
    fprintf(out, "%*s  start: %s\n", indent, "", 
            fmtisodate(job->start.tv_sec, job->start.tv_usec));
    fprintf(out, "%*s  duration: %.3f\n", indent, "", 
            doubletime(job->finish) - doubletime(job->start));

    /* optional attribute: application process id */
    if (job->child != 0) {
        fprintf(out, "%*s  pid: %d\n", indent, "", job->child);
    }

    /* <usage> */
    printYAMLUseInfo(out, indent+2, "usage", &job->use);

    int status = (int) job->status;

    /* <status>: open tag */
    fprintf(out, "%*sstatus:\n%*sraw: %d\n",
                 indent+2, "", indent+4, "", status);

    /* <status>: cases of completion */
    if (status < 0) {
        /* <failure> */
        fprintf(out, "%*sfailure_error: %d   %s%s\n", indent+4, "",
                     job->saverr,
                     job->prefix && job->prefix[0] ? job->prefix : "",
                     strerror(job->saverr));
    } else if (WIFEXITED(status)) {
        fprintf(out, "%*sregular_exitcode: %d\n", indent+4, "",
                     WEXITSTATUS(status));
    } else if (WIFSIGNALED(status)) {
        /* result = 128 + WTERMSIG(status); */
        fprintf(out, "%*ssignalled_signal: %u\n", indent+4, "",
                     WTERMSIG(status));
        fprintf(out, "%*ssingalled_name: %s\n", indent+4, "",
                     sys_siglist[WTERMSIG(status)]);
#ifdef WCOREDUMP
        fprintf(out, "%*scorefile: %s\n", indent+4, "",
                     WCOREDUMP(status) ? "true" : "false");
#endif
    } else if (WIFSTOPPED(status)) {
        fprintf(out, "%*ssuspended_signal: %u\n", indent+4, "",
                     WSTOPSIG(status));
        fprintf(out, "%*ssuspended_name: %s\n", indent+4, "",
                sys_siglist[WSTOPSIG(status)]);
    } /* FIXME: else? */

    /* <executable> */
    printYAMLStatInfo(out, indent+2, "executable", &job->executable, 1, 0, 1);

    /* alternative 1: new-style <argument-vector> */
    fprintf(out, "%*sargument_vector:\n", indent+2, "");
    if (job->argc > 1) {
        /* content are the CLI args */
        int i;
        for (i=1; i<job->argc; ++i) {
            fprintf(out, "%*s- %s\n", indent+4, "", job->argv[i]);
        }
    }

    /* <proc>s */
    printYAMLProcInfo(out, indent+2, job->children);

    return 0;
}
Example #6
0
size_t printXMLStatInfo(FILE *out, int indent, const char* tag, const char* id,
                        const StatInfo* info, int includeData, int useCDATA) {
    char *real = NULL;

    /* sanity check */
    if (info->source == IS_INVALID) {
        return 0;
    }

    /* start main tag */
    fprintf(out, "%*s<%s error=\"%d\"", indent, "", tag, info->error);
    if (id != NULL) {
        fprintf(out, " id=\"%s\"", id);
    }
    if (info->lfn != NULL) {
        fprintf(out, " lfn=\"%s\"", info->lfn);
    }
    fprintf(out, ">\n");

    /* NEW: ignore "file not found" error for "kickstart" */
    if (id != NULL && info->error == 2 && strcmp(id, "kickstart") == 0) {
        fprintf(out, "%*s<!-- ignore above error -->\n", indent+2, "");
    }

    /* either a <name> or <descriptor> sub element */
    switch (info->source) {
        case IS_TEMP:   /* preparation for <temporary> element */
            /* late update for temp files */
            errno = 0;
            if (fstat(info->file.descriptor, (struct stat*) &info->info) != -1 &&
                (((StatInfo*) info)->error = errno) == 0) {

                /* obtain header of file */
                int fd = dup(info->file.descriptor);
                if (fd != -1) {
                    if (lseek(fd, 0, SEEK_SET) != -1) {
                        read(fd, (char*) info->client.header, sizeof(info->client.header));
                    }
                    close(fd);
                }
            }

            fprintf(out, "%*s<temporary name=\"%s\" descriptor=\"%d\"/>\n",
                    indent+2, "", info->file.name, info->file.descriptor);
            break;

        case IS_FIFO: /* <fifo> element */
            fprintf(out, "%*s<fifo name=\"%s\" descriptor=\"%d\" count=\"%zu\" rsize=\"%zu\" wsize=\"%zu\"/>\n",
                    indent+2, "", info->file.name, info->file.descriptor,
                    info->client.fifo.count, info->client.fifo.rsize,
                    info->client.fifo.wsize);
            break;

        case IS_FILE: /* <file> element */
            real = realpath(info->file.name, NULL);
            fprintf(out, "%*s<file name=\"%s\"", indent+2, "", real ? real : info->file.name);
            if (real) {
                free((void*) real);
            }

            if (info->error == 0 &&
                S_ISREG(info->info.st_mode) &&
                info->info.st_size > 0) {

                /* optional hex information */
                size_t i, end = sizeof(info->client.header);
                if (info->info.st_size < end) end = info->info.st_size;

                fprintf(out, ">");
                for (i=0; i<end; ++i) {
                    fprintf(out, "%02X", info->client.header[i]);
                }
                fprintf(out, "</file>\n");
            } else {
                fprintf(out, "/>\n");
            }
            break;

        case IS_HANDLE: /* <descriptor> element */
            fprintf(out, "%*s<descriptor number=\"%u\"/>\n", indent+2, "",
                    info->file.descriptor);
            break;

        default: /* this must not happen! */
            fprintf(out, "%*s<!-- ERROR: No valid file info available -->\n",
                    indent+2, "");
            break;
    }

    if (info->error == 0 && info->source != IS_INVALID) {
        /* <stat> subrecord */
        char my[32];
        struct passwd* user = getpwuid(info->info.st_uid);
        struct group* group = getgrgid(info->info.st_gid);

        fprintf(out, "%*s<statinfo mode=\"0%o\"", indent+2, "",
                info->info.st_mode);

        /* Grmblftz, are we in 32bit, 64bit LFS on 32bit, or 64bit on 64 */
        sizer(my, sizeof(my), sizeof(info->info.st_size), &info->info.st_size);
        fprintf(out, " size=\"%s\"", my);

        sizer(my, sizeof(my), sizeof(info->info.st_ino), &info->info.st_ino);
        fprintf(out, " inode=\"%s\"", my);

        sizer(my, sizeof(my), sizeof(info->info.st_nlink), &info->info.st_nlink);
        fprintf(out, " nlink=\"%s\"", my);

        sizer(my, sizeof(my), sizeof(info->info.st_blksize), &info->info.st_blksize);
        fprintf(out, " blksize=\"%s\"", my);

        /* st_blocks is new in iv-1.8 */
        sizer(my, sizeof(my), sizeof(info->info.st_blocks), &info->info.st_blocks);
        fprintf(out, " blocks=\"%s\"", my);

        fprintf(out, " mtime=\"%s\"", fmtisodate(info->info.st_mtime, -1));
        fprintf(out, " atime=\"%s\"", fmtisodate(info->info.st_atime, -1));
        fprintf(out, " ctime=\"%s\"", fmtisodate(info->info.st_ctime, -1));

        fprintf(out, " uid=\"%d\"", info->info.st_uid);
        if (user) {
            fprintf(out, " user=\"%s\"", user->pw_name);
        }
        fprintf(out, " gid=\"%d\"", info->info.st_gid);
        if (group) {
            fprintf(out, " group=\"%s\"", group->gr_name);
        }

        fprintf(out, "/>\n");
    }

    /* data section from stdout and stderr of application */
    if (includeData &&
        info->source == IS_TEMP &&
        info->error == 0 &&
        info->info.st_size && data_section_size > 0) {

        size_t dsize = data_section_size;
        size_t fsize = info->info.st_size;
        fprintf(out, "%*s<data%s", indent+2, "",
                (fsize > dsize ? " truncated=\"true\"" : ""));
        if (fsize > 0) {
            char buf [BUFSIZ];
            int fd = dup(info->file.descriptor);

            fprintf(out, ">");
            if (fd != -1) {

                if (useCDATA) {
                    fprintf(out, "<![CDATA[");
                }

                /* Get the last dsize bytes of the file */
                size_t offset = 0;
                if (fsize > dsize) {
                    offset = fsize - dsize;
                }
                if (lseek(fd, offset, SEEK_SET) != -1) {
                    ssize_t total = 0;
                    while (total < dsize) {
                        ssize_t rsize = read(fd, buf, BUFSIZ);
                        if (rsize == 0) {
                            break;
                        } else if (rsize < 0) {
                            printerr("ERROR reading %s: %s",
                                    info->file.name, strerror(errno));
                            break;
                        }
                        if (useCDATA) {
                            fwrite(buf, rsize, 1, out);
                        } else {
                            xmlquote(out, buf, rsize);
                        }
                        total += rsize;
                    }
                }
                close(fd);

                if (useCDATA) {
                    fprintf(out, "]]>");
                }
            }

            fprintf(out, "</data>\n");
        } else {
            fprintf(out, "/>\n");
        }
    }

    fprintf(out, "%*s</%s>\n", indent, "", tag);

    return 0;
}
Example #7
0
size_t
printXMLStatInfo(FILE *out, int indent, const char* tag, const char* id,
                 const StatInfo* info)
/* purpose: XML format a stat info record into a given stream
 * paramtr: out (IO): the stream
 *          tag (IN): name of element to generate
 *          id (IN): id attribute, use NULL to not generate
 *          info (IN): stat info to print.
 * returns: number of characters put into buffer (buffer length)
 */
{
  char* real = NULL;

  /* sanity check */
  if (info->source == IS_INVALID) return 0;

  /* start main tag */
  fprintf(out, "%*s<%s error=\"%d\"", indent, "", tag, info->error);
  if (id != NULL) fprintf(out, " id=\"%s\"", id);
  if (info->lfn != NULL) fprintf(out, " lfn=\"%s\"", info->lfn);
  fprintf(out, ">\n");

  /* NEW: ignore "file not found" error for "gridstart" */
  if (id != NULL && info->error == 2 && strcmp(id, "gridstart") == 0)
    fprintf(out, "%*s<!-- ignore above error -->\n", indent+2, "");

  /* either a <name> or <descriptor> sub element */
  switch (info->source) {
  case IS_TEMP:   /* preparation for <temporary> element */
    /* late update for temp files */
    errno = 0;
    if (fstat(info->file.descriptor, (struct stat*) &info->info) != -1 &&
         (((StatInfo*) info)->error = errno) == 0) {
      /* obtain header of file */

#if 0
      /* implementation alternative 1: use a new filetable kernel structure */
      int fd = open(info->file.name, O_RDONLY);
      if (fd != -1) {
        read(fd, (char*) info->client.header, sizeof(info->client.header));
        close(fd);
      }
#else
      /* implementation alternative 2: share the kernel filetable structure */
      int fd = dup(info->file.descriptor);
      if (fd != -1) {
        if (lseek(fd, 0, SEEK_SET) != -1)
          read(fd, (char*) info->client.header, sizeof(info->client.header));
        close(fd);
      }
#endif
    }

    fprintf(out, "%*s<temporary name=\"%s\" descriptor=\"%d\"/>\n",
            indent+2, "", info->file.name, info->file.descriptor);
    break;

  case IS_FIFO: /* <fifo> element */
    fprintf(out, "%*s<fifo name=\"%s\" descriptor=\"%d\" count=\"%zu\" rsize=\"%zu\" wsize=\"%zu\"/>\n",
            indent+2, "", info->file.name, info->file.descriptor,
            info->client.fifo.count, info->client.fifo.rsize, 
            info->client.fifo.wsize);
    break;

  case IS_FILE: /* <file> element */
#if 0
    /* some debug info - for now */
    fprintf(out, "%*s<!-- deferred flag: %d -->\n",
            indent+2, "", info->deferred);
#endif

#ifdef HAS_REALPATH_EXT
    real = realpath(info->file.name, NULL); 
#endif /* HAS_REALPATH_EXT */
    fprintf(out, "%*s<file name=\"%s\"", indent+2, "",
            real ? real : info->file.name);
#ifdef HAS_REALPATH_EXT
    if (real) free((void*) real);
#endif /* HAS_REALPATH_EXT */

    if (info->error == 0 && S_ISREG(info->info.st_mode) &&
        info->info.st_size > 0) {
      /* optional hex information */
      size_t i, end = sizeof(info->client.header);
      if (info->info.st_size < end) end = info->info.st_size;

      fprintf(out, ">");
      for (i=0; i<end; ++i)
        fprintf(out, "%02X", info->client.header[i]);
      fprintf(out, "</file>\n");
    } else {
      fprintf(out, "/>\n");
    }
    break;

  case IS_HANDLE: /* <descriptor> element */
    fprintf(out, "%*s<descriptor number=\"%u\"/>\n", indent+2, "",
            info->file.descriptor);
    break;

  default: /* this must not happen! */
    fprintf(out, "%*s<!-- ERROR: No valid file info available -->\n",
            indent+2, "");
    break;
  }

  if (info->error == 0 && info->source != IS_INVALID) {
    /* <stat> subrecord */
    char my[32];
    struct passwd* user = wrap_getpwuid(info->info.st_uid);
    struct group* group = wrap_getgrgid(info->info.st_gid);

    fprintf(out, "%*s<statinfo mode=\"0%o\"", indent+2, "",
            info->info.st_mode);

    /* Grmblftz, are we in 32bit, 64bit LFS on 32bit, or 64bit on 64 */
    sizer(my, sizeof(my), sizeof(info->info.st_size), &info->info.st_size);
    fprintf(out, " size=\"%s\"", my);

    sizer(my, sizeof(my), sizeof(info->info.st_ino), &info->info.st_ino);
    fprintf(out, " inode=\"%s\"", my);

    sizer(my, sizeof(my), sizeof(info->info.st_nlink), &info->info.st_nlink);
    fprintf(out, " nlink=\"%s\"", my);

    sizer(my, sizeof(my), sizeof(info->info.st_blksize), &info->info.st_blksize);
    fprintf(out, " blksize=\"%s\"", my);

    /* st_blocks is new in iv-1.8 */
    sizer(my, sizeof(my), sizeof(info->info.st_blocks), &info->info.st_blocks);
    fprintf(out, " blocks=\"%s\"", my);

    fprintf(out, " mtime=\"%s\"",
            fmtisodate(isLocal, isExtended, info->info.st_mtime, -1));
    fprintf(out, " atime=\"%s\"",
            fmtisodate(isLocal, isExtended, info->info.st_atime, -1));
    fprintf(out, " ctime=\"%s\"",
            fmtisodate(isLocal, isExtended, info->info.st_ctime, -1));

    fprintf(out, " uid=\"%d\"", info->info.st_uid);
    if (user) fprintf(out, " user=\"%s\"", user->pw_name);
    fprintf(out, " gid=\"%d\"", info->info.st_gid);
    if (group) fprintf(out, " group=\"%s\"", group->gr_name);

    fprintf(out, "/>\n");
  }

  /* data section from stdout and stderr of application */
  if (info->source == IS_TEMP && info->error == 0 && info->info.st_size &&
      data_section_size > 0) {
    size_t dsize = data_section_size;
    size_t fsize = info->info.st_size;
    fprintf(out, "%*s<data%s", indent+2, "",
            (fsize > dsize ? " truncated=\"true\"" : ""));
    if (fsize > 0) {
      char* data = (char*) malloc(dsize+1);
      int fd = dup(info->file.descriptor);

      fprintf(out, ">");
      if (fd != -1) {
        /* Get the last dsize bytes of the file */
        size_t offset = 0;
        if (fsize > dsize) {
          offset = fsize - dsize;
        }
        if (lseek(fd, offset, SEEK_SET) != -1) {
          ssize_t rsize = read(fd, data, dsize);
          xmlquote(out, data, rsize);
        }
        close(fd);
      }

      fprintf(out, "</data>\n");
      free((void*) data);
    } else {
      fprintf(out, "/>\n");
    }
  }

  fprintf(out, "%*s</%s>\n", indent, "", tag);

  return 0;
}