cgroup-show.c revision fa776d8e962da9d90459e2f3e86a2a0c6366ee12
/*-*- Mode: C; c-basic-offset: 8 -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include "util.h"
#include "macro.h"
#include "cgroup-show.h"
static int compare(const void *a, const void *b) {
const pid_t *p = a, *q = b;
if (*p < *q)
return -1;
if (*p > *q)
return 1;
return 0;
}
static char *get_cgroup_path(const char *name) {
name += 13;
}
int n = 0;
while (ul > 0) {
n++;
ul /= 10;
}
return n;
}
char *fn;
FILE *f;
size_t n = 0, n_allocated = 0;
char *p;
int r;
unsigned long biggest = 0;
if (n_columns <= 0)
if (!prefix)
prefix = "";
if (!(p = get_cgroup_path(name)))
return -ENOMEM;
free(p);
if (r < 0)
return -ENOMEM;
if (!f)
return -errno;
while (!feof(f)) {
unsigned long ul;
break;
if (ul <= 0)
continue;
if (n >= n_allocated) {
r = -ENOMEM;
goto finish;
}
}
assert(n < n_allocated);
}
if (n > 0) {
unsigned i, m;
/* Filter duplicates */
m = 0;
for (i = 0; i < n; i++) {
unsigned j;
for (j = i+1; j < n; j++)
break;
if (j >= n)
}
n = m;
/* And sort */
if (n_columns > 8)
n_columns -= 8;
else
n_columns = 20;
for (i = 0; i < n; i++) {
char *t = NULL;
printf("%s%s %*lu %s\n",
(unsigned long) pids[i],
strna(t));
free(t);
}
}
r = 0;
if (f)
fclose(f);
return r;
}
}
DIR *d;
bool shown_pids = false;
int r;
if (n_columns <= 0)
if (!prefix)
prefix = "";
return -ENOMEM;
return -errno;
}
continue;
continue;
if (!shown_pids) {
shown_pids = true;
}
if (last) {
if (!p1)
r = -ENOMEM;
goto finish;
}
}
log_error("Out of memory");
goto finish;
}
}
if (!shown_pids)
if (last) {
if (!p2)
r = -ENOMEM;
goto finish;
}
}
r = 0;
closedir(d);
return r;
}