void Director::add_tr(std::ostringstream& ss, const std::string& path, const Entry& entry) { if(entry.name() == ".") return; bool isFile = entry.is_file(); ss << "<tr>"; add_td(ss, "type", get_icon(entry)); add_td(ss, "file", create_url(path, entry.name())); isFile ? add_td(ss, "size", human_readable_size(entry.size())) : add_td(ss, "size", "-"); isFile ? add_td(ss, "modified", "N/A") : add_td(ss, "modified", "-"); ss << "</tr>"; }
struct proc_task *proc_stat(pid_t pid, int page_size) { int ret; char *p, *q; char *buf; char pid_path[PROC_PID_SIZE]; struct proc_task *t; t = flb_calloc(1, sizeof(struct proc_task)); if (!t) { flb_errno(); return NULL; } /* Compose path for /proc/PID/stat */ ret = snprintf(pid_path, PROC_PID_SIZE, "/proc/%i/stat", pid); if (ret < 0) { flb_errno(); return NULL; } buf = file_to_buffer(pid_path); if (!buf) { flb_free(t); return NULL; } sscanf(buf, "%d", &t->pid); /* * workaround for process with spaces in the name, so we dont screw up * sscanf(3). */ p = buf; while (*p != '(') p++; p++; q = p; while (*q != ')') q++; strncpy(t->comm, p, q - p); q += 2; /* Read pending values */ sscanf(q, PROC_STAT_FORMAT, &t->state, &t->ppid, &t->pgrp, &t->session, &t->tty_nr, &t->tpgid, &t->flags, &t->minflt, &t->cminflt, &t->majflt, &t->cmajflt, &t->utime, &t->stime, &t->cutime, &t->cstime, &t->priority, &t->nice, &t->num_threads, &t->itrealvalue, &t->starttime, &t->vsize, &t->rss); /* Internal conversion */ t->proc_rss = (t->rss * page_size); t->proc_rss_hr = human_readable_size(t->proc_rss); flb_free(buf); return t; }