char str[32];
double uptime;
- f = fopen("/proc/uptime", "r");
+ f = fopen("/proc/uptime", "re");
if (!f)
return;
struct list_sample_data *sampledata;
struct ps_sched_struct *ps_prev = NULL;
-
-
sampledata = *ptr;
/* all the per-process stuff goes here */
/* block stuff */
vmstat = openat(procfd, "vmstat", O_RDONLY);
if (vmstat == -1) {
- perror("open /proc/vmstat");
- exit (EXIT_FAILURE);
+ log_error("Failed to open /proc/vmstat: %m");
+ exit(EXIT_FAILURE);
}
}
/* overall CPU utilization */
schedstat = openat(procfd, "schedstat", O_RDONLY);
if (schedstat == -1) {
- perror("open /proc/schedstat");
- exit (EXIT_FAILURE);
+ log_error("Failed to open /proc/schedstat: %m");
+ exit(EXIT_FAILURE);
}
}
char t[32];
struct ps_struct *parent;
- ps->next_ps = calloc(1, sizeof(struct ps_struct));
+ ps->next_ps = new0(struct ps_struct, 1);
if (!ps->next_ps) {
- perror("calloc(ps_struct)");
+ log_oom();
exit (EXIT_FAILURE);
}
ps = ps->next_ps;
ps->pid = pid;
- ps->sample = calloc(1, sizeof(struct ps_sched_struct));
+ ps->sample = new0(struct ps_sched_struct, 1);
if (!ps->sample) {
- perror("calloc(ps_struct)");
+ log_oom();
exit (EXIT_FAILURE);
}
ps->sample->sampledata = sampledata;
pscount++;
/* mark our first sample */
- ps->first = ps->sample;
+ ps->first = ps->last = ps->sample;
ps->sample->runtime = atoll(rt);
ps->sample->waittime = atoll(wt);
while ((parent->next_ps && parent->pid != ps->ppid))
parent = parent->next_ps;
- if ((!parent) || (parent->pid != ps->ppid)) {
+ if (parent->pid != ps->ppid) {
/* orphan */
ps->ppid = 1;
parent = ps_first->next_ps;
if (!sscanf(buf, "%s %s %*s", rt, wt))
continue;
- ps->sample->next = calloc(1, sizeof(struct ps_sched_struct));
+ ps->sample->next = new0(struct ps_sched_struct, 1);
if (!ps->sample) {
- perror("calloc(ps_struct)");
- exit (EXIT_FAILURE);
+ log_oom();
+ exit(EXIT_FAILURE);
}
ps->sample->next->prev = ps->sample;
ps->sample = ps->sample->next;